2 from django.http import JsonResponse
3 from django.urls import reverse
4 from django.shortcuts import render
5 from django.utils.translation import gettext as _
6 from django.views.decorators import cache
7 from django.views.generic import DetailView, UpdateView
9 from .states import Level, states
13 if hasattr(value, '_meta'):
15 return _('''a <a href="%(docs_url)s">%(verbose_name)s</a> object.''') % {
16 'docs_url': reverse('django-admindocs-models-detail', args=(meta.app_label, meta.model_name)),
17 'verbose_name': meta.verbose_name,
20 return type(value).__name__
24 def state_info(request, slug):
26 if state.slug == slug:
29 return JsonResponse({})
31 contact = models.Contact()
35 ctx.update(state(test=True).get_context(contact))
36 help_text = '%s:<br>' % _('Context')
37 for k, v in ctx.items():
38 help_text += '<br><code>{{ %s }}</code> — %s<br>' % (k, describe(v))
45 class OptOutView(UpdateView):
46 model = models.Contact
47 slug_url_kwarg = 'key'
51 def get_success_url(self):
52 return reverse('messaging_optout_ok', args=[self.object.key])
54 def form_valid(self, form):
55 self.object.ascend(Level.OPT_OUT)
56 return super().form_valid(form)
59 class OptOutOkView(DetailView):
60 model = models.Contact
61 slug_url_kwarg = 'key'