X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/a7e41fefbf46ad5bfa2eb97dbd1cc11d3a28a354..ca8f4e8fef80cb603117ed579da8554f503698e5:/src/messaging/views.py?ds=inline
diff --git a/src/messaging/views.py b/src/messaging/views.py
index be83d95f2..b4dbc2693 100644
--- a/src/messaging/views.py
+++ b/src/messaging/views.py
@@ -2,10 +2,24 @@ import json
from django.http import JsonResponse
from django.urls import reverse
from django.shortcuts import render
-from django.utils.translation import ugettext as _
-from .states import states
+from django.views.decorators import cache
+from django.views.generic import DetailView, UpdateView
+from . import models
+from .states import Level, states
+def describe(value):
+ if hasattr(value, '_meta'):
+ meta = value._meta
+ return '''objekt typu %(verbose_name)s.''' % {
+ 'docs_url': reverse('django-admindocs-models-detail', args=(meta.app_label, meta.model_name)),
+ 'verbose_name': meta.verbose_name,
+ }
+ else:
+ return type(value).__name__
+
+
+@cache.never_cache
def state_info(request, slug):
for state in states:
if state.slug == slug:
@@ -13,19 +27,37 @@ def state_info(request, slug):
else:
return JsonResponse({})
- meta = state().get_objects().model._meta
-
-
- help_text = _('''Context:
- {{ %(model_name)s }}
â a %(verbose_name)s object.
- You can put it in in the fields Subject and Body using dot notation, like this:
- {{ %(model_name)s.id }}
.''') % {
- 'model_name': meta.model_name,
- 'docs_url': reverse('django-admindocs-models-detail', args=(meta.app_label, meta.model_name)),
- 'verbose_name': meta.verbose_name,
- }
+ contact = models.Contact()
+ ctx = {
+ "contact": contact,
+ }
+ ctx.update(state(test=True).get_context(contact))
+ help_text = 'Kontekst:
'
+ for k, v in ctx.items():
+ help_text += '
{{ %s }}
â %s
' % (k, describe(v))
return JsonResponse({
"help": help_text,
})
+
+class OptOutView(UpdateView):
+ model = models.Contact
+ slug_url_kwarg = 'key'
+ slug_field = 'key'
+ 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'
+
+