annotate bandmap/views.py @ 820:9a0df7bd2409

Bandmap application work in progress. Model defined. Map is displaying. Initial display of add form.
author Brian Neal <bgneal@gmail.com>
date Sun, 21 Sep 2014 18:20:29 -0500
parents
children 71db8076dc3d
rev   line source
bgneal@820 1 """Views for the bandmap application.
bgneal@820 2
bgneal@820 3 """
bgneal@820 4 from django.contrib.auth.decorators import login_required
bgneal@820 5 from django.shortcuts import redirect, render
bgneal@820 6
bgneal@820 7 from bandmap.forms import BandForm
bgneal@820 8
bgneal@820 9
bgneal@820 10 def map_view(request):
bgneal@820 11 return render(request, 'bandmap/map.html')
bgneal@820 12
bgneal@820 13
bgneal@820 14 @login_required
bgneal@820 15 def add_band(request):
bgneal@820 16 """
bgneal@820 17 Provides the ability for a user to submit a new band to the map.
bgneal@820 18
bgneal@820 19 """
bgneal@820 20 if request.method == 'POST':
bgneal@820 21 form = BandForm(request.POST)
bgneal@820 22 if form.is_valid():
bgneal@820 23 band = form.save(commit=False)
bgneal@820 24 band.user = request.user
bgneal@820 25 band.save()
bgneal@820 26 redirect('bandmap-thanks')
bgneal@820 27 else:
bgneal@820 28 form = BandForm()
bgneal@820 29
bgneal@820 30 return render(request, 'bandmap/add.html', {
bgneal@820 31 'form': form,
bgneal@820 32 })