bgneal@819: """Views for the contact application.""" gremmie@1: bgneal@1172: from django.conf import settings bgneal@819: from django.shortcuts import redirect, render bgneal@1070: from django.views.generic import TemplateView 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@1172: form = ContactForm(request.POST, request=request) 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@1070: name = get_full_name(request.user).strip() bgneal@1070: if name != request.user.username: bgneal@1070: name = '{} ({})'.format(name, request.user.username) bgneal@1070: 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@1172: form = ContactForm(initial=initial_data, request=request) gremmie@1: bgneal@1070: return render(request, 'contact/contact_form.html', { bgneal@1070: 'form': form, bgneal@1172: 'RECAPTCHA_SITE_KEY': settings.RECAPTCHA_SITE_KEY, bgneal@1070: 'V3_DESIGN': True, bgneal@1070: }) bgneal@1070: bgneal@1070: bgneal@1070: class ContactThanksView(TemplateView): bgneal@1070: template_name = 'contact/contact_thanks.html' bgneal@1070: bgneal@1070: def get_context_data(self, **kwargs): bgneal@1070: context = super(ContactThanksView, self).get_context_data(**kwargs) bgneal@1070: context['V3_DESIGN'] = True bgneal@1070: return context