changeset 820:9a0df7bd2409

Bandmap application work in progress. Model defined. Map is displaying. Initial display of add form.
author Brian Neal <bgneal@gmail.com>
date Sun, 21 Sep 2014 18:20:29 -0500 (2014-09-21)
parents 38db6ec61af3
children 71db8076dc3d
files bandmap/__init__.py bandmap/admin.py bandmap/forms.py bandmap/models.py bandmap/static/css/bandmap.css bandmap/static/js/bandmap.js bandmap/tests.py bandmap/urls.py bandmap/views.py sg101/settings/base.py sg101/templates/bandmap/add.html sg101/templates/bandmap/bandmap_base.html sg101/templates/bandmap/map.html sg101/urls.py
diffstat 13 files changed, 216 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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)
--- /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(),
+        }
--- /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)
--- /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;
+}
--- /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) {
+   }
+});
--- /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.
--- /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'),
+)
--- /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,
+        })
--- 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',
--- /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 %}
+<h3>Add Band</h3>
+<p>
+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.
+</p>
+<p>The <em>location</em> 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.
+</p>
+<p>
+Example locations:
+</p>
+<ul>
+   <li>3rd and Main, Chicago, IL</li>
+   <li>Tucson, Arizona</li>
+   <li>The Purple Orchid, El Segundo, CA</li>
+   <li>Rome, Italy</li>
+   <li>5018EA, Tilburg, Netherlands</li>
+</ul>
+
+<form id="bandmap-add-form" action="." method="post">{% csrf_token %}
+<table>
+{{ form.as_table }}
+<tr>
+   <td>&nbsp;</td>
+   <td>
+      <input type="submit" name="submit_button" value="Submit" />
+   </td>
+</tr>
+</table>
+</form>
+{% endblock %}
--- /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 %}
+<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/bandmap.css" />
+{% endblock %}
+{% block custom_js %}
+<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA8-qKS8Qi9vALxgndMLCdxQrRkXJ_CWNQ"></script>
+<script type="text/javascript" src="{{ STATIC_URL }}js/bandmap.js"></script>
+{% endblock %}
+{% block content %}
+<h2>Surf Band Map</h2>
+{% block bandmap_content %}{% endblock %}
+{% endblock %}
--- /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 %}
+<p>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.</p>
+<div id="map-canvas"></div>
+<p><a href="{% url 'bandmap-add' %}">Add a band to the map</a>.
+{% endblock %}
--- 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')),