From 427469edfcd7e1d44a1493048ffd08bd4c8c57c2 Mon Sep 17 00:00:00 2001 From: Alexander Burdeiny Date: Fri, 9 Sep 2016 09:17:29 +0300 Subject: [PATCH] admin statistic unsubscription fix and unique link fix --- .../django/newsletter/views/mailing_list.py | 32 ++++++++++++++++--- .../c_admin/newsletters/newsletter_stat.html | 2 +- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/emencia/django/newsletter/views/mailing_list.py b/emencia/django/newsletter/views/mailing_list.py index f25d9a2d..3472522c 100644 --- a/emencia/django/newsletter/views/mailing_list.py +++ b/emencia/django/newsletter/views/mailing_list.py @@ -24,8 +24,20 @@ def view_mailinglist_unsubscribe(request, slug, uidb36, token): newsletter.mailing_list.unsubscribers.add(contact) newsletter.mailing_list.save() already_unsubscribed = True - ContactMailingStatus.objects.create(newsletter=newsletter, contact=contact, - status=ContactMailingStatus.UNSUBSCRIPTION) + params = dict(newsletter=newsletter, + contact=contact, + status=ContactMailingStatus.UNSUBSCRIPTION) + if newsletter.ab_testing: + try: + ab_state = ContactMailingStatus.objects.filter( + newsletter=newsletter, + contact=contact, + status__in=(ContactMailingStatus.SENT_TEST, ContactMailingStatus.SENT), + ).order_by('-creation_date')[0].ab + params.update({'ab': ab_state}) + except: + pass + ContactMailingStatus.objects.create(**params) return HttpResponseRedirect(reverse_lazy('newsletter_mailinglist_unsubscribe_success')) @@ -87,8 +99,20 @@ class UnsubscribeView(DetailView): context = super(UnsubscribeView, self).get_context_data(**kwargs) context['subscribe'] = self.get_announce_form() # - ContactMailingStatus.objects.create(newsletter=self.object, contact=self.contact, - status=ContactMailingStatus.UNSUBSCRIPTION) + params = dict(newsletter=self.object, + contact=self.contact, + status=ContactMailingStatus.UNSUBSCRIPTION) + if self.object.ab_testing: + try: + ab_state = ContactMailingStatus.objects.filter( + newsletter=self.object, + contact=self.contact, + status__in=(ContactMailingStatus.SENT_TEST, ContactMailingStatus.SENT), + ).order_by('-creation_date')[0].ab + params.update({'ab': ab_state}) + except: + pass + ContactMailingStatus.objects.create(**params) return context diff --git a/templates/c_admin/newsletters/newsletter_stat.html b/templates/c_admin/newsletters/newsletter_stat.html index e9f399c3..e56f9ac9 100644 --- a/templates/c_admin/newsletters/newsletter_stat.html +++ b/templates/c_admin/newsletters/newsletter_stat.html @@ -95,7 +95,7 @@ Открыто(уникальных) - {{ statB.opened.data }} {% if statB.opened.percent %} ({{ statB.opened.percent|floatformat:"0" }}%) {% endif %} + {{ statB.opened.data }} {% if statB.opened.percent %} ({{ statB.opened.percent|floatformat:"0" }}%) {% endif %}/ {{ stat.opened.data_all }} Подробно