Merged with changes from local repo.
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tabc/templates/tabc/base.html Tue Sep 09 22:42:00 2008 -0500
1.3 @@ -0,0 +1,13 @@
1.4 +<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
1.5 +<html>
1.6 +<head>
1.7 + <title>{% block title %}{% endblock %}</title>
1.8 + {% block scripts %}{% endblock %}
1.9 + {% block style %}{% endblock %}
1.10 +</head>
1.11 +
1.12 +<body{% block body_extra %}{% endblock %}>
1.13 +{% block content %}{% endblock %}
1.14 +</body>
1.15 +
1.16 +</html>
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/tabc/templates/tabc/city.html Tue Sep 09 22:42:00 2008 -0500
2.3 @@ -0,0 +1,15 @@
2.4 +{% extends "tabc/base.html" %}
2.5 +{% block title %}GeoDjango Demo | TABC Licenses in {{ neighborhood }}{% endblock %}
2.6 +{% block scripts %}
2.7 +<script src="http://openlayers.org/api/2.6/OpenLayers.js" type="text/javascript"></script>
2.8 +<script src="http://openstreetmap.org/openlayers/OpenStreetMap.js" type="text/javascript"></script>
2.9 +<script type="text/javascript">
2.10 +//<![CDATA[
2.11 +{% include "tabc/city.js" %}
2.12 +//]]>
2.13 +</script>
2.14 +{% endblock %}
2.15 +{% block body_extra %} onload="init()" {% endblock %}
2.16 +{% block content %}
2.17 +<div id="map" style="width: 700px; height: 500px;"></div>
2.18 +{% endblock %}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/tabc/templates/tabc/city.js Tue Sep 09 22:42:00 2008 -0500
3.3 @@ -0,0 +1,39 @@
3.4 +var map;
3.5 +var wkt_f = new OpenLayers.Format.WKT();
3.6 +var alcohol_licenses = [{% for license in licenses %}wkt_f.read('{{ license.location.point.wkt }}'){% if not forloop.last %},{% endif %}{% endfor %}];
3.7 +var alcohol_style = {'strokeColor' : 'green', 'fillColor' : 'green', 'fillOpacity' : 0.4, 'pointRadius' : 6}
3.8 +for (var i = 0; i < alcohol_licenses.length; i++){alcohol_licenses[i].style = alcohol_style;}
3.9 +function init(){
3.10 + // The options hash, w/the number of zoom levels and the projection set to the
3.11 + // Google Maps Mercator Projection (SRID 900913).
3.12 + var options = {
3.13 + projection: new OpenLayers.Projection("EPSG:900913"),
3.14 + units: "m",
3.15 + maxResolution: 156543.0339,
3.16 + maxExtent: new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508),
3.17 + numZoomLevels: 19
3.18 + }
3.19 +
3.20 + // Base Map
3.21 + map = new OpenLayers.Map('map', options);
3.22 +
3.23 + // OSM Mapnik Layer
3.24 + var base_layer = new OpenLayers.Layer.OSM.Mapnik("Mapnik (by OSM)");
3.25 + map.addLayer(base_layer);
3.26 +
3.27 + // Controls for the map.
3.28 + map.addControl(new OpenLayers.Control.MousePosition());
3.29 + map.addControl(new OpenLayers.Control.LayerSwitcher());
3.30 +
3.31 + // Vector layers for the neighborhood and alchohol licensed establishements.
3.32 + var nbhood_vector = new OpenLayers.Layer.Vector("{{ neighborhood }}");
3.33 + var alcohol_vector = new OpenLayers.Layer.Vector("Establishments that Serve Alchohol");
3.34 + var neighborhood = wkt_f.read('{{ neighborhood.mpoly.wkt }}');
3.35 +
3.36 + // Zooming to the bounds.
3.37 + bounds = neighborhood.geometry.getBounds();
3.38 + nbhood_vector.addFeatures([neighborhood]);
3.39 + alcohol_vector.addFeatures(alcohol_licenses);
3.40 + map.zoomToExtent(bounds);
3.41 + map.addLayers([nbhood_vector, alcohol_vector]);
3.42 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/tabc/templates/tabc/city_index.html Tue Sep 09 22:42:00 2008 -0500
4.3 @@ -0,0 +1,9 @@
4.4 +{% extends "tabc/base.html" %}
4.5 +{% block title %}GeoDjango Demo | Available Neighborhoods for {{ city.name }}{% endblock %}
4.6 +{% block content %}
4.7 +<h3>{{ city.name }} Neighborhoods</h3>
4.8 +<ul>
4.9 +{% for nbhood in neighborhoods %} <li><a href="/{{ city.slug }}/{{ nbhood.name|slugify }}/">{{ nbhood.name }}</a></li>
4.10 +{% endfor %}
4.11 +</ul>
4.12 +{% endblock %}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/tabc/templates/tabc/home.html Tue Sep 09 22:42:00 2008 -0500
5.3 @@ -0,0 +1,8 @@
5.4 +{% extends "tabc/base.html" %}
5.5 +{% block title %}GeoDjango Demo | Available Cities{% endblock %}
5.6 +{% block content %}
5.7 + <ul>
5.8 +{% for city in cities %} <li><a href="/{{ city.slug }}/">{{ city.name }}</a></li>
5.9 +{% endfor %}
5.10 + </ul>
5.11 +{% endblock %}
6.1 --- a/tabc/views.py Tue Sep 09 22:38:09 2008 -0500
6.2 +++ b/tabc/views.py Tue Sep 09 22:42:00 2008 -0500
6.3 @@ -6,6 +6,31 @@
6.4 from where2.texas import Neighborhood
6.5
6.6 slug_dict = {}
6.7 +city_slugs = {}
6.8 +
6.9 +def by_key(key):
6.10 + "Used for sorting lists of dictionaries."
6.11 + def compare(obj1, obj2): return cmp(obj1[key], obj2[key])
6.12 + return compare
6.13 +
6.14 +def _init_city_slugs():
6.15 + for n in Neighborhood.objects.values('city'):
6.16 + city = n['city']
6.17 + city_slugs[slugify(city)] = city
6.18 +_init_city_slugs()
6.19 +
6.20 +def home(request):
6.21 + city_info = [{'name' : v, 'slug' : k} for k, v in city_slugs.items()]
6.22 + city_info.sort(by_key('name'))
6.23 + return render_to_response('tabc/home.html', {'cities' : city_info})
6.24 +
6.25 +def city_index(request, city):
6.26 + if not city in city_slugs:
6.27 + raise Http404('invalid city')
6.28 + c = {'slug' : city, 'name' : city_slugs[city]}
6.29 + qs = Neighborhood.objects.filter(city=c['name']).order_by('name')
6.30 + return render_to_response('tabc/city_index.html',
6.31 + {'city' : c, 'neighborhoods' : qs})
6.32
6.33 def city(request, city, nbhood):
6.34 # So we can map from slugs of the neighborhood name to the
6.35 @@ -23,7 +48,7 @@
6.36
6.37 # Checking to see if a valid neighborhood was given.
6.38 if not key in slug_dict:
6.39 - raise Http404
6.40 + raise Http404(slug_dict.keys())
6.41 else:
6.42 n = slug_dict[key]
6.43
6.44 @@ -34,4 +59,4 @@
6.45 'licenses' : License.objects.filter(location__point__intersects=n.mpoly).transform(900913, field_name='location__point')
6.46 }
6.47
6.48 - return render_to_response('openlayers_example.html', params)
6.49 + return render_to_response('tabc/city.html', params)
7.1 --- a/urls.py Tue Sep 09 22:38:09 2008 -0500
7.2 +++ b/urls.py Tue Sep 09 22:42:00 2008 -0500
7.3 @@ -9,5 +9,7 @@
7.4 # Example:
7.5 # (r'^where2/', include('where2.foo.urls')),
7.6 ('^admin/(.*)', admin.site.root),
7.7 + ('^$', 'tabc.views.home'),
7.8 + ('^(?P<city>[a-z\-]+)/$', 'tabc.views.city_index'),
7.9 ('^(?P<city>.+)/(?P<nbhood>.+)/$', 'tabc.views.city'),
7.10 )