Skip to content

Commit e5333d9

Browse files
committed
send email upon extension + nit
1 parent 1b7cef0 commit e5333d9

File tree

3 files changed

+54
-9
lines changed

3 files changed

+54
-9
lines changed

backend/clubs/models.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,25 @@ class ApplicationExtension(models.Model):
16031603
)
16041604
end_time = models.DateTimeField()
16051605

1606+
def send_extension_mail(self):
1607+
context = {
1608+
"name": self.user.first_name,
1609+
"application_name": self.application.name,
1610+
"end_time": self.end_time,
1611+
"club": self.application.club.name,
1612+
"url": (
1613+
f"https://pennclubs.com/club/{self.application.club.code}"
1614+
f"/application/{self.application.pk}/"
1615+
),
1616+
}
1617+
1618+
send_mail_helper(
1619+
name="application_extension",
1620+
subject=f"Application Extension for {self.application.name}",
1621+
emails=[self.user.email],
1622+
context=context,
1623+
)
1624+
16061625
class Meta:
16071626
unique_together = (("user", "application"),)
16081627

backend/clubs/serializers.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,15 +2476,14 @@ def validate(self, data):
24762476
if not application:
24772477
raise serializers.ValidationError("Invalid application id!")
24782478

2479-
if (
2480-
(
2481-
not self.instance
2482-
or (username and self.instance.user.username != username)
2483-
)
2484-
and ApplicationExtension.objects.filter(
2485-
user=user, application=application
2486-
).exists()
2487-
):
2479+
application_exists = ApplicationExtension.objects.filter(
2480+
user=user, application=application
2481+
).exists()
2482+
modify_username = not self.instance or (
2483+
username and self.instance.user.username != username
2484+
)
2485+
2486+
if modify_username and application_exists:
24882487
raise serializers.ValidationError(
24892488
"An extension for this user and application already exists!"
24902489
)
@@ -2500,6 +2499,11 @@ def validate(self, data):
25002499

25012500
return data
25022501

2502+
def save(self):
2503+
extension_obj = super().save()
2504+
extension_obj.send_extension_mail()
2505+
return extension_obj
2506+
25032507

25042508
class ApplicationSubmissionSerializer(serializers.ModelSerializer):
25052509
committee = ApplicationCommitteeSerializer(required=False, read_only=True)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!-- TYPES:
2+
name:
3+
type: string
4+
club:
5+
type: string
6+
application_name:
7+
type: string
8+
end_time:
9+
type: string
10+
url:
11+
type: string
12+
-->
13+
{% extends 'emails/base.html' %}
14+
15+
{% block content %}
16+
<h2>Application Extension for {{ application_name }}</h2>
17+
<p style="font-size: 1.2em;">Hello {{ name }},</p>
18+
<p style="font-size: 1.2em;">You have been granted an extension for {{ application_name }} by the officers of {{ club }} on Penn Clubs:</p>
19+
<p style="font-size: 1.2em;">The updated deadline to submit your application is {{ end_time }}. You can apply using the button below.</p>
20+
<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"
21+
href="{{ url }}">Apply</a>
22+
{% endblock %}

0 commit comments

Comments
 (0)