Mercurial > public > sg101
diff contact/views.py @ 581:ee87ea74d46b
For Django 1.4, rearranged project structure for new manage.py.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 05 May 2012 17:10:48 -0500 |
parents | gpp/contact/views.py@dbd703f7d63a |
children | 38db6ec61af3 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contact/views.py Sat May 05 17:10:48 2012 -0500 @@ -0,0 +1,33 @@ +# Create your views here. + +from django.shortcuts import render_to_response +from django.template import RequestContext +from django.http import HttpResponseRedirect +from django.core.urlresolvers import reverse + +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} + + form = ContactForm(initial = initial_data) + + return render_to_response('contact/contact_form.html', + {'form' : form}, + context_instance = RequestContext(request)) + + +def contact_thanks(request): + return render_to_response('contact/contact_thanks.html', + context_instance = RequestContext(request))