Mercurial > public > sg101
diff contact/views.py @ 819:38db6ec61af3
Contact form can prepopulate subject field now.
Also updated code for PEP-8 and added tests.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 20 Sep 2014 14:05:52 -0500 |
parents | ee87ea74d46b |
children | 6ac56115e0a8 |
line wrap: on
line diff
--- a/contact/views.py Sat Sep 13 16:19:46 2014 -0500 +++ b/contact/views.py Sat Sep 20 14:05:52 2014 -0500 @@ -1,33 +1,27 @@ -# Create your views here. +"""Views for the contact application.""" -from django.shortcuts import render_to_response -from django.template import RequestContext -from django.http import HttpResponseRedirect -from django.core.urlresolvers import reverse +from django.shortcuts import redirect, render from contact.forms import ContactForm from core.functions import get_full_name def contact_form(request): - if request.method == 'POST': - form = ContactForm(request.POST) - if form.is_valid(): - form.save() - return HttpResponseRedirect(reverse('contact.views.contact_thanks')) - else: - initial_data = {} - if request.user.is_authenticated(): - name = get_full_name(request.user) - initial_data = {'name' : name, 'email' : request.user.email} + if request.method == 'POST': + form = ContactForm(request.POST) + if form.is_valid(): + form.save() + return redirect('contact-thanks') + else: + initial_data = {} + if request.user.is_authenticated(): + name = get_full_name(request.user) + initial_data = {'name': name, 'email': request.user.email} - form = ContactForm(initial = initial_data) + subject = request.GET.get('subject') + if subject: + initial_data['subject'] = subject - return render_to_response('contact/contact_form.html', - {'form' : form}, - context_instance = RequestContext(request)) + form = ContactForm(initial=initial_data) - -def contact_thanks(request): - return render_to_response('contact/contact_thanks.html', - context_instance = RequestContext(request)) + return render(request, 'contact/contact_form.html', {'form': form})