from django.db import models
from django.template import Template, Context
from django.urls import reverse
+from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _
from sentry_sdk import capture_exception
from catalogue.utils import get_random_hash
if not created:
obj.ascend(level, since, expires_at)
- def ascend(self, level, since, expires_at=None):
+ def ascend(self, level, since=None, expires_at=None):
+ if since is None:
+ since = now()
if level < self.level:
return
if level == self.level:
--- /dev/null
+{% extends "base/base.html" %}
+
+{% block body %}
+
+<h1>Adres wypisany</h1>
+
+{% if contact.level == 50 %}
+<p>Potwierdzamy, że adres {{ contact.email }} został wypisany z korespondencji.</p>
+{% else %}
+Błąd.
+{% endif %}
+
+{% endblock %}
<h1>Czy na pewno chcesz zrezygnować z otrzymywania e-maili na adres {{ object.email }}?</h1>
<form method="POST" action="">
+ {% csrf_token %}
<button type="submit">Tak, wypisz mnie</button>
</form>
urlpatterns = [
path('states/<slug>/info.json', views.state_info),
path('opt-out/<key>/', views.OptOutView.as_view(), name='messaging_optout'),
+ path('opt-out/<key>/ok/', views.OptOutOkView.as_view(), name='messaging_optout_ok'),
]
from django.shortcuts import render
from django.utils.translation import ugettext as _
from django.views.decorators import cache
-from django.views.generic import UpdateView
+from django.views.generic import DetailView, UpdateView
from . import models
-from .states import states
+from .states import Level, states
def describe(value):
model = models.Contact
slug_url_kwarg = 'key'
slug_field = 'key'
- fields = ['level']
+ fields = []
+
+ def get_success_url(self):
+ return reverse('messaging_optout_ok', args=[self.object.key])
+
+ def form_valid(self, form):
+ self.object.ascend(Level.OPT_OUT)
+ return super().form_valid(form)
+
+
+class OptOutOkView(DetailView):
+ model = models.Contact
+ slug_url_kwarg = 'key'
+ slug_field = 'key'
+