bgneal@819: """Views for the contact application."""
gremmie@1: 
bgneal@819: from django.shortcuts import redirect, render
gremmie@1: 
gremmie@1: from contact.forms import ContactForm
gremmie@1: from core.functions import get_full_name
gremmie@1: 
gremmie@1: 
gremmie@1: def contact_form(request):
bgneal@819:     if request.method == 'POST':
bgneal@819:         form = ContactForm(request.POST)
bgneal@819:         if form.is_valid():
bgneal@819:             form.save()
bgneal@819:             return redirect('contact-thanks')
bgneal@819:     else:
bgneal@819:         initial_data = {}
bgneal@819:         if request.user.is_authenticated():
bgneal@819:             name = get_full_name(request.user)
bgneal@819:             initial_data = {'name': name, 'email': request.user.email}
gremmie@1: 
bgneal@819:         subject = request.GET.get('subject')
bgneal@819:         if subject:
bgneal@819:             initial_data['subject'] = subject
gremmie@1: 
bgneal@819:         form = ContactForm(initial=initial_data)
gremmie@1: 
bgneal@819:     return render(request, 'contact/contact_form.html', {'form': form})