Commit feeccf48 authored by Robert's avatar Robert

Add basic unsubscribe view

parent dd42cdf4
__pycache__
.idea
build
db.sqlite3
db.sqlite3*
media
node_modules
prod_*.py
......
{% load rules utils %}
{% load fragments rules %}
{% has_perm 'content.change_content' user content as can_edit_content %}
<div class="content-data">
......@@ -10,7 +10,7 @@
Ändern
</a>
{% endif %}
{% include_features '_content_actions.html' %}
{% include_fragments 'content-actions' %}
{% if can_edit_content and not content.gallery %}
<a href="{% url 'content-image-list' content.pk %}" class="btn btn-default">
Bilder
......
......@@ -32,6 +32,13 @@ def fieldclass_factory(superclass, name, **kwargs):
return type(classname, (superclass,), kwargs)
class Constant(Field):
def get_data(self, form_data):
return self.value
constant = functools.partial(fieldclass_factory, Constant)
class Email(Field):
def get_form_field(self):
return forms.EmailField(label='E-Mail-Adresse')
......
from core import fragments
fragments.register(
'content-subscription-actions',
'subscriptions/_content_actions.html')
fragments.register(
'group-meta-subscriptions',
'subscriptions/_group_meta.html')
fragments.insert(
'content-subscription-actions',
'content-actions')
fragments.insert(
'group-meta-subscriptions',
'group-meta',
......
......@@ -5,18 +5,30 @@ from features.memberships import rules as memberships
import rules
@rules.predicate
def has_external_content_unsubscription_for(user, group):
return models.Subscription.objects.filter(
subscribed_to=group,
subscriber=user.gestalt,
unsubscribe=True,
).exists()
@rules.predicate
def is_subscribed_to(user, instance):
return models.Subscription.objects.filter(
subscribed_to=instance,
subscriber=user.gestalt
subscriber=user.gestalt,
unsubscribe=False,
).exists()
@rules.predicate
def is_subscriber(user, subscription):
if subscription:
return subscription.subscriber == user.gestalt
return (
not subscription.unsubscribe
and subscription.subscriber == user.gestalt)
return False
......@@ -30,6 +42,12 @@ rules.add_perm(
& ~associations.is_member_of_any_content_group
& ~is_subscribed_to))
rules.add_perm(
'subscriptions.create_external_content_unsubscription',
rules.is_authenticated
& memberships.is_member_of
& ~has_external_content_unsubscription_for)
rules.add_perm(
'subscriptions.create_group_subscription',
~rules.is_authenticated
......
......@@ -2,9 +2,10 @@
{% has_perm 'subscriptions.create_content_subscription' user content as can_subscribe %}
{% has_perm 'subscriptions.delete_subscription' user user.gestalt|subscription:content as can_unsubscribe %}
{% has_perm 'subscriptions.create_external_content_unsubscription' user content.groupcontent.group as can_unsubscribe_from_external_content %}
{% if can_unsubscribe %}
<a href="{% url 'content-unsubscribe' content.pk %}" class="btn btn-default" title="Du erhältst Benachrichtungen für diesen Beitrag">
{% if can_unsubscribe or can_unsubscribe_from_external_content %}
<a href="{% if can_unsubscribe %}{% url 'content-unsubscribe' content.pk %}{% else %}{% url 'external-content-unsubscribe' content.groupcontent.group.pk %}{% endif %}" class="btn btn-default" title="Du erhältst Benachrichtungen für diesen Beitrag">
<i class="sg sg-subscription"></i> Abonniert
</a>
{% elif not user.is_authenticated or can_subscribe %}
......
......@@ -12,6 +12,11 @@ urlpatterns = [
views.ContentUnsubscribe.as_view(),
name='content-unsubscribe'),
urls.url(
r'^group/(?P<group_pk>[0-9]+)/external-content-unsubscribe/$',
views.ExternalContentUnsubscribe.as_view(),
name='external-content-unsubscribe'),
urls.url(
r'^group/(?P<group_pk>[0-9]+)/subscribe/$',
views.GroupSubscribe.as_view(),
......
......@@ -74,3 +74,22 @@ class GroupUnsubscribe(Unsubscribe):
def get_related_object(self):
return self.get_group()
class ExternalContentUnsubscribe(SubscriptionMixin, groups.Mixin, views.Create):
permission = 'subscriptions.create_external_content_unsubscription'
action = 'Abbestellen'
description = (
'Keine Benachrichtigungen mehr für Gespräche der Gruppe '
'<em>{{ group }}</em> erhalten, deren Autor nicht Gruppenmitglied '
'ist')
message = 'Du erhältst nun keine Benachrichtigungen mehr.'
data_field_classes = (
fields.related_object('subscribed_to'),
fields.current_gestalt('subscriber'),
fields.constant('unsubscribe', value=True))
def get_related_object(self):
return self.get_group()
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