Skip to content

Commit

Permalink
feat: send club announcements emails
Browse files Browse the repository at this point in the history
  • Loading branch information
alanzhu0 committed Oct 5, 2024
1 parent df32926 commit 92483f1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 5 additions & 1 deletion intranet/apps/announcements/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,20 @@ def __init__(self, user, *args, **kwargs):
else:
self.fields["activity"].queryset = []
self.fields["activity"].required = True
self.fields[
"notify_post"
].help_text = "If this box is checked, students who have subscribed to your club's announcements will receive an email."

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

expiration_date = forms.DateTimeInput()
notify_post = forms.BooleanField(required=False, initial=True)

class Meta:
model = Announcement
fields = ["activity", "title", "content", "expiration_date"]
fields = ["activity", "title", "content", "expiration_date", "notify_post"]
help_texts = {
"expiration_date": "By default, announcements expire after two weeks. Choose the shortest time necessary.",
}
Expand Down
7 changes: 6 additions & 1 deletion intranet/apps/announcements/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ def announcement_posted_email(request, obj, send_all=False):
subject = f"Club Announcement for {obj.activity.name}: {obj.title}"
users = (
get_user_model()
.objects.filter(user_type="student", graduation_year__gte=get_senior_graduation_year(), subscribed_to_set__contains=obj.activity)
.objects.filter(
user_type="student",
graduation_year__gte=get_senior_graduation_year(),
receive_news_emails=True,
subscribed_activity_set=obj.activity,
)
.union(get_user_model().objects.filter(user_type__in=["teacher", "counselor"], subscribed_to_set__contains=obj.activity))
)

Expand Down
3 changes: 2 additions & 1 deletion intranet/apps/announcements/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ def add_club_announcement_view(request):
obj.user = request.user
# SAFE HTML
obj.content = safe_html(obj.content)

obj.save()

announcement_posted_hook(request, obj)

messages.success(request, "Successfully posted club announcement.")
return redirect("club_announcements")
else:
Expand Down

0 comments on commit 92483f1

Please sign in to comment.