Skip to content
Snippets Groups Projects
Commit 159ed1d5 authored by Tom Teichler's avatar Tom Teichler :beers:
Browse files

Allow to send mails to person or guardians from registration

parent 8e8ed089
No related branches found
No related tags found
1 merge request!12Resolve "Send mail to guradians and/or participants from registration"
Pipeline #58345 failed
...@@ -476,3 +476,17 @@ class EditInfoMailingForm(forms.ModelForm): ...@@ -476,3 +476,17 @@ class EditInfoMailingForm(forms.ModelForm):
class Meta: class Meta:
model = InfoMailing model = InfoMailing
exclude = ["sent_to"] 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"]
...@@ -12,8 +12,9 @@ ...@@ -12,8 +12,9 @@
{% has_perm 'paweljong.manage_registration' user registration as can_manage_registration %} {% 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.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> <p>
{% if can_manage_registration %} {% if can_manage_registration %}
<a href="{% url 'edit_registration_by_pk' registration.pk %}" class="btn waves-effect waves-light"> <a href="{% url 'edit_registration_by_pk' registration.pk %}" class="btn waves-effect waves-light">
...@@ -29,6 +30,13 @@ ...@@ -29,6 +30,13 @@
</a> </a>
{% endif %} {% 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> </p>
{% endif %} {% endif %}
......
{% 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 %}
{% block subject %}{{ subject }}{% endblock %}
{% block html %}{{ body|safe }}{% endblock %}
...@@ -87,6 +87,11 @@ urlpatterns = [ ...@@ -87,6 +87,11 @@ urlpatterns = [
views.EventRegistrationDeleteView.as_view(), views.EventRegistrationDeleteView.as_view(),
name="delete_registration_by_pk", name="delete_registration_by_pk",
), ),
path(
"event/registrations/<int:pk>/notification",
views.SendMailFromRegistration.as_view(),
name="registration_notification_by_pk",
),
path( path(
"event/terms/list", "event/terms/list",
views.TermListView.as_view(), views.TermListView.as_view(),
......
...@@ -12,6 +12,7 @@ from django.utils.text import slugify ...@@ -12,6 +12,7 @@ from django.utils.text import slugify
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.views.decorators.cache import never_cache from django.views.decorators.cache import never_cache
from django.views.generic import TemplateView from django.views.generic import TemplateView
from django.views.generic import FormView
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
import reversion import reversion
...@@ -36,6 +37,7 @@ from .forms import ( ...@@ -36,6 +37,7 @@ from .forms import (
EditTermForm, EditTermForm,
EditVoucherForm, EditVoucherForm,
GenerateListForm, GenerateListForm,
RegistrationNotificationForm
) )
from .models import Event, EventRegistration, InfoMailing, Terms, Voucher from .models import Event, EventRegistration, InfoMailing, Terms, Voucher
from .tables import ( from .tables import (
...@@ -819,3 +821,42 @@ class InfoMailingDeleteView(PermissionRequiredMixin, AdvancedDeleteView): ...@@ -819,3 +821,42 @@ class InfoMailingDeleteView(PermissionRequiredMixin, AdvancedDeleteView):
template_name = "core/pages/delete.html" template_name = "core/pages/delete.html"
success_url = reverse_lazy("info_mailings") success_url = reverse_lazy("info_mailings")
success_message = _("The info mailing has been deleted.") 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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment