Skip to content

Commit 92483f1

Browse files
committed
feat: send club announcements emails
1 parent df32926 commit 92483f1

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

intranet/apps/announcements/forms.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,20 @@ def __init__(self, user, *args, **kwargs):
4444
else:
4545
self.fields["activity"].queryset = []
4646
self.fields["activity"].required = True
47+
self.fields[
48+
"notify_post"
49+
].help_text = "If this box is checked, students who have subscribed to your club's announcements will receive an email."
4750

4851
if "instance" in kwargs: # Don't allow changing the activity once the announcement has been created
4952
self.fields["activity"].widget.attrs["disabled"] = True
5053
self.fields["activity"].initial = kwargs["instance"].activity
5154

5255
expiration_date = forms.DateTimeInput()
56+
notify_post = forms.BooleanField(required=False, initial=True)
5357

5458
class Meta:
5559
model = Announcement
56-
fields = ["activity", "title", "content", "expiration_date"]
60+
fields = ["activity", "title", "content", "expiration_date", "notify_post"]
5761
help_texts = {
5862
"expiration_date": "By default, announcements expire after two weeks. Choose the shortest time necessary.",
5963
}

intranet/apps/announcements/notifications.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ def announcement_posted_email(request, obj, send_all=False):
122122
subject = f"Club Announcement for {obj.activity.name}: {obj.title}"
123123
users = (
124124
get_user_model()
125-
.objects.filter(user_type="student", graduation_year__gte=get_senior_graduation_year(), subscribed_to_set__contains=obj.activity)
125+
.objects.filter(
126+
user_type="student",
127+
graduation_year__gte=get_senior_graduation_year(),
128+
receive_news_emails=True,
129+
subscribed_activity_set=obj.activity,
130+
)
126131
.union(get_user_model().objects.filter(user_type__in=["teacher", "counselor"], subscribed_to_set__contains=obj.activity))
127132
)
128133

intranet/apps/announcements/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,10 @@ def add_club_announcement_view(request):
157157
obj.user = request.user
158158
# SAFE HTML
159159
obj.content = safe_html(obj.content)
160-
161160
obj.save()
162161

162+
announcement_posted_hook(request, obj)
163+
163164
messages.success(request, "Successfully posted club announcement.")
164165
return redirect("club_announcements")
165166
else:

0 commit comments

Comments
 (0)