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 @reversion.register
class EventAuthorisation(models.Model): class EventAuthorisation(models.Model, RevisionMixin):
event = models.OneToOneField('Event', related_name='authorisation') event = models.OneToOneField('Event', related_name='authorisation')
email = models.EmailField() email = models.EmailField()
name = models.CharField(max_length=255) name = models.CharField(max_length=255)

View File

@@ -3,6 +3,9 @@ import cStringIO as StringIO
from io import BytesIO from io import BytesIO
import urllib2 import urllib2
import reversion
from django.core.mail import EmailMessage
from django.db import transaction
from django.views import generic from django.views import generic
from django.core.urlresolvers import reverse_lazy from django.core.urlresolvers import reverse_lazy
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
@@ -232,7 +235,7 @@ class EventAuthorise(generic.UpdateView):
def form_valid(self, form): def form_valid(self, form):
self.object = form.save() self.object = form.save()
# TODO: send email confirmation
self.template_name = self.success_template self.template_name = self.success_template
messages.add_message(self.request, messages.SUCCESS, messages.add_message(self.request, messages.SUCCESS,
'Success! Your event has been authorised. You will also receive email confirmation.') '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 pytz
import reversion
from django.conf import settings from django.conf import settings
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.test import TestCase from django.test import TestCase
@@ -331,14 +332,13 @@ class EventPricingTestCase(TestCase):
class EventAuthorisationTestCase(TestCase): class EventAuthorisationTestCase(TestCase):
@classmethod def setUp(self):
def setUpTestData(cls): self.person = models.Person.objects.create(name='Authorisation Test Person')
cls.person = models.Person.objects.create(name='Authorisation Test Person') self.organisation = models.Organisation.objects.create(name='Authorisation Test Organisation')
cls.organisation = models.Organisation.objects.create(name='Authorisation Test Organisation') self.event = models.Event.objects.create(name="AuthorisationTestCase", person=self.person,
cls.event = models.Event.objects.create(name="AuthorisationTestCase", person=cls.person,
start_date=date.today()) start_date=date.today())
# Add some items # 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) order=1)
def test_event_property(self): def test_event_property(self):
@@ -348,3 +348,9 @@ class EventAuthorisationTestCase(TestCase):
auth1.amount = self.event.total auth1.amount = self.event.total
auth1.save() auth1.save()
self.assertTrue(self.event.authorised) 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)