annotate contact/views.py @ 1190:ce5a5c9cd9d8

Tweaks to MP3 comp tool
author Brian Neal <bgneal@gmail.com>
date Sun, 13 Mar 2022 13:09:37 -0500
parents b957e4829a03
children
rev   line source
bgneal@819 1 """Views for the contact application."""
gremmie@1 2
bgneal@1172 3 from django.conf import settings
bgneal@819 4 from django.shortcuts import redirect, render
bgneal@1070 5 from django.views.generic import TemplateView
gremmie@1 6
gremmie@1 7 from contact.forms import ContactForm
gremmie@1 8 from core.functions import get_full_name
gremmie@1 9
gremmie@1 10
gremmie@1 11 def contact_form(request):
bgneal@819 12 if request.method == 'POST':
bgneal@1172 13 form = ContactForm(request.POST, request=request)
bgneal@819 14 if form.is_valid():
bgneal@819 15 form.save()
bgneal@819 16 return redirect('contact-thanks')
bgneal@819 17 else:
bgneal@819 18 initial_data = {}
bgneal@819 19 if request.user.is_authenticated():
bgneal@1070 20 name = get_full_name(request.user).strip()
bgneal@1070 21 if name != request.user.username:
bgneal@1070 22 name = '{} ({})'.format(name, request.user.username)
bgneal@1070 23
bgneal@819 24 initial_data = {'name': name, 'email': request.user.email}
gremmie@1 25
bgneal@819 26 subject = request.GET.get('subject')
bgneal@819 27 if subject:
bgneal@819 28 initial_data['subject'] = subject
gremmie@1 29
bgneal@1172 30 form = ContactForm(initial=initial_data, request=request)
gremmie@1 31
bgneal@1070 32 return render(request, 'contact/contact_form.html', {
bgneal@1070 33 'form': form,
bgneal@1172 34 'RECAPTCHA_SITE_KEY': settings.RECAPTCHA_SITE_KEY,
bgneal@1070 35 'V3_DESIGN': True,
bgneal@1070 36 })
bgneal@1070 37
bgneal@1070 38
bgneal@1070 39 class ContactThanksView(TemplateView):
bgneal@1070 40 template_name = 'contact/contact_thanks.html'
bgneal@1070 41
bgneal@1070 42 def get_context_data(self, **kwargs):
bgneal@1070 43 context = super(ContactThanksView, self).get_context_data(**kwargs)
bgneal@1070 44 context['V3_DESIGN'] = True
bgneal@1070 45 return context