Skip to content

Commit

Permalink
send email upon extension + nit
Browse files Browse the repository at this point in the history
  • Loading branch information
rm03 committed Nov 26, 2023
1 parent 1b7cef0 commit e5333d9
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
19 changes: 19 additions & 0 deletions backend/clubs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),)

Expand Down
22 changes: 13 additions & 9 deletions backend/clubs/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
)
Expand All @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions backend/templates/emails/application_extension.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- TYPES:
name:
type: string
club:
type: string
application_name:
type: string
end_time:
type: string
url:
type: string
-->
{% extends 'emails/base.html' %}

{% block content %}
<h2>Application Extension for {{ application_name }}</h2>
<p style="font-size: 1.2em;">Hello {{ name }},</p>
<p style="font-size: 1.2em;">You have been granted an extension for {{ application_name }} by the officers of {{ club }} on Penn Clubs:</p>
<p style="font-size: 1.2em;">The updated deadline to submit your application is {{ end_time }}. You can apply using the button below.</p>
<a style="text-decoration: none; padding: 5px 20px; font-size: 1.5em; margin-top: 25px; color: white; background-color: green; border-radius: 3px; font-weight: bold"
href="{{ url }}">Apply</a>
{% endblock %}

0 comments on commit e5333d9

Please sign in to comment.