# HG changeset patch # User Brian Neal # Date 1411341629 18000 # Node ID 9a0df7bd240971dc581374c6b81b1dbb61d466fd # Parent 38db6ec61af37339261cdd88bfe79a5fbe6ae409 Bandmap application work in progress. Model defined. Map is displaying. Initial display of add form. diff -r 38db6ec61af3 -r 9a0df7bd2409 bandmap/admin.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bandmap/admin.py Sun Sep 21 18:20:29 2014 -0500 @@ -0,0 +1,18 @@ +"""Admin definitions for the bandmap application. + +""" +from django.contrib import admin + +from bandmap.models import BandEntry + + +class BandEntryAdmin(admin.ModelAdmin): + list_display = ['name', 'date_submitted', 'date_approved', 'is_active', + 'is_approved'] + date_hierarchy = 'date_submitted' + list_filter = ['date_submitted', 'is_active', 'is_approved'] + readonly_fields = ['lat', 'lon'] + search_fields = ['name', 'location', 'note'] + raw_id_fields = ['user'] + +admin.site.register(BandEntry, BandEntryAdmin) diff -r 38db6ec61af3 -r 9a0df7bd2409 bandmap/forms.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bandmap/forms.py Sun Sep 21 18:20:29 2014 -0500 @@ -0,0 +1,41 @@ +"""Forms for the bandmap application. + +""" +from django import forms + +from bandmap.models import BandEntry + + +class BandForm(forms.ModelForm): + """This form is used to add bands to the map.""" + class Meta: + model = BandEntry + fields = ['name', 'url', 'location', 'note', 'is_active', 'lat', 'lon'] + labels = { + 'name': 'Band name', + 'url': 'Link', + 'is_active': 'Band is currently active', + } + help_texts = { + 'url': 'Link to website or web presence (optional)', + 'location': 'See examples, above', + } + widgets = { + 'name': forms.TextInput(attrs={ + 'size': 64, + 'class': 'text'}), + 'url': forms.TextInput(attrs={ + 'size': 64, + 'class': 'text', + 'placeholder': 'http://'}), + 'location': forms.TextInput(attrs={ + 'size': 64, + 'class': 'text', + 'placeholder': 'Huntington Beach, CA, USA'}), + 'note': forms.TextInput(attrs={ + 'size': 64, + 'class': 'text', + 'placeholder': 'Optional short note about the band'}), + 'lat': forms.HiddenInput(), + 'lon': forms.HiddenInput(), + } diff -r 38db6ec61af3 -r 9a0df7bd2409 bandmap/models.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bandmap/models.py Sun Sep 21 18:20:29 2014 -0500 @@ -0,0 +1,34 @@ +"""Models for the bandmap application. + +""" +import datetime + +from django.db import models +from django.contrib.auth.models import User + + +class BandEntry(models.Model): + """Represents a band entry on the band map.""" + name = models.CharField(max_length=128) + user = models.ForeignKey(User) + date_submitted = models.DateTimeField() + date_approved = models.DateTimeField(null=True, blank=True) + url = models.URLField(blank=True, max_length=200) + location = models.CharField(max_length=255) + lat = models.FloatField() + lon = models.FloatField() + note = models.CharField(max_length=255, blank=True) + is_active = models.BooleanField(default=True, db_index=True) + is_approved = models.BooleanField(default=False, db_index=True) + + class Meta: + ordering = ['name'] + verbose_name_plural = 'band map entries' + + def __unicode__(self): + return u"BandMap entry for {}".format(self.name) + + def save(self, *args, **kwargs): + if not self.pk and not self.date_submitted: + self.date_submitted = datetime.datetime.now() + super(BandEntry, self).save(*args, **kwargs) diff -r 38db6ec61af3 -r 9a0df7bd2409 bandmap/static/css/bandmap.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bandmap/static/css/bandmap.css Sun Sep 21 18:20:29 2014 -0500 @@ -0,0 +1,6 @@ +#map-canvas { + width: 720px; + height: 540px; + border: 1px solid black; + margin: 0 auto; +} diff -r 38db6ec61af3 -r 9a0df7bd2409 bandmap/static/js/bandmap.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bandmap/static/js/bandmap.js Sun Sep 21 18:20:29 2014 -0500 @@ -0,0 +1,14 @@ +$(document).ready(function() { + var map_div = $('#map-canvas'); + if (map_div.length) { + var map_options = { + center: {lat: 15.0, lng: -30.0}, + zoom: 2 + }; + var map = new google.maps.Map(map_div[0], map_options); + } + + var add_form = $('#bandmap-add-form'); + if (add_form.length) { + } +}); diff -r 38db6ec61af3 -r 9a0df7bd2409 bandmap/tests.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bandmap/tests.py Sun Sep 21 18:20:29 2014 -0500 @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff -r 38db6ec61af3 -r 9a0df7bd2409 bandmap/urls.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bandmap/urls.py Sun Sep 21 18:20:29 2014 -0500 @@ -0,0 +1,11 @@ +"""urls for the bandmap application""" +from django.conf.urls import patterns, url + +urlpatterns = patterns('', + url(r'^$', + 'bandmap.views.map_view', + name='bandmap-map'), + url(r'^add/$', + 'bandmap.views.add_band', + name='bandmap-add'), +) diff -r 38db6ec61af3 -r 9a0df7bd2409 bandmap/views.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bandmap/views.py Sun Sep 21 18:20:29 2014 -0500 @@ -0,0 +1,32 @@ +"""Views for the bandmap application. + +""" +from django.contrib.auth.decorators import login_required +from django.shortcuts import redirect, render + +from bandmap.forms import BandForm + + +def map_view(request): + return render(request, 'bandmap/map.html') + + +@login_required +def add_band(request): + """ + Provides the ability for a user to submit a new band to the map. + + """ + if request.method == 'POST': + form = BandForm(request.POST) + if form.is_valid(): + band = form.save(commit=False) + band.user = request.user + band.save() + redirect('bandmap-thanks') + else: + form = BandForm() + + return render(request, 'bandmap/add.html', { + 'form': form, + }) diff -r 38db6ec61af3 -r 9a0df7bd2409 sg101/settings/base.py --- a/sg101/settings/base.py Sat Sep 20 14:05:52 2014 -0500 +++ b/sg101/settings/base.py Sun Sep 21 18:20:29 2014 -0500 @@ -113,6 +113,7 @@ 'tagging', 'accounts', 'antispam', + 'bandmap', 'banners', 'bio', 'bulletins', diff -r 38db6ec61af3 -r 9a0df7bd2409 sg101/templates/bandmap/add.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sg101/templates/bandmap/add.html Sun Sep 21 18:20:29 2014 -0500 @@ -0,0 +1,36 @@ +{% extends 'bandmap/bandmap_base.html' %} +{% block bandmap_content %} +

Add Band

+

+To add a band to our map, please fill out the form, below. The information will +be reviewed by our staff and will normally be published within 24 hours. +

+

The location field is important. Please enter an address and/or +city and state. For privacy reasons we don't recommend using an exact street +address unless it is a public place or landmark special to the band (such +a frequently played venue). Any text that you can use on Google Maps can be +used here. +

+

+Example locations: +

+ + +
{% csrf_token %} + +{{ form.as_table }} + + + + +
  + +
+
+{% endblock %} diff -r 38db6ec61af3 -r 9a0df7bd2409 sg101/templates/bandmap/bandmap_base.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sg101/templates/bandmap/bandmap_base.html Sun Sep 21 18:20:29 2014 -0500 @@ -0,0 +1,12 @@ +{% extends 'base.html' %} +{% block custom_css %} + +{% endblock %} +{% block custom_js %} + + +{% endblock %} +{% block content %} +

Surf Band Map

+{% block bandmap_content %}{% endblock %} +{% endblock %} diff -r 38db6ec61af3 -r 9a0df7bd2409 sg101/templates/bandmap/map.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sg101/templates/bandmap/map.html Sun Sep 21 18:20:29 2014 -0500 @@ -0,0 +1,7 @@ +{% extends 'bandmap/bandmap_base.html' %} +{% block bandmap_content %} +

Welcome to our surf band map! This map is updated by our users and displays +the locations of both active and inactive surf bands from around the world.

+
+

Add a band to the map. +{% endblock %} diff -r 38db6ec61af3 -r 9a0df7bd2409 sg101/urls.py --- a/sg101/urls.py Sat Sep 20 14:05:52 2014 -0500 +++ b/sg101/urls.py Sun Sep 21 18:20:29 2014 -0500 @@ -54,6 +54,7 @@ (r'^admin/', include(admin.site.urls)), (r'^accounts/', include('accounts.urls')), (r'^antispam/', include('antispam.urls')), + (r'^bandmap/', include('bandmap.urls')), (r'^calendar/', include('gcalendar.urls')), (r'^comments/', include('comments.urls')), (r'^contact/', include('contact.urls')),