Mercurial > public > sg101
comparison contact/views.py @ 1172:b957e4829a03
Add reCAPTCHA to contact form
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 14 Apr 2018 13:53:05 -0500 |
parents | 6ac56115e0a8 |
children |
comparison
equal
deleted
inserted
replaced
1170:b213e4b333bb | 1172:b957e4829a03 |
---|---|
1 """Views for the contact application.""" | 1 """Views for the contact application.""" |
2 | 2 |
3 from django.conf import settings | |
3 from django.shortcuts import redirect, render | 4 from django.shortcuts import redirect, render |
4 from django.views.generic import TemplateView | 5 from django.views.generic import TemplateView |
5 | 6 |
6 from contact.forms import ContactForm | 7 from contact.forms import ContactForm |
7 from core.functions import get_full_name | 8 from core.functions import get_full_name |
8 | 9 |
9 | 10 |
10 def contact_form(request): | 11 def contact_form(request): |
11 if request.method == 'POST': | 12 if request.method == 'POST': |
12 form = ContactForm(request.POST) | 13 form = ContactForm(request.POST, request=request) |
13 if form.is_valid(): | 14 if form.is_valid(): |
14 form.save() | 15 form.save() |
15 return redirect('contact-thanks') | 16 return redirect('contact-thanks') |
16 else: | 17 else: |
17 initial_data = {} | 18 initial_data = {} |
24 | 25 |
25 subject = request.GET.get('subject') | 26 subject = request.GET.get('subject') |
26 if subject: | 27 if subject: |
27 initial_data['subject'] = subject | 28 initial_data['subject'] = subject |
28 | 29 |
29 form = ContactForm(initial=initial_data) | 30 form = ContactForm(initial=initial_data, request=request) |
30 | 31 |
31 return render(request, 'contact/contact_form.html', { | 32 return render(request, 'contact/contact_form.html', { |
32 'form': form, | 33 'form': form, |
34 'RECAPTCHA_SITE_KEY': settings.RECAPTCHA_SITE_KEY, | |
33 'V3_DESIGN': True, | 35 'V3_DESIGN': True, |
34 }) | 36 }) |
35 | 37 |
36 | 38 |
37 class ContactThanksView(TemplateView): | 39 class ContactThanksView(TemplateView): |