comparison contact/views.py @ 1070:6ac56115e0a8

Convert contact form & views to V3.
author Brian Neal <bgneal@gmail.com>
date Sat, 09 Apr 2016 17:15:32 -0500
parents 38db6ec61af3
children b957e4829a03
comparison
equal deleted inserted replaced
1069:ae015fcec351 1070:6ac56115e0a8
1 """Views for the contact application.""" 1 """Views for the contact application."""
2 2
3 from django.shortcuts import redirect, render 3 from django.shortcuts import redirect, render
4 from django.views.generic import TemplateView
4 5
5 from contact.forms import ContactForm 6 from contact.forms import ContactForm
6 from core.functions import get_full_name 7 from core.functions import get_full_name
7 8
8 9
13 form.save() 14 form.save()
14 return redirect('contact-thanks') 15 return redirect('contact-thanks')
15 else: 16 else:
16 initial_data = {} 17 initial_data = {}
17 if request.user.is_authenticated(): 18 if request.user.is_authenticated():
18 name = get_full_name(request.user) 19 name = get_full_name(request.user).strip()
20 if name != request.user.username:
21 name = '{} ({})'.format(name, request.user.username)
22
19 initial_data = {'name': name, 'email': request.user.email} 23 initial_data = {'name': name, 'email': request.user.email}
20 24
21 subject = request.GET.get('subject') 25 subject = request.GET.get('subject')
22 if subject: 26 if subject:
23 initial_data['subject'] = subject 27 initial_data['subject'] = subject
24 28
25 form = ContactForm(initial=initial_data) 29 form = ContactForm(initial=initial_data)
26 30
27 return render(request, 'contact/contact_form.html', {'form': form}) 31 return render(request, 'contact/contact_form.html', {
32 'form': form,
33 'V3_DESIGN': True,
34 })
35
36
37 class ContactThanksView(TemplateView):
38 template_name = 'contact/contact_thanks.html'
39
40 def get_context_data(self, **kwargs):
41 context = super(ContactThanksView, self).get_context_data(**kwargs)
42 context['V3_DESIGN'] = True
43 return context