Mercurial > public > sg101
annotate bandmap/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 | 9a0df7bd2409 |
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 }) |