annotate bandmap/views.py @ 822:2c4f28b1c12a

Band map WIP: update admin dashboard for new band map entries.
author Brian Neal <bgneal@gmail.com>
date Wed, 24 Sep 2014 19:53:36 -0500
parents 71db8076dc3d
children d91356818cef
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@821 6 from django.contrib import messages as django_messages
bgneal@820 7
bgneal@820 8 from bandmap.forms import BandForm
bgneal@820 9
bgneal@820 10
bgneal@821 11 SUCCESS = "Successfully submitted {} for admin review. Thanks!"
bgneal@821 12
bgneal@821 13
bgneal@820 14 def map_view(request):
bgneal@820 15 return render(request, 'bandmap/map.html')
bgneal@820 16
bgneal@820 17
bgneal@820 18 @login_required
bgneal@820 19 def add_band(request):
bgneal@820 20 """
bgneal@820 21 Provides the ability for a user to submit a new band to the map.
bgneal@820 22
bgneal@820 23 """
bgneal@820 24 if request.method == 'POST':
bgneal@820 25 form = BandForm(request.POST)
bgneal@820 26 if form.is_valid():
bgneal@820 27 band = form.save(commit=False)
bgneal@820 28 band.user = request.user
bgneal@820 29 band.save()
bgneal@821 30 django_messages.success(request, SUCCESS.format(band.name))
bgneal@821 31 redirect('bandmap-add')
bgneal@820 32 else:
bgneal@820 33 form = BandForm()
bgneal@820 34
bgneal@820 35 return render(request, 'bandmap/add.html', {
bgneal@820 36 'form': form,
bgneal@820 37 })