[Commits] python.it commit r252 - in
code/pythonisti/trunk/pythonisti: . geo template template/geo
commit a svn.python.it
commit a svn.python.it
Ven 5 Gen 2007 12:13:19 CET
Author: manlio
Date: Fri Jan 5 12:13:18 2007
New Revision: 252
Added:
code/pythonisti/trunk/pythonisti/template/
code/pythonisti/trunk/pythonisti/template/geo/
code/pythonisti/trunk/pythonisti/template/geo/db.js (contents, props changed)
code/pythonisti/trunk/pythonisti/template/geo/map.xhtml (contents, props changed)
Modified:
code/pythonisti/trunk/pythonisti/geo/urls.py
code/pythonisti/trunk/pythonisti/geo/views.py
code/pythonisti/trunk/pythonisti/settings.py
Log:
Completato sviluppo applicazione geo.
Modified: code/pythonisti/trunk/pythonisti/geo/urls.py
==============================================================================
--- code/pythonisti/trunk/pythonisti/geo/urls.py (original)
+++ code/pythonisti/trunk/pythonisti/geo/urls.py Fri Jan 5 12:13:18 2007
@@ -1,4 +1,9 @@
from django.conf.urls.defaults import *
+from pythonisti.geo import views
+
+
urlpatterns = patterns('',
+ (r'^db/', views.db_view),
+ (r'^map/', views.map_view)
)
Modified: code/pythonisti/trunk/pythonisti/geo/views.py
==============================================================================
--- code/pythonisti/trunk/pythonisti/geo/views.py (original)
+++ code/pythonisti/trunk/pythonisti/geo/views.py Fri Jan 5 12:13:18 2007
@@ -1 +1,37 @@
# Create your views here.
+from django.template import Context, loader
+from django.http import HttpResponse
+from django.shortcuts import render_to_response
+from django.utils.simplejson import dumps, loads
+from django.conf import settings
+
+from pythonisti.geo import models
+
+
+
+def db_view(request):
+ locations = models.GeoLocation.objects.all()
+ content = []
+
+ for item in locations:
+ content.append({
+ 'info': item.username.username,
+ 'location': loads(item.geolocation)
+ })
+
+ t = loader.get_template('geo/db.js')
+ c = Context({
+ 'locations': dumps(content)
+ })
+
+ return HttpResponse(t.render(c), mimetype='text/javascript')
+
+
+def map_view(request):
+ context = {
+ 'key': settings.GOOGLE_API_KEY,
+ 'center': settings.MAP_CENTER,
+ 'zoom': settings.MAP_ZOOM
+ }
+
+ return render_to_response('geo/map.xhtml', context)
Modified: code/pythonisti/trunk/pythonisti/settings.py
==============================================================================
--- code/pythonisti/trunk/pythonisti/settings.py (original)
+++ code/pythonisti/trunk/pythonisti/settings.py Fri Jan 5 12:13:18 2007
@@ -62,6 +62,7 @@
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates".
# Always use forward slashes, even on Windows.
+ 'template'
)
INSTALLED_APPS = (
@@ -78,3 +79,7 @@
# pythonisti specific configuration
#
GOOGLE_API_KEY = file('gmaps.key').read()
+
+# Where to center the map and the zoom
+MAP_CENTER = [12.482323, 41.895466] # Rome
+MAP_ZOOM = 6
Added: code/pythonisti/trunk/pythonisti/template/geo/db.js
==============================================================================
--- (empty file)
+++ code/pythonisti/trunk/pythonisti/template/geo/db.js Fri Jan 5 12:13:18 2007
@@ -0,0 +1 @@
+var locations = {{ locations }};
Added: code/pythonisti/trunk/pythonisti/template/geo/map.xhtml
==============================================================================
--- (empty file)
+++ code/pythonisti/trunk/pythonisti/template/geo/map.xhtml Fri Jan 5 12:13:18 2007
@@ -0,0 +1,50 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:v="urn:schemas-microsoft-com:vml"
+ lang="it" xml:lang="it">
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <title>pythonisti</title>
+ <script src="http://maps.google.com/maps?file=api&v=2&key={{key}}"
+ type="text/javascript"></script>
+ <script src="../db" type="text/javascript"></script>
+ <script type="text/javascript">
+ //<![CDATA[
+
+ var center = {{ center }};
+ var zoom = {{ zoom }};
+
+ function load() {
+ if (GBrowserIsCompatible()) {
+ var map = new GMap2(document.getElementById("map"));
+ map.addControl(new GSmallMapControl());
+ map.addControl(new GMapTypeControl());
+ map.setCenter(new GLatLng(center[1], center[0]), zoom);
+
+ /* Define a custom marker function, that adds an info window
+ about the pythonista */
+ function createMarker(point, i) {
+ var marker = new GMarker(point);
+ GEvent.addListener(marker, "click", function() {
+ info = locations[i]["info"]
+ marker.openInfoWindowHtml("<strong>" + info + "</strong>");
+ });
+ return marker;
+ }
+
+ // Add the pythonisti markers
+ for (var i = 0, n = locations.length; i < n; i++) {
+ var location = locations[i]["location"];
+ var point = new GLatLng(location[1], location[0]);
+ map.addOverlay(createMarker(point, i));
+ }
+ }
+ }
+ //]]>
+ </script>
+ </head>
+ <body onload="load()" onunload="GUnload()">
+ <div id="map" style="width: 800px; height: 600px" />
+ </body>
+</html>
Maggiori informazioni sulla lista
Commits