From e5333d923145d958a0244b4fc37e79688c7d6c50 Mon Sep 17 00:00:00 2001 From: Rohan Moniz <60864468+rm03@users.noreply.github.com> Date: Sat, 25 Nov 2023 23:00:06 -0500 Subject: [PATCH] send email upon extension + nit --- backend/clubs/models.py | 19 ++++++++++++++++ backend/clubs/serializers.py | 22 +++++++++++-------- .../emails/application_extension.html | 22 +++++++++++++++++++ 3 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 backend/templates/emails/application_extension.html diff --git a/backend/clubs/models.py b/backend/clubs/models.py index 162e471bf..a26531e6c 100644 --- a/backend/clubs/models.py +++ b/backend/clubs/models.py @@ -1603,6 +1603,25 @@ class ApplicationExtension(models.Model): ) end_time = models.DateTimeField() + def send_extension_mail(self): + context = { + "name": self.user.first_name, + "application_name": self.application.name, + "end_time": self.end_time, + "club": self.application.club.name, + "url": ( + f"https://pennclubs.com/club/{self.application.club.code}" + f"/application/{self.application.pk}/" + ), + } + + send_mail_helper( + name="application_extension", + subject=f"Application Extension for {self.application.name}", + emails=[self.user.email], + context=context, + ) + class Meta: unique_together = (("user", "application"),) diff --git a/backend/clubs/serializers.py b/backend/clubs/serializers.py index db3c13471..56f5a851a 100644 --- a/backend/clubs/serializers.py +++ b/backend/clubs/serializers.py @@ -2476,15 +2476,14 @@ def validate(self, data): if not application: raise serializers.ValidationError("Invalid application id!") - if ( - ( - not self.instance - or (username and self.instance.user.username != username) - ) - and ApplicationExtension.objects.filter( - user=user, application=application - ).exists() - ): + application_exists = ApplicationExtension.objects.filter( + user=user, application=application + ).exists() + modify_username = not self.instance or ( + username and self.instance.user.username != username + ) + + if modify_username and application_exists: raise serializers.ValidationError( "An extension for this user and application already exists!" ) @@ -2500,6 +2499,11 @@ def validate(self, data): return data + def save(self): + extension_obj = super().save() + extension_obj.send_extension_mail() + return extension_obj + class ApplicationSubmissionSerializer(serializers.ModelSerializer): committee = ApplicationCommitteeSerializer(required=False, read_only=True) diff --git a/backend/templates/emails/application_extension.html b/backend/templates/emails/application_extension.html new file mode 100644 index 000000000..f3aeee637 --- /dev/null +++ b/backend/templates/emails/application_extension.html @@ -0,0 +1,22 @@ + +{% extends 'emails/base.html' %} + +{% block content %} +
Hello {{ name }},
+You have been granted an extension for {{ application_name }} by the officers of {{ club }} on Penn Clubs:
+The updated deadline to submit your application is {{ end_time }}. You can apply using the button below.
+ Apply +{% endblock %}