Commit 2c44468d authored by fred's avatar fred
Browse files

remove unused unsubscribe view

parent ce72764e
from django.conf.urls import url
from django.conf import settings
from .views import (subscribe, thanks, confirmation, stats, unsubscription,
from .views import (subscribe, thanks, confirmation, stats,
newsletter_list, newsletter_create, newsletter_view, newsletter_update,
newsletter_send)
......@@ -9,7 +9,6 @@ urlpatterns = [
url(r'^thanks/$', thanks, name='newsletter-thanks'),
url(r'^(?P<token>[0-9a-f]{40})$', confirmation, name='newsletter-confirmation'),
url(r'^stats/$', stats),
url(r'^unsubscription/$', unsubscription),
]
management_patterns = [
......
......@@ -68,41 +68,6 @@ class ConfirmationView(TemplateView):
confirmation = ConfirmationView.as_view()
def unsubscription(request) :
UNSUBSCRIPTION_MESSAGE = _("Enter your email for unsunscribe to the newsletter.")
UNSUBSCRIPTION_CONFIRMATION_MESSAGE = _("You're now unsubscribed")
if request.method == 'GET' :
form = SubscriptionForm()
return render(request, 'unsubscription_form.html', {'form' : form, 'message' : UNSUBSCRIPTION_MESSAGE})
elif request.method == 'POST' :
form = SubscriptionForm(request.POST)
if form.is_valid() :
cd = form.cleaned_data
try :
subscriber = Subscriber.objects.get(email = cd['email'])
cookie_jar = cookielib.CookieJar()
url_opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie_jar))
login_params = urlencode({'email' : subscriber.email, 'password' : subscriber.password})
login_request = urllib2.Request(settings.NEWSLETTER_UNSUBSCRIPTION_URL, login_params)
url = url_opener.open(login_request)
unsubscribe_action_url = ("%s/%s" % (settings.NEWSLETTER_UNSUBSCRIPTION_URL, subscriber.email))
unsubscribe_params = urlencode({'unsub' : 'Résilier', 'unsubconfirm' : '1'})
unsubscribe_request = urllib2.Request(unsubscribe_action_url, unsubscribe_params)
url = url_opener.open(unsubscribe_request)
url.close()
subscriber.delete()
return render(request, 'unsubscription_form.html', {'message' : UNSUBSCRIPTION_CONFIRMATION_MESSAGE})
except Subscriber.DoesNotExist :
error_message = _("The entered email address does not exist. Please try another one.")
return render(request, 'unsubscription_form.html', {'form' : form, 'message' : error_message})
class NewsletterCreateView(CreateView):
form_class = NewsletterForm
model = Newsletter
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment