Mercurial > public > sg101
annotate contact/views.py @ 1144:c31008989a16
Convert home page to V3 design.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 14 Nov 2016 19:29:34 -0600 |
parents | 6ac56115e0a8 |
children | b957e4829a03 |
rev | line source |
---|---|
bgneal@819 | 1 """Views for the contact application.""" |
gremmie@1 | 2 |
bgneal@819 | 3 from django.shortcuts import redirect, render |
bgneal@1070 | 4 from django.views.generic import TemplateView |
gremmie@1 | 5 |
gremmie@1 | 6 from contact.forms import ContactForm |
gremmie@1 | 7 from core.functions import get_full_name |
gremmie@1 | 8 |
gremmie@1 | 9 |
gremmie@1 | 10 def contact_form(request): |
bgneal@819 | 11 if request.method == 'POST': |
bgneal@819 | 12 form = ContactForm(request.POST) |
bgneal@819 | 13 if form.is_valid(): |
bgneal@819 | 14 form.save() |
bgneal@819 | 15 return redirect('contact-thanks') |
bgneal@819 | 16 else: |
bgneal@819 | 17 initial_data = {} |
bgneal@819 | 18 if request.user.is_authenticated(): |
bgneal@1070 | 19 name = get_full_name(request.user).strip() |
bgneal@1070 | 20 if name != request.user.username: |
bgneal@1070 | 21 name = '{} ({})'.format(name, request.user.username) |
bgneal@1070 | 22 |
bgneal@819 | 23 initial_data = {'name': name, 'email': request.user.email} |
gremmie@1 | 24 |
bgneal@819 | 25 subject = request.GET.get('subject') |
bgneal@819 | 26 if subject: |
bgneal@819 | 27 initial_data['subject'] = subject |
gremmie@1 | 28 |
bgneal@819 | 29 form = ContactForm(initial=initial_data) |
gremmie@1 | 30 |
bgneal@1070 | 31 return render(request, 'contact/contact_form.html', { |
bgneal@1070 | 32 'form': form, |
bgneal@1070 | 33 'V3_DESIGN': True, |
bgneal@1070 | 34 }) |
bgneal@1070 | 35 |
bgneal@1070 | 36 |
bgneal@1070 | 37 class ContactThanksView(TemplateView): |
bgneal@1070 | 38 template_name = 'contact/contact_thanks.html' |
bgneal@1070 | 39 |
bgneal@1070 | 40 def get_context_data(self, **kwargs): |
bgneal@1070 | 41 context = super(ContactThanksView, self).get_context_data(**kwargs) |
bgneal@1070 | 42 context['V3_DESIGN'] = True |
bgneal@1070 | 43 return context |