Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add support for notifications #54

Merged
merged 4 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading