diff --git a/emencia/django/newsletter/urls/mailing_list.py b/emencia/django/newsletter/urls/mailing_list.py index f0716c82..a42238b6 100644 --- a/emencia/django/newsletter/urls/mailing_list.py +++ b/emencia/django/newsletter/urls/mailing_list.py @@ -1,7 +1,7 @@ """Urls for the emencia.django.newsletter Mailing List""" from django.conf.urls import url from django.conf.urls import patterns -from emencia.django.newsletter.views.mailing_list import UnsubscribeView +from emencia.django.newsletter.views.mailing_list import UnsubscribeView, UnsubscriptionSuccess from emencia.django.newsletter.forms import MailingListSubscriptionForm from emencia.django.newsletter.forms import AllMailingListSubscriptionForm @@ -20,6 +20,10 @@ urlpatterns = patterns('emencia.django.newsletter.views.mailing_list', 'unsubscription_handle', name='newsletter_mailinglist_unsubscribe_handle'), + url(r'^unsubscribe/success/$', + UnsubscriptionSuccess.as_view(), + name='newsletter_mailinglist_unsubscribe_success'), + url(r'^subscribe/(?P\d+)/', 'view_mailinglist_subscribe', {'form_class': MailingListSubscriptionForm}, diff --git a/emencia/django/newsletter/urls/tracking.py b/emencia/django/newsletter/urls/tracking.py index aca0a49d..5aae9e5e 100644 --- a/emencia/django/newsletter/urls/tracking.py +++ b/emencia/django/newsletter/urls/tracking.py @@ -1,6 +1,6 @@ """Urls for the emencia.django.newsletter Tracking""" -from django.conf.urls.defaults import url -from django.conf.urls.defaults import patterns +from django.conf.urls import url +from django.conf.urls import patterns urlpatterns = patterns('emencia.django.newsletter.views.tracking', url(r'^newsletter/(?P[-\w]+)/(?P[0-9A-Za-z]+)-(?P.+)\.(?Ppng|gif|jpg)$', diff --git a/emencia/django/newsletter/views/mailing_list.py b/emencia/django/newsletter/views/mailing_list.py index 8b4bbf29..2a1bd1c6 100644 --- a/emencia/django/newsletter/views/mailing_list.py +++ b/emencia/django/newsletter/views/mailing_list.py @@ -1,10 +1,12 @@ +# -*- coding: utf-8 -*- """Views for emencia.django.newsletter Mailing List""" from django.template import RequestContext from django.shortcuts import get_object_or_404 from django.shortcuts import render_to_response from django.contrib import messages from django.http import HttpResponseRedirect -from django.views.generic import DetailView +from django.views.generic import DetailView, TemplateView +from django.core.urlresolvers import reverse_lazy from emencia.django.newsletter.utils.tokens import untokenize from emencia.django.newsletter.models import Newsletter, MailingList, ContactMailingStatus, Contact, ContactSettings @@ -13,7 +15,6 @@ from emencia.django.newsletter.forms import SubscribeSettingsForm def view_mailinglist_unsubscribe(request, slug, uidb36, token): """hard Unsubscribe a contact to a mailing list""" - # todo: 111 newsletter = get_object_or_404(Newsletter, slug=slug) contact = untokenize(uidb36, token) @@ -24,20 +25,8 @@ def view_mailinglist_unsubscribe(request, slug, uidb36, token): already_unsubscribed = True ContactMailingStatus.objects.create(newsletter=newsletter, contact=contact, status=ContactMailingStatus.UNSUBSCRIPTION) - """ - if request.POST.get('email') and not already_unsubscribed: - newsletter.mailing_list.unsubscribers.add(contact) - newsletter.mailing_list.save() - already_unsubscribed = True - ContactMailingStatus.objects.create(newsletter=newsletter, contact=contact, - status=ContactMailingStatus.UNSUBSCRIPTION) - """ - - return render_to_response('newsletter/mailing_list_unsubscribe.html', - {'email': contact.email, - 'already_unsubscribed': already_unsubscribed}, - context_instance=RequestContext(request)) + return HttpResponseRedirect(reverse_lazy('newsletter_mailinglist_unsubscribe_success')) def view_mailinglist_subscribe(request, form_class, mailing_list_id=None): """ @@ -74,6 +63,7 @@ class UnsubscribeView(DetailView): def get_announce_form(self): contact = untokenize(self.kwargs.get('uidb36'), self.kwargs.get('token')) + self.contact= contact setting = contact.contactsettings initial = {'email': contact.email} @@ -97,6 +87,9 @@ class UnsubscribeView(DetailView): def get_context_data(self, **kwargs): 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) return context @@ -114,5 +107,10 @@ def unsubscription_handle(request): setting.save() form.save_m2m() form.save_additional_fields(setting) - messages.add_message(request, messages.INFO, u'Настройки вашой подписки успешно сохранены') - return HttpResponseRedirect('/') \ No newline at end of file + if form.cleaned_data.get('get_announce'): + messages.add_message(request, messages.INFO, u'Настройки вашой подписки успешно сохранены') + + return HttpResponseRedirect(reverse_lazy('newsletter_mailinglist_unsubscribe_success')) + +class UnsubscriptionSuccess(TemplateView): + template_name = 'client/newsletters/unsubscribe_success.html' diff --git a/templates/admin/newsletters/newsletter_list.html b/templates/admin/newsletters/newsletter_list.html index 4f8cc05f..6f7d712a 100644 --- a/templates/admin/newsletters/newsletter_list.html +++ b/templates/admin/newsletters/newsletter_list.html @@ -18,6 +18,8 @@ Дата отправки     +   +   @@ -29,6 +31,8 @@ {{ item.sending_date|date:"Y-m-d H:i" }} тест Изменить + История + {% if item.status == item.SENT or item.status == item.CANCELED %}Статистика{% endif %} {% endfor %} diff --git a/templates/client/base_catalog.html b/templates/client/base_catalog.html index 6eaf28e5..ac80542d 100644 --- a/templates/client/base_catalog.html +++ b/templates/client/base_catalog.html @@ -96,4 +96,5 @@ {% block popup %} {% include 'client/popups/announces.html' %} + {% include 'client/popups/announce_subscription.html' %} {% endblock %} diff --git a/templates/client/newsletters/unsubscribe_form.html b/templates/client/newsletters/unsubscribe_form.html index d900b00b..f16be816 100644 --- a/templates/client/newsletters/unsubscribe_form.html +++ b/templates/client/newsletters/unsubscribe_form.html @@ -27,7 +27,7 @@
+ {{ subscribe.get_announce.label }}
@@ -78,11 +78,11 @@
- +
- +
diff --git a/templates/client/newsletters/unsubscribe_success.html b/templates/client/newsletters/unsubscribe_success.html new file mode 100644 index 00000000..b6f8b154 --- /dev/null +++ b/templates/client/newsletters/unsubscribe_success.html @@ -0,0 +1,41 @@ +{% extends 'client/base_catalog.html' %} +{% load static %} +{% load i18n %} + + +{% block page_body %} + +
+
+
+ {% if messages %} +
+
+ {% trans 'Параметры вашей подписки изменены.' %} +
+ +
+ {% else %} +
+
+ {% trans 'Вы успешно отписаны' %} +
+ +
+ +
+
+
+ {% trans 'Мы очень сожалеем, что потеряли такого ценного подписчика как Вы! =( Но будем рады видеть Вас снова!' %} +
+
+ +
+ {% endif %} + + +
+
+
+ +{% endblock %} \ No newline at end of file diff --git a/templates/client/popups/announce_subscription.html b/templates/client/popups/announce_subscription.html new file mode 100644 index 00000000..c6e1a575 --- /dev/null +++ b/templates/client/popups/announce_subscription.html @@ -0,0 +1,71 @@ +{% load static %} +{% load i18n %} +{% if not request.COOKIES.subscribe_popup %} + + +{% endif %} \ No newline at end of file