Add success notification emails.

Enable RevisionMixin for EventAuthorisation.

Add signal receivers for RIGS.

Expand RIGS into an explicitly defined app to support signals.
This commit is contained in:
Tom Price
2017-04-10 19:16:45 +01:00
parent cf11e8235f
commit 3b2aa02ae5
8 changed files with 76 additions and 8 deletions

View File

@@ -0,0 +1 @@
default_app_config = 'RIGS.apps.RIGSAppConfig'

8
RIGS/apps.py Normal file
View File

@@ -0,0 +1,8 @@
from django.apps import AppConfig
class RIGSAppConfig(AppConfig):
name = 'RIGS'
def ready(self):
import RIGS.signals

View File

@@ -506,7 +506,7 @@ class EventCrew(models.Model):
@reversion.register
class EventAuthorisation(models.Model):
class EventAuthorisation(models.Model, RevisionMixin):
event = models.OneToOneField('Event', related_name='authorisation')
email = models.EmailField()
name = models.CharField(max_length=255)

View File

@@ -3,6 +3,9 @@ import cStringIO as StringIO
from io import BytesIO
import urllib2
import reversion
from django.core.mail import EmailMessage
from django.db import transaction
from django.views import generic
from django.core.urlresolvers import reverse_lazy
from django.shortcuts import get_object_or_404
@@ -232,7 +235,7 @@ class EventAuthorise(generic.UpdateView):
def form_valid(self, form):
self.object = form.save()
# TODO: send email confirmation
self.template_name = self.success_template
messages.add_message(self.request, messages.SUCCESS,
'Success! Your event has been authorised. You will also receive email confirmation.')

34
RIGS/signals.py Normal file
View File

@@ -0,0 +1,34 @@
import reversion
from django.core.mail import EmailMessage
from django.template.loader import get_template
from RIGS import models
def send_eventauthorisation_success_email(instance):
context = {
'object': instance,
}
client_email = EmailMessage(
"N%05d | %s - Event Authorised".format(instance.event.pk, instance.event.name),
get_template("RIGS/eventauthorisation_client_success.txt").render(context),
to=[instance.email]
)
mic_email = EmailMessage(
"N%05d | %s - Event Authorised".format(instance.event.pk, instance.event.name),
get_template("RIGS/eventauthorisation_mic_success.txt").render(context),
to=[instance.event.mic.email]
)
client_email.send()
mic_email.send()
def on_revision_commit(instances, **kwargs):
for instance in instances:
if isinstance(instance, models.EventAuthorisation):
send_eventauthorisation_success_email(instance)
reversion.post_revision_commit.connect(on_revision_commit)

View File

@@ -0,0 +1,11 @@
Hi there,
Just to let you know your event N{{object.event.pk|stringformat:"05d"}} has been successfully authorised for {{object.amount}} by {{object.name}} as of {{object.last_edited_at}}.
{% if object.event.organisation and object.event.organisation.union_account %}{# internal #}
Your event is now fully booked and payment will be processed by the finance department automatically.
{% else %}{# external #}
Your event is now fully booked and our finance department will be contact to arrange payment.
{% endif %}
The TEC Rig Information Gathering System

View File

@@ -0,0 +1,5 @@
Hi {{object.event.mic.name}},
Just to let you know your event N{{object.event.pk|stringformat:"05d"}} has been successfully authorised for {{object.amount}} by {{object.name}} as of {{object.last_edited_at}}.
The TEC Rig Information Gathering System

View File

@@ -1,4 +1,5 @@
import pytz
import reversion
from django.conf import settings
from django.core.exceptions import ValidationError
from django.test import TestCase
@@ -331,14 +332,13 @@ class EventPricingTestCase(TestCase):
class EventAuthorisationTestCase(TestCase):
@classmethod
def setUpTestData(cls):
cls.person = models.Person.objects.create(name='Authorisation Test Person')
cls.organisation = models.Organisation.objects.create(name='Authorisation Test Organisation')
cls.event = models.Event.objects.create(name="AuthorisationTestCase", person=cls.person,
def setUp(self):
self.person = models.Person.objects.create(name='Authorisation Test Person')
self.organisation = models.Organisation.objects.create(name='Authorisation Test Organisation')
self.event = models.Event.objects.create(name="AuthorisationTestCase", person=self.person,
start_date=date.today())
# Add some items
models.EventItem.objects.create(event=cls.event, name="Authorisation test item", quantity=2, cost=123.45,
models.EventItem.objects.create(event=self.event, name="Authorisation test item", quantity=2, cost=123.45,
order=1)
def test_event_property(self):
@@ -348,3 +348,9 @@ class EventAuthorisationTestCase(TestCase):
auth1.amount = self.event.total
auth1.save()
self.assertTrue(self.event.authorised)
def test_last_edited(self):
with reversion.create_revision():
auth = models.EventAuthorisation.objects.create(event=self.event, email="authroisation@model.test.case",
name="Test Auth", amount=self.event.total)
self.assertIsNotNone(auth.last_edited_at)