bgneal@820: """Views for the bandmap application. bgneal@820: bgneal@820: """ bgneal@820: from django.contrib.auth.decorators import login_required bgneal@820: from django.shortcuts import redirect, render bgneal@821: from django.contrib import messages as django_messages bgneal@820: bgneal@820: from bandmap.forms import BandForm bgneal@820: bgneal@820: bgneal@821: SUCCESS = "Successfully submitted {} for admin review. Thanks!" bgneal@821: bgneal@821: bgneal@820: def map_view(request): bgneal@820: return render(request, 'bandmap/map.html') bgneal@820: bgneal@820: bgneal@820: @login_required bgneal@820: def add_band(request): bgneal@820: """ bgneal@820: Provides the ability for a user to submit a new band to the map. bgneal@820: bgneal@820: """ bgneal@820: if request.method == 'POST': bgneal@820: form = BandForm(request.POST) bgneal@820: if form.is_valid(): bgneal@820: band = form.save(commit=False) bgneal@820: band.user = request.user bgneal@820: band.save() bgneal@821: django_messages.success(request, SUCCESS.format(band.name)) bgneal@825: return redirect('bandmap-add') bgneal@820: else: bgneal@820: form = BandForm() bgneal@820: bgneal@820: return render(request, 'bandmap/add.html', { bgneal@820: 'form': form, bgneal@820: })