diff --git a/PyRIGS/settings.py b/PyRIGS/settings.py index 5db9bf8da..13eb97482 100644 --- a/PyRIGS/settings.py +++ b/PyRIGS/settings.py @@ -42,8 +42,9 @@ INTERNAL_IPS = ['127.0.0.1'] -ADMINS = [('Tom Price', 'tomtom5152@gmail.com'), ('IT Manager', 'it@nottinghamtec.co.uk'), - ('Arona Jones', 'arona.jones@nottinghamtec.co.uk')] +DOMAIN = env('DOMAIN', default='example.com') + +ADMINS = [('IT Manager', f'it@{DOMAIN}'), ('Arona Jones', f'arona.jones@{DOMAIN}')] if DEBUG: ADMINS.append(('Testing Superuser', 'superuser@example.com')) diff --git a/RIGS/management/commands/send_reminders.py b/RIGS/management/commands/send_reminders.py new file mode 100644 index 000000000..1334b5cc8 --- /dev/null +++ b/RIGS/management/commands/send_reminders.py @@ -0,0 +1,38 @@ +import premailer +import datetime + +from django.template.loader import get_template +from django.contrib.staticfiles import finders +from django.conf import settings +from django.core.management.base import BaseCommand, CommandError +from django.core.mail import EmailMultiAlternatives +from django.utils import timezone +from django.urls import reverse + +from RIGS import models + + +class Command(BaseCommand): + help = 'Sends email reminders as required. Triggered daily through heroku-scheduler in production.' + + def handle(self, *args, **options): + events = models.Event.objects.current_events().select_related('riskassessment') + for event in events: + earliest_time = event.earliest_time if isinstance(event.earliest_time, datetime.datetime) else timezone.make_aware(datetime.datetime.combine(event.earliest_time, datetime.time(00, 00))) + # 48 hours = 172800 seconds + if not event.cancelled and not event.dry_hire and (earliest_time - timezone.now()).total_seconds() <= 172800 and not hasattr(event, 'riskassessment'): + context = { + "event": event, + "url": "https://" + settings.DOMAIN + reverse('event_ra', kwargs={'pk': event.pk}) + } + target = event.mic.email if event.mic else f"productions@{settings.DOMAIN}" + msg = EmailMultiAlternatives( + f"{event} - Risk Assessment Incomplete", + get_template("email/ra_reminder.txt").render(context), + to=[target], + reply_to=[f"h.s.manager@{settings.DOMAIN}"], + ) + css = finders.find('css/email.css') + html = premailer.Premailer(get_template("email/ra_reminder.html").render(context), external_styles=css).transform() + msg.attach_alternative(html, 'text/html') + msg.send() diff --git a/RIGS/signals.py b/RIGS/signals.py index 1a9aee517..46793c715 100644 --- a/RIGS/signals.py +++ b/RIGS/signals.py @@ -58,13 +58,13 @@ def send_eventauthorisation_success_email(instance): client_email = EmailMultiAlternatives( subject, - get_template("eventauthorisation_client_success.txt").render(context), + get_template("email/eventauthorisation_client_success.txt").render(context), to=[instance.email], reply_to=[settings.AUTHORISATION_NOTIFICATION_ADDRESS], ) css = finders.find('css/email.css') - html = Premailer(get_template("eventauthorisation_client_success.html").render(context), + html = Premailer(get_template("email/eventauthorisation_client_success.html").render(context), external_styles=css).transform() client_email.attach_alternative(html, 'text/html') @@ -82,7 +82,7 @@ def send_eventauthorisation_success_email(instance): mic_email = EmailMessage( subject, - get_template("eventauthorisation_mic_success.txt").render(context), + get_template("email/eventauthorisation_mic_success.txt").render(context), to=[mic_email_address] ) @@ -117,12 +117,12 @@ def send_admin_awaiting_approval_email(user, request, **kwargs): email = EmailMultiAlternatives( f"{context['number_of_users']} new users awaiting approval on RIGS", - get_template("admin_awaiting_approval.txt").render(context), + get_template("email/admin_awaiting_approval.txt").render(context), to=[admin.email], reply_to=[user.email], ) css = finders.find('css/email.css') - html = Premailer(get_template("admin_awaiting_approval.html").render(context), + html = Premailer(get_template("email/admin_awaiting_approval.html").render(context), external_styles=css).transform() email.attach_alternative(html, 'text/html') email.send() diff --git a/RIGS/templates/admin_awaiting_approval.html b/RIGS/templates/email/admin_awaiting_approval.html similarity index 100% rename from RIGS/templates/admin_awaiting_approval.html rename to RIGS/templates/email/admin_awaiting_approval.html diff --git a/RIGS/templates/admin_awaiting_approval.txt b/RIGS/templates/email/admin_awaiting_approval.txt similarity index 100% rename from RIGS/templates/admin_awaiting_approval.txt rename to RIGS/templates/email/admin_awaiting_approval.txt diff --git a/RIGS/templates/eventauthorisation_client_request.html b/RIGS/templates/email/eventauthorisation_client_request.html similarity index 100% rename from RIGS/templates/eventauthorisation_client_request.html rename to RIGS/templates/email/eventauthorisation_client_request.html diff --git a/RIGS/templates/eventauthorisation_client_request.txt b/RIGS/templates/email/eventauthorisation_client_request.txt similarity index 100% rename from RIGS/templates/eventauthorisation_client_request.txt rename to RIGS/templates/email/eventauthorisation_client_request.txt diff --git a/RIGS/templates/eventauthorisation_client_success.html b/RIGS/templates/email/eventauthorisation_client_success.html similarity index 100% rename from RIGS/templates/eventauthorisation_client_success.html rename to RIGS/templates/email/eventauthorisation_client_success.html diff --git a/RIGS/templates/eventauthorisation_client_success.txt b/RIGS/templates/email/eventauthorisation_client_success.txt similarity index 100% rename from RIGS/templates/eventauthorisation_client_success.txt rename to RIGS/templates/email/eventauthorisation_client_success.txt diff --git a/RIGS/templates/email/eventauthorisation_mic_success.txt b/RIGS/templates/email/eventauthorisation_mic_success.txt new file mode 100644 index 000000000..b4309dd4f --- /dev/null +++ b/RIGS/templates/email/eventauthorisation_mic_success.txt @@ -0,0 +1,5 @@ +Hi {{object.event.mic.get_full_name|default_if_none:"somebody"}}, + +Just to let you know your event N{{object.eventdisplay_id}} has been successfully authorised for £{{object.amount}} by {{object.name}} as of {{object.event.last_edited_at}}. + +The TEC Rig Information Gathering System diff --git a/RIGS/templates/email/ra_reminder.html b/RIGS/templates/email/ra_reminder.html new file mode 100644 index 000000000..e32eae115 --- /dev/null +++ b/RIGS/templates/email/ra_reminder.html @@ -0,0 +1,16 @@ +{% extends 'base_client_email.html' %} + +{% block content %} +

Hi {{event.mic.get_full_name|default_if_none:"Productions Manager"}},

+ + {% if event.mic %} +

Just to let you know your event {{event.display_id}} requires a pre-event risk assessment completing prior to the event. Please do so as soon as possible.

+ {% else %} +

This is a reminder that event {{event.display_id}} requires a MIC assigning and a risk assessment completing.

+ {% endif %} + +

Fill it out here:

+ Create Risk Assessment + +

TEC PA & Lighting

+{% endblock %} diff --git a/RIGS/templates/email/ra_reminder.txt b/RIGS/templates/email/ra_reminder.txt new file mode 100644 index 000000000..9b66e7617 --- /dev/null +++ b/RIGS/templates/email/ra_reminder.txt @@ -0,0 +1,9 @@ +Hi {{event.mic.get_full_name|default_if_none:"Productions Manager"}}, + +{% if event.mic %} +Just to let you know your event {{event.display_id}} requires a risk assessment completing prior to the event. Please do so as soon as possible. +{% else %} +This is a reminder that event {{event.display_id}} requires a MIC assigning and a risk assessment completing. +{% endif %} + +The TEC Rig Information Gathering System diff --git a/RIGS/templates/eventauthorisation_mic_success.txt b/RIGS/templates/eventauthorisation_mic_success.txt deleted file mode 100644 index 43ddd5e17..000000000 --- a/RIGS/templates/eventauthorisation_mic_success.txt +++ /dev/null @@ -1,5 +0,0 @@ -Hi {{object.event.mic.get_full_name|default_if_none:"somebody"}}, - -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.event.last_edited_at}}. - -The TEC Rig Information Gathering System diff --git a/RIGS/views/rigboard.py b/RIGS/views/rigboard.py index 1a146c477..d60f0c2b3 100644 --- a/RIGS/views/rigboard.py +++ b/RIGS/views/rigboard.py @@ -342,12 +342,12 @@ def form_valid(self, form): msg = EmailMultiAlternatives( f"{self.object.display_id} | {self.object.name} - Event Authorisation Request", - get_template("eventauthorisation_client_request.txt").render(context), + get_template("email/eventauthorisation_client_request.txt").render(context), to=[email], reply_to=[self.request.user.email], ) css = finders.find('css/email.css') - html = premailer.Premailer(get_template("eventauthorisation_client_request.html").render(context), + html = premailer.Premailer(get_template("email/eventauthorisation_client_request.html").render(context), external_styles=css).transform() msg.attach_alternative(html, 'text/html') @@ -357,7 +357,7 @@ def form_valid(self, form): class EventAuthoriseRequestEmailPreview(generic.DetailView): - template_name = "eventauthorisation_client_request.html" + template_name = "email/eventauthorisation_client_request.html" model = models.Event def render_to_response(self, context, **response_kwargs):