annotate contact/views.py @ 821:71db8076dc3d

Bandmap WIP: geocoding integrated with add form. Add form works. Before submitting the form, client side JS makes a geocode request to Google and populates hidden lat/lon fields with the result. Successfully created a model instance on the server side. Still need to update admin dashboard, admin approval, and give out badges for adding bands to the map. Once that is done, then work on displaying the map with filtering.
author Brian Neal <bgneal@gmail.com>
date Tue, 23 Sep 2014 20:40:31 -0500
parents 38db6ec61af3
children 6ac56115e0a8
rev   line source
bgneal@819 1 """Views for the contact application."""
gremmie@1 2
bgneal@819 3 from django.shortcuts import redirect, render
gremmie@1 4
gremmie@1 5 from contact.forms import ContactForm
gremmie@1 6 from core.functions import get_full_name
gremmie@1 7
gremmie@1 8
gremmie@1 9 def contact_form(request):
bgneal@819 10 if request.method == 'POST':
bgneal@819 11 form = ContactForm(request.POST)
bgneal@819 12 if form.is_valid():
bgneal@819 13 form.save()
bgneal@819 14 return redirect('contact-thanks')
bgneal@819 15 else:
bgneal@819 16 initial_data = {}
bgneal@819 17 if request.user.is_authenticated():
bgneal@819 18 name = get_full_name(request.user)
bgneal@819 19 initial_data = {'name': name, 'email': request.user.email}
gremmie@1 20
bgneal@819 21 subject = request.GET.get('subject')
bgneal@819 22 if subject:
bgneal@819 23 initial_data['subject'] = subject
gremmie@1 24
bgneal@819 25 form = ContactForm(initial=initial_data)
gremmie@1 26
bgneal@819 27 return render(request, 'contact/contact_form.html', {'form': form})