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

Update/dsc 3 #150

Merged
merged 44 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
419c7c7
Initial work on upgrading to DSC 3 (and Django 4)
tymees Sep 16, 2022
7b2ae77
fix: select2 not being enabled on experiment form pages
tymees Sep 16, 2022
9a7a958
fix: select2 not being enabled on location field
tymees Sep 16, 2022
82d5731
feat: use smaller hero headers
tymees Sep 19, 2022
a473088
fix: datatables top row layout
tymees Sep 19, 2022
ae9e3df
feature: use small buttons for DT buttons
tymees Sep 19, 2022
b41b14e
feat: switch invite emails over to the new templated email system
tymees Sep 19, 2022
6ce098a
refactor: move default footer to emails.py
tymees Sep 19, 2022
f329765
fix: use proper context values
tymees Sep 19, 2022
84a1892
chore: updated dependencies
tymees Oct 24, 2022
4d7e1a6
feat: implemented all user-templated emails
tymees Oct 24, 2022
1339c9b
feat: slight header redesign
tymees Oct 24, 2022
04e085f
feat: rolled out new actions menu to all list views
tymees Oct 24, 2022
e41acb3
feat: use tineMCE for HTML enabled fields
tymees Oct 26, 2022
46c231d
feat: use frontend layout for slot editing
tymees Oct 26, 2022
0fe997e
feat: better spec.crit. help texts
tymees Oct 31, 2022
5b39c39
feat: allow empty primary email
tymees Oct 31, 2022
377091b
feat: allow edit of admin email addresses
tymees Oct 31, 2022
5f3439d
fix: typos
tymees Oct 31, 2022
49f45fd
feat: use new mail code
tymees Oct 31, 2022
d7ccbea
feat: use the right template block
tymees Oct 31, 2022
5d3fdc8
fix: num participants not being counted right
tymees Oct 31, 2022
d6329cb
fix: test cases failing because they were wrong
tymees Oct 31, 2022
affadd9
chore: cleanup imports
tymees Nov 2, 2022
57431c7
feat: use settings.email_from for all emails
tymees Nov 2, 2022
bc687f8
security update dependencies
tymees Nov 8, 2022
687b950
Merge branch 'develop' into update/dsc-3
tymees Jan 13, 2023
4f5b249
Uil OTS -> ILS Labs
tymees Jan 13, 2023
5f9375f
Merge branch 'develop' into update/dsc-3
tymees Jul 21, 2023
26715cc
Merge remote-tracking branch 'origin/update/dsc-3' into update/dsc-3
tymees Jul 21, 2023
9309ca0
chore: textual changes
tymees Jul 21, 2023
b3857fa
Merge branch 'develop' into update/dsc-3
tymees Jul 21, 2023
033ade7
deps: update to DSC 3.1.0-alpha-5
tymees Jul 24, 2023
5c0b3d1
feature: use new tool-layout
tymees Jul 24, 2023
3309a2a
deps: updated DSC to 3.1.0-alpha-6
tymees Aug 4, 2023
b3fb84a
fix: mark CTE variables as safe
tymees Aug 4, 2023
a10e6f3
Fix typo in invite mail template
tymees Jul 17, 2024
927a33c
deps: update to django 4.2 and DSC 3.2
tymees Jul 17, 2024
55882b1
fix: fx
tymees Jul 17, 2024
bfd500b
Merge branch 'refs/heads/develop' into update/dsc-3
tymees Jul 17, 2024
8a3e262
fix: disable valid-feedback on all templated forms
tymees Aug 30, 2024
6a19da6
fix: fixed translations being assigned to the wrong key
tymees Aug 30, 2024
01d19cc
merged migrations
bbonf Sep 3, 2024
2a05552
fix: fixed issue causing no new tokens to be generated
tymees Sep 3, 2024
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
2 changes: 1 addition & 1 deletion api/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-05-12 11:10+0000\n"
"POT-Creation-Date: 2023-07-24 12:22+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down
2 changes: 1 addition & 1 deletion api/locale/nl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-05-12 11:10+0000\n"
"POT-Creation-Date: 2023-07-24 12:22+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down
8 changes: 6 additions & 2 deletions api/templates/api/mail/cancel_token.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{% extends 'mail/base.html' %}
{% extends 'cdh.mail/mail_template.html' %}

{% block subtitle %}
{% block sender %}
Taal-experimenten
{% endblock %}

{% block banner %}
Afspraak afzeggen
{% endblock %}

Expand Down
10 changes: 7 additions & 3 deletions api/templates/api/mail/cancelled_appointment.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{% extends 'mail/base.html' %}
{% extends 'cdh.mail/mail_template.html' %}

{% block subtitle %}
{% block sender %}
Taal-experimenten
{% endblock %}

{% block banner %}
Uitgeschreven voor experiment: <strong>{{ experiment.name }}</strong>
{% endblock %}

Expand Down Expand Up @@ -35,4 +39,4 @@
</a>
{% endif %}
</p>
{% endblock %}
{% endblock %}
8 changes: 6 additions & 2 deletions api/templates/api/mail/existing_leader_new_participant.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{% extends 'mail/base.html' %}
{% extends 'cdh.mail/mail_template.html' %}

{% block subtitle %}
{% block sender %}
Taal-experimenten
{% endblock %}

{% block banner %}
Account aangemaakt
{% endblock %}

Expand Down
8 changes: 6 additions & 2 deletions api/templates/api/mail/new_account.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{% extends 'mail/base.html' %}
{% extends 'cdh.mail/mail_template.html' %}

{% block subtitle %}
{% block sender %}
Taal-experimenten
{% endblock %}

{% block banner %}
Account aangemaakt
{% endblock %}

Expand Down
16 changes: 0 additions & 16 deletions api/templates/api/mail/new_appointment.html

This file was deleted.

3 changes: 0 additions & 3 deletions api/templates/api/mail/new_appointment.txt

This file was deleted.

33 changes: 0 additions & 33 deletions api/templates/api/mail/new_appointment_timeslot.html

This file was deleted.

17 changes: 0 additions & 17 deletions api/templates/api/mail/new_appointment_timeslot.txt

This file was deleted.

10 changes: 7 additions & 3 deletions api/templates/api/mail/participant_cancelled.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{% extends 'mail/base.html' %}
{% extends 'cdh.mail/mail_template.html' %}

{% block subtitle %}
{% block sender %}
Taal-experimenten
{% endblock %}

{% block banner %}
Participant deregistered for experiment: <strong>{{ experiment.name }}</strong>
{% endblock %}

Expand Down Expand Up @@ -29,4 +33,4 @@
<p>
This email was generated automatically because you are listed as the leader for experiment {{ experiment.name }}.
</p>
{% endblock %}
{% endblock %}
7 changes: 4 additions & 3 deletions api/templates/api/mail/password_reset.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends 'mail/base.html' %}
{% extends 'cdh.mail/mail_template.html' %}

{% block subtitle %}
{% block sender %}
Taal-experimenten
{% endblock %}

{% block content %}
Expand Down Expand Up @@ -30,4 +31,4 @@


{% block footer %}
{% endblock %}
{% endblock %}
144 changes: 40 additions & 104 deletions api/utils/appointment_mail.py
Original file line number Diff line number Diff line change
@@ -1,132 +1,68 @@
import re

from django.conf import settings
from django.template import defaultfilters
from django.utils.html import strip_tags
from django.utils.safestring import mark_safe
from django.utils.timezone import localtime
import urllib.parse as parse

from uil.core.utils.mail import send_template_email
from experiments.emails import ConfirmationEmail

from experiments.models import Experiment, TimeSlot
from main.utils import get_supreme_admin
from participants.models import Participant

CANCEL_LINK_REGEX = r'{cancel_link(?::\"(.*)\")?}'


def get_initial_confirmation_context(experiment: Experiment) -> dict:
context = {
'experiment_name': experiment.name,
'experiment_location': '',
'leader_name': experiment.leader.name,
'leader_email': experiment.leader.api_user.email,
'leader_phonenumber': experiment.leader.phonenumber,
'all_leaders_name_list': experiment.all_leaders_str,
'cancel_link': parse.urljoin(
settings.FRONTEND_URI,
'participant/cancel/'
),
}

if experiment.location:
context['experiment_location'] = experiment.location.name

return context


def send_appointment_mail(
experiment: Experiment,
participant: Participant,
time_slot: TimeSlot,
) -> None:
admin = get_supreme_admin()
template = 'api/mail/new_appointment'

subject = 'Bevestiging inschrijving experiment ILS Labs: {}'.format(
experiment.name
)
# Should not happen, but as that field technically now can be none we make
# sure to handle it.
if participant.email is None:
return

replacements = {
'{experiment_name}': experiment.name,
'{experiment_location}': '',
'{participant_name}': participant.name,
'{leader_name}': experiment.leader.name,
'{leader_email}': experiment.leader.api_user.email,
'{leader_phonenumber}': experiment.leader.phonenumber,
'{all_leaders_name_list}': experiment.leader.name,
}

num_additional_leaders = experiment.additional_leaders.count()

if num_additional_leaders > 0:
last_leader = experiment.additional_leaders.last()
others = experiment.additional_leaders.exclude(pk=last_leader.pk)

# If there's one additional, don't add the comma as it looks weird
if num_additional_leaders > 1:
replacements['{all_leaders_name_list}'] += ", "

replacements['{all_leaders_name_list}'] += ", ".join(
[x.name for x in others]
)
replacements['{all_leaders_name_list}'] += f" en {last_leader.name}"

if experiment.location:
replacements['{experiment_location}'] = experiment.location.name
context = get_initial_confirmation_context(experiment)
context.update({
'name': participant.mail_name,
})

if experiment.use_timeslots:
# We don't use strftime because that's not _always_ timezone aware
# Also, using the template filter is a neat hack to have the same format
# string syntax everywhere
replacements.update({
'{date}': defaultfilters.date(localtime(time_slot.datetime), 'l d-m-Y'),
'{time}': defaultfilters.date(localtime(time_slot.datetime), 'H:i'),
context.update({
'date': defaultfilters.date(localtime(time_slot.datetime), 'l d-m-Y'),
'time': defaultfilters.date(localtime(time_slot.datetime), 'H:i'),
})

send_template_email(
[participant.email],
subject,
template,
{
'experiment': experiment,
'html_content': _parse_contents_html(
experiment.confirmation_email,
replacements
),
'plain_content': _parse_contents_plain(
experiment.confirmation_email,
replacements
)
},
settings.EMAIL_FROM
email = ConfirmationEmail(
to=[participant.email],
subject='Bevestiging inschrijving experiment ILS Labs: {}'.format(
experiment.name
),
contents=experiment.confirmation_email,
context=context,
)


def _parse_contents_html(
content: str,
replacements: dict,
) -> str:
match = re.search(CANCEL_LINK_REGEX, content)

if match:
replacement = "<a href=\"{}\">{}</a>".format(
parse.urljoin(settings.FRONTEND_URI, 'participant/cancel/'),
match.group(1)
)
content = content.replace(match.group(0), replacement)

content = _apply_replacements(content, replacements)

return mark_safe(content)


def _parse_contents_plain(
content: str,
replacements: dict,
) -> str:
# Remove all HTML
content = strip_tags(content)

match = re.search(CANCEL_LINK_REGEX, content)

if match:
replacement = "{} ({})".format(
match.group(1),
parse.urljoin(settings.FRONTEND_URI, 'participant/cancel/'),
)
content = content.replace(match.group(0), replacement)

content = _apply_replacements(content, replacements)

return mark_safe(content)


def _apply_replacements(content: str, replacements: dict) -> str:

for key, value in replacements.items():
content = content.replace(key, value)

return content
email.send()

Loading
Loading