Commit 415286eb authored by Robert's avatar Robert

Add notifications

parent f8f43a8e
from core.notifications import Notification
def update_recipients(recipients_dict, association=None, subscriptions=[], contributions=[]):
def update_attributes(key, **kwargs):
attributes = recipients_dict.setdefault(key, {})
......@@ -13,3 +16,14 @@ def update_recipients(recipients_dict, association=None, subscriptions=[], contr
update_attributes(contribution.author, contribution=contribution)
if association and not association.entity.is_group:
update_attributes(association.entity, association=association)
class NoSubscriber(Notification):
subject = 'Abonnement'
def get_formatted_recipient(self):
return '<{}>'.format(self.recipient)
class Subscriber(Notification):
subject = 'Abonnement'
Jemand hat Deine E-Mail-Adresse auf {{ site.name }} angegeben.
Für Deine E-Mail-Adresse existiert kein Abonnenment der Gruppe {{ object }}.
Jemand hat Deine E-Mail-Adresse auf {{ site.name }} angegeben.
Wenn Du Dein Abonnement der Gruppe {{ object }} kündigen möchtest, bestätige dies bitte, indem Du dem folgenden Verweis folgst:
...
......@@ -6,10 +6,11 @@ from django.shortcuts import get_object_or_404
from django.views.generic import CreateView, DeleteView, FormView
from core.views import PermissionMixin
from features.gestalten.models import Gestalt
from features.groups.models import Group
from features.subscriptions.models import Subscription
from features.subscriptions.rules import is_subscribed
from . import forms
from . import forms, notifications
class GroupSubscribe(SuccessMessageMixin, PermissionMixin, CreateView):
......@@ -76,7 +77,12 @@ class GroupUnsubscribeRequest(PermissionMixin, FormView):
template_name = 'subscriptions/delete_request.html'
def form_valid(self, form):
email = form.cleaned_data['subscriber']
try:
subscriber = self.group.subscribers.get_by_email(email)
notifications.Subscriber(self.group).send(subscriber)
except Gestalt.DoesNotExist:
notifications.NoSubscriber(self.group).send(email)
info(self.request, 'Es wurde eine E-Mail an die angebene Adresse versendet.')
return super().form_valid(form)
......
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