Skip to content

Commit

Permalink
Feat: Add support for notifications (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
sverben authored Jan 21, 2024
1 parent c5dca78 commit 4fa6c62
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions LedenAdministratie/settings.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,4 @@ TINYMCE_DEFAULT_CONFIG = {
"alignright alignjustify | bullist numlist outdent indent | code table "
"removeformat link | help",
}
NOTIFICATION_ENDPOINT = None
22 changes: 22 additions & 0 deletions LedenAdministratie/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,29 +444,51 @@ def send_email(self, form, recipients):

return Utils.send_email(message)

def send_notification(self, form, recipients):
if len(recipients) == 0:
return
if not settings.NOTIFICATION_ENDPOINT:
return

requests.post(
settings.NOTIFICATION_ENDPOINT,
json={
"title": "DJO Aankondigingen",
"description": form.cleaned_data["subject"],
"content": form.cleaned_data["body"],
"recipients": recipients,
},
timeout=10,
)

def form_valid(self, form):
if "self" in form.cleaned_data["recipients"]:
self.send_email(form, [self.request.user.email])

recipients = Member.objects.filter(
Q(afmeld_datum__gt=date.today()) | Q(afmeld_datum=None)
)
to_user_list = []
for recipient in recipients:
to_list = []
if recipient.is_begeleider() or recipient.is_aspirant():
if "begeleiders" in form.cleaned_data["recipients"]:
to_list.append(recipient.email_address)
to_user_list.append(str(recipient.user.id))
elif recipient.is_ondersteuner():
if "ondersteuning" in form.cleaned_data["recipients"]:
to_list.append(recipient.email_address)
to_user_list.append(str(recipient.user.id))
else:
if "parents" in form.cleaned_data["recipients"]:
for address in recipient.email_ouders.split(","):
to_list.append(address)
if "members" in form.cleaned_data["recipients"]:
to_list.append(recipient.email_address)
to_user_list.append(str(recipient.user.id))

self.send_email(form, to_list)
self.send_notification(form, list(set(to_user_list)))

return HttpResponseRedirect(reverse_lazy("email_log"))

Expand Down

0 comments on commit 4fa6c62

Please sign in to comment.