Commit 2f0ce2a8 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Merge branch 'feature/eventPushNotification' into 'master'

Add sending of notification to participants of event by organisers

Closes #837

See merge request !1254
parents a877b3c6 f95b7363
......@@ -230,6 +230,10 @@ class EventAdmin(DoNextTranslatedModelAdmin):
self.admin_site.admin_view(
admin_views.EventRegistrationsMarkPresent.as_view()),
name='events_event_all_present'),
path('<int:pk>/message/',
self.admin_site.admin_view(
admin_views.EventMessage.as_view(admin=self)),
name='events_event_message'),
]
return custom_urls + urls
......
......@@ -5,7 +5,7 @@ from django.contrib.admin import helpers
from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse
from django.utils import timezone
from django.utils.decorators import method_decorator
......@@ -18,7 +18,8 @@ from django.views.generic import DetailView, TemplateView, FormView
from events import services
from events.decorators import organiser_only
from events.exceptions import RegistrationError
from events.forms import FieldsForm
from events.forms import FieldsForm, EventMessageForm
from pushnotifications.models import Message, Category
from .models import Event, Registration
......@@ -110,6 +111,74 @@ class RegistrationAdminFields(FormView):
))
@method_decorator(staff_member_required, name='dispatch')
@method_decorator(organiser_only, name='dispatch')
class EventMessage(FormView):
"""
Renders a form that allows the user to create a push notification for all
users registers to the event.
"""
form_class = EventMessageForm
template_name = 'events/admin/message_form.html'
admin = None
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context.update({
**self.admin.admin_site.each_context(self.request),
'add': False,
'change': True,
'has_view_permission': True,
'has_add_permission': False,
'has_change_permission':
self.request.user.has_perms('events.change_event'),
'has_delete_permission': False,
'has_editable_inline_admin_formsets': False,
'app_label': 'events',
'opts': self.event._meta,
'is_popup': False,
'save_as': False,
'save_on_top': False,
'original': self.event,
'obj_id': self.event.pk,
'title': _('Send push notification'),
'adminform': helpers.AdminForm(context['form'], (
(None, {
'fields': [f for f in context['form'].fields.keys()]
}),
), {})
})
return context
def form_valid(self, form):
values = form.cleaned_data
message = Message(
title_nl=values['title_nl'],
title_en=values['title_en'],
body_nl=values['title_nl'],
body_en=values['title_en'],
url=values['url'],
category=Category.objects.get(key='event')
)
message.save()
message.users.set([r.member for r in self.event.participants
if r.member])
message.send()
print(message)
messages.success(self.request,
_("Message sent successfully."))
if '_save' in self.request.POST:
return redirect(
'admin:events_event_details',
args=[str(self.event.pk)]
)
def dispatch(self, request, *args, **kwargs):
self.event = get_object_or_404(Event, pk=self.kwargs['pk'])
return super().dispatch(request, *args, **kwargs)
@method_decorator(staff_member_required, name='dispatch')
@method_decorator(organiser_only, name='dispatch')
class EventRegistrationsExport(View, PermissionRequiredMixin):
......
......@@ -86,3 +86,12 @@ class FieldsForm(forms.Form):
def field_values(self):
for key, field in self.information_fields.items():
yield (key, self.cleaned_data[key])
class EventMessageForm(forms.Form):
"""Form that outputs a widget to get info to send a push notification"""
title_en = forms.CharField(required=True, max_length=150)
title_nl = forms.CharField(required=True, max_length=150)
body_en = forms.CharField(required=True)
body_nl = forms.CharField(required=True)
url = forms.CharField(max_length=256)
......@@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-01-01 15:30+0100\n"
"PO-Revision-Date: 2019-01-01 15:33+0100\n"
"POT-Creation-Date: 2019-05-22 20:11+0200\n"
"PO-Revision-Date: 2019-05-22 20:13+0200\n"
"Last-Translator: Thom Wiggers <thom@thomwiggers.nl>\n"
"Language-Team: \n"
"Language: nl\n"
......@@ -16,7 +16,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.2\n"
"X-Generator: Poedit 1.8.7.1\n"
#: admin.py
msgid "lecture year"
......@@ -46,6 +46,22 @@ msgstr "Publiceer geselecteerde evenementen"
msgid "Unpublish selected events"
msgstr "Publicatie van geselecteerde evenementen ongedaan maken"
#: admin_views.py
msgid "Change registration fields"
msgstr "Verander registratie velden"
#: admin_views.py views.py
msgid "Registration successfully saved."
msgstr "Je aanmelding is succesvol opgeslagen."
#: admin_views.py
msgid "Send push notification"
msgstr "verstuur pushnotificatie"
#: admin_views.py
msgid "Message sent successfully."
msgstr "Pushnotificatie succesvol verzonden."
#: admin_views.py
msgid "Name"
msgstr "Naam"
......@@ -102,14 +118,6 @@ msgstr "wachtend"
msgid "Yes"
msgstr "Ja"
#: admin_views.py
msgid "Cash"
msgstr "Contant"
#: admin_views.py
msgid "Pin"
msgstr "Pin"
#: admin_views.py
msgid "No"
msgstr "Nee"
......@@ -190,7 +198,7 @@ msgstr "starttijd"
msgid "end time"
msgstr "eindtijd"
#: models.py templates/events/admin/details.html
#: models.py templates/events/admin/details.html templates/events/event.html
msgid "organiser"
msgstr "organisator"
......@@ -332,18 +340,6 @@ msgstr "De organisator heeft geen contact mailinglijst."
msgid "You cannot change this field after the registration has started."
msgstr "Je kunt dit veld niet aanpassen nadat de registratie is gestart."
#: models.py
msgid "No payment"
msgstr "Niet betaald"
#: models.py
msgid "Paid with cash"
msgstr "Contant betaald"
#: models.py
msgid "Paid with card"
msgstr "Pin betaald"
#: models.py templates/events/admin/registrations_table.html
msgid "name"
msgstr "naam"
......@@ -364,10 +360,6 @@ msgstr "afmelddatum"
msgid "present"
msgstr "aanwezig"
#: models.py
msgid "payment"
msgstr "betaling"
#: models.py
msgid "Either specify a member or a name"
msgstr "Geef een lid of een naam op"
......@@ -418,6 +410,10 @@ msgstr "Je mag je niet aanmelden."
msgid "You are not registered for this event."
msgstr "Je bent niet aangemeld voor dit evenement."
#: services.py
msgid "Unable to find the right registration."
msgstr "De juiste registratie is niet gevonden."
#: services.py
msgid "You are not allowed to update this registration."
msgstr "Je mag deze aanmelding niet bijwerken."
......@@ -475,6 +471,10 @@ msgstr "Exporteer e-mailadressen van aanwezigen"
msgid "Set all registered to paid and present"
msgstr "Zet iedereen op betaald en present"
#: templates/events/admin/details.html
msgid "Send pushnotification to registered users"
msgstr "Stuur pushnotificatie naar participerende gebruikers"
#: templates/events/admin/details.html
msgid "Event properties"
msgstr "Eigenschappen van evenement"
......@@ -531,6 +531,14 @@ msgstr ""
"Sommige geregistreerden zijn met de hand toegevoegd, en komen dus niet in de "
"bovenstaande lijst voor:"
#: templates/events/admin/fields_widget.html
msgid "Edit information fields"
msgstr "Wijzig informatie velden"
#: templates/events/admin/message_form.html
msgid "Send message"
msgstr "Stuur pushnotificatie"
#: templates/events/admin/registrations_table.html
msgid "not paid"
msgstr "niet betaald"
......@@ -833,7 +841,3 @@ msgstr "Je aanmelding was succesvol."
#: views.py
msgid "Registration successfully cancelled."
msgstr "Je afmelding was succesvol."
#: views.py
msgid "Registration successfully saved."
msgstr "Je aanmelding is succesvol opgeslagen."
......@@ -42,7 +42,7 @@
{% include 'events/admin/registrations_table.html' with registrations=event.participants %}
<br>
{% if event.queue.count > 0 %}
<h2>{% trans "waiting"|capfirst %}</h2>
<hregisterd2>{% trans "waiting"|capfirst %}</hregisterd2>
{% trans "queued" as queued %}
{% include 'events/admin/registrations_table.html' with registrations=event.queue verb=queued addlink=False %}
<br>
......@@ -55,6 +55,7 @@
<a href="{% url 'admin:events_event_export' pk=event.pk %}" class="button">{% trans "Export registrations" %}</a>
<a href="{% url 'admin:events_event_export_email' pk=event.pk %}" class="button">{% trans "Export email addresses of attendees" %}</a>
<a href="{% url 'admin:events_event_all_present' pk=event.pk %}" class="button">{% trans "Set all registered to paid and present" %}</a>
<a href="{% url 'admin:events_event_message' pk=event.pk %}" class="button">{% trans "Send pushnotification to registered users" %}</a>
</div>
</div>
{% endblock %}
......
{% extends "admin/change_form.html" %}
{% load i18n admin_urls static compress %}
{% block extrastyle %}
{{ block.super }}
{% compress css %}<link rel="stylesheet" type="text/x-scss" href="{% static 'admin/pushnotifications/css/forms.scss' %}" />{% endcompress %}
{% endblock %}
{% block submit_buttons_bottom %}
<div class="submit-row pushnotifications-row">
<input type="submit" value="{% trans 'Send message' %}" class="default button" name="_save" data-_extension-text-contrast="">
</div>
{% endblock %}
......@@ -11,7 +11,7 @@
}
}
.pushnotifications-row a.button {
.pushnotifications-row .button {
background-color: #e65c95;
font-size: 13px;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment