2 from django.http import JsonResponse
3 from django.urls import reverse
4 from django.shortcuts import render
5 from django.views.decorators import cache
6 from django.views.generic import DetailView, UpdateView
8 from .states import Level, states
12 if hasattr(value, '_meta'):
14 return '''objekt typu <a href="%(docs_url)s">%(verbose_name)s</a>.''' % {
15 'docs_url': reverse('django-admindocs-models-detail', args=(meta.app_label, meta.model_name)),
16 'verbose_name': meta.verbose_name,
19 return type(value).__name__
23 def state_info(request, slug):
25 if state.slug == slug:
28 return JsonResponse({})
30 contact = models.Contact()
34 ctx.update(state(test=True).get_context(contact))
35 help_text = 'Kontekst:<br>'
36 for k, v in ctx.items():
37 help_text += '<br><code>{{ %s }}</code> — %s<br>' % (k, describe(v))
44 class OptOutView(UpdateView):
45 model = models.Contact
46 slug_url_kwarg = 'key'
50 def get_success_url(self):
51 return reverse('messaging_optout_ok', args=[self.object.key])
53 def form_valid(self, form):
54 self.object.ascend(Level.OPT_OUT)
55 return super().form_valid(form)
58 class OptOutOkView(DetailView):
59 model = models.Contact
60 slug_url_kwarg = 'key'