Mercurial > public > sg101
annotate bandmap/views.py @ 825:d91356818cef
Bandmap WIP: added test to add band.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 25 Sep 2014 21:15:22 -0500 |
parents | 71db8076dc3d |
children | 5103edd3acc4 |
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@825 | 31 return 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 }) |