diff --git a/aleksis/apps/paweljong/forms.py b/aleksis/apps/paweljong/forms.py index 46dade3deda9d17afca981ec628b68591465ef85..8a51d714bb6b574bc8412ed83d535800d6f16fb3 100644 --- a/aleksis/apps/paweljong/forms.py +++ b/aleksis/apps/paweljong/forms.py @@ -476,3 +476,17 @@ class EditInfoMailingForm(forms.ModelForm): class Meta: model = InfoMailing exclude = ["sent_to"] + + +class RegistrationNotificationForm(forms.ModelForm): + + layout = Layout( + Row("sender", "reply_to"), + Row("send_to_person", "send_to_guardians"), + Row("subject"), + Row("text"), + ) + + class Meta: + model = InfoMailing + exclude = ["sent_to", "active"] diff --git a/aleksis/apps/paweljong/templates/paweljong/event_registration/full.html b/aleksis/apps/paweljong/templates/paweljong/event_registration/full.html index ba22d3006f4e79607936242a62d5f5b03b8e5ac6..351c67ddc63e2a643adbbe289580083badfc2707 100644 --- a/aleksis/apps/paweljong/templates/paweljong/event_registration/full.html +++ b/aleksis/apps/paweljong/templates/paweljong/event_registration/full.html @@ -12,8 +12,9 @@ {% has_perm 'paweljong.manage_registration' user registration as can_manage_registration %} {% has_perm 'paweljong.delete_registration' user registration as can_delete_registration %} + {% has_perm 'paweljong.send_notification_mail' user registration as can_send_notification %} - {% if can_manage_registration or can_manage_registration_preferences or can_delete_registration %} + {% if can_manage_registration or can_manage_registration_preferences or can_delete_registration or can_send_notification %} <p> {% if can_manage_registration %} <a href="{% url 'edit_registration_by_pk' registration.pk %}" class="btn waves-effect waves-light"> @@ -29,6 +30,13 @@ </a> {% endif %} + {% if can_send_notification %} + <a href="{% url 'registration_notification_by_pk' registration.pk %}" class="btn waves-effect waves-light"> + <i class="material-icons left">email</i> + {% trans "Notification" %} + </a> + {% endif %} + </p> {% endif %} diff --git a/aleksis/apps/paweljong/templates/paweljong/event_registration/notification.html b/aleksis/apps/paweljong/templates/paweljong/event_registration/notification.html new file mode 100644 index 0000000000000000000000000000000000000000..86faa742b4a60bf6c5fd9aefb0e20681aee7b443 --- /dev/null +++ b/aleksis/apps/paweljong/templates/paweljong/event_registration/notification.html @@ -0,0 +1,20 @@ +{% extends "core/base.html" %} +{% load material_form i18n any_js %} + +{% block page_title %}{% blocktrans %}Send notification{% endblocktrans %}{% endblock %} +{% block browser_title %}{% blocktrans %}Send notification{% endblocktrans %}{% endblock %} + +{% block extra_head %} + {{ form.media.css }} +{% endblock %} + +{% block content %} + + <form method="post"> + {% csrf_token %} + {% form form=form %}{% form %} + {% include "core/partials/save_button.html" %} + </form> + {{ form.media.js }} + +{% endblock %} diff --git a/aleksis/apps/paweljong/templates/templated_email/event_notification.email b/aleksis/apps/paweljong/templates/templated_email/event_notification.email new file mode 100644 index 0000000000000000000000000000000000000000..946f635afbdfca45318bf3dda4232cbdf11a3c6c --- /dev/null +++ b/aleksis/apps/paweljong/templates/templated_email/event_notification.email @@ -0,0 +1,3 @@ +{% block subject %}{{ subject }}{% endblock %} + +{% block html %}{{ body|safe }}{% endblock %} diff --git a/aleksis/apps/paweljong/urls.py b/aleksis/apps/paweljong/urls.py index e90bde07f8ef1bbc3ebcb2575bbf58c9f100a55c..d2a43fd5c9a994cdc33720944ea85d12b3ce79ce 100644 --- a/aleksis/apps/paweljong/urls.py +++ b/aleksis/apps/paweljong/urls.py @@ -87,6 +87,11 @@ urlpatterns = [ views.EventRegistrationDeleteView.as_view(), name="delete_registration_by_pk", ), + path( + "event/registrations/<int:pk>/notification", + views.SendMailFromRegistration.as_view(), + name="registration_notification_by_pk", + ), path( "event/terms/list", views.TermListView.as_view(), diff --git a/aleksis/apps/paweljong/views.py b/aleksis/apps/paweljong/views.py index 429f4c1f8601320917fa06eacd6edb6d5aa582ee..9786d3140eb75f828fe516c4f27ce29b47eb1e8c 100644 --- a/aleksis/apps/paweljong/views.py +++ b/aleksis/apps/paweljong/views.py @@ -11,7 +11,7 @@ from django.utils.decorators import method_decorator from django.utils.text import slugify from django.utils.translation import ugettext as _ from django.views.decorators.cache import never_cache -from django.views.generic import TemplateView +from django.views.generic import FormView, TemplateView from django.views.generic.detail import DetailView import reversion @@ -36,6 +36,7 @@ from .forms import ( EditTermForm, EditVoucherForm, GenerateListForm, + RegistrationNotificationForm, ) from .models import Event, EventRegistration, InfoMailing, Terms, Voucher from .tables import ( @@ -820,3 +821,42 @@ class InfoMailingDeleteView(PermissionRequiredMixin, AdvancedDeleteView): template_name = "core/pages/delete.html" success_url = reverse_lazy("info_mailings") success_message = _("The info mailing has been deleted.") + + +class SendMailFromRegistration(PermissionRequiredMixin, FormView): + + template_name = "paweljong/event_registration/notification.html" + permission_required = "paweljong.send_notification_mail" + form_class = RegistrationNotificationForm + success_url = reverse_lazy("registrations") + + def form_valid(self, form): + + registration = EventRegistration.objects.get(id=self.kwargs["pk"]) + + context = {} + recipient_list = [] + context["subject"] = form.cleaned_data["subject"] + context["registration"] = registration + context["body"] = form.cleaned_data["text"] + + if form.cleaned_data["reply_to"]: + reply_to = form.cleaned_data["reply_to"] + else: + reply_to = form.cleaned_data["sender"] + if form.cleaned_data["send_to_person"]: + recipient_list.append(registration.person.email) + if form.cleaned_data["send_to_guardians"]: + recipient_list.append(registration.person.guardians.first().email) + + send_templated_mail( + template_name="event_notification", + from_email=get_site_preferences()["mail__address"], + recipient_list=recipient_list, + headers={ + "reply_to": reply_to, + }, + context=context, + ) + + return super().form_valid(self)