Commit 78977bd7 authored by fred's avatar fred
Browse files

add trivial anti-bot feature on subscribe view

(this requires adding a checkbox on forms)
parent b381e282
......@@ -10,7 +10,7 @@ from django.conf import settings
from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse_lazy
from django.db import models, IntegrityError
from django.http import JsonResponse
from django.http import JsonResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.utils.http import urlencode
from django.utils.translation import ugettext as _
......@@ -31,6 +31,15 @@ class SubscribeView(CreateView):
form_class = SubscribeForm
model = Subscriber
success_url = reverse_lazy('newsletter-thanks')
def form_valid(self, form):
if 'validation' in self.request.POST:
# anti-bot checkbox, if present, do not create subscription,
# but redirect to success page nevertheless
return HttpResponseRedirect(self.success_url)
return super().form_valid(form)
subscribe = SubscribeView.as_view()
......
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