Mercurial > public > sg101
annotate contact/views.py @ 948:f2fbe2b0d25d
Use unicode to log messages.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 16 May 2015 15:02:04 -0500 |
parents | 38db6ec61af3 |
children | 6ac56115e0a8 |
rev | line source |
---|---|
bgneal@819 | 1 """Views for the contact application.""" |
gremmie@1 | 2 |
bgneal@819 | 3 from django.shortcuts import redirect, render |
gremmie@1 | 4 |
gremmie@1 | 5 from contact.forms import ContactForm |
gremmie@1 | 6 from core.functions import get_full_name |
gremmie@1 | 7 |
gremmie@1 | 8 |
gremmie@1 | 9 def contact_form(request): |
bgneal@819 | 10 if request.method == 'POST': |
bgneal@819 | 11 form = ContactForm(request.POST) |
bgneal@819 | 12 if form.is_valid(): |
bgneal@819 | 13 form.save() |
bgneal@819 | 14 return redirect('contact-thanks') |
bgneal@819 | 15 else: |
bgneal@819 | 16 initial_data = {} |
bgneal@819 | 17 if request.user.is_authenticated(): |
bgneal@819 | 18 name = get_full_name(request.user) |
bgneal@819 | 19 initial_data = {'name': name, 'email': request.user.email} |
gremmie@1 | 20 |
bgneal@819 | 21 subject = request.GET.get('subject') |
bgneal@819 | 22 if subject: |
bgneal@819 | 23 initial_data['subject'] = subject |
gremmie@1 | 24 |
bgneal@819 | 25 form = ContactForm(initial=initial_data) |
gremmie@1 | 26 |
bgneal@819 | 27 return render(request, 'contact/contact_form.html', {'form': form}) |