view contact/views.py @ 848:32ebe22f0cad

For issue #79 update to Markdown 2.5.1. This commit follows new Markdown conventions for extensions.
author Brian Neal <bgneal@gmail.com>
date Tue, 28 Oct 2014 19:33:14 -0500
parents 38db6ec61af3
children 6ac56115e0a8
line wrap: on
line source
"""Views for the contact application."""

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 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}

        subject = request.GET.get('subject')
        if subject:
            initial_data['subject'] = subject

        form = ContactForm(initial=initial_data)

    return render(request, 'contact/contact_form.html', {'form': form})