[Commits] python.it commit r256 - in
code/pythonisti/trunk/pythonisti: geo template/geo
commit a svn.python.it
commit a svn.python.it
Mer 10 Gen 2007 16:29:09 CET
Author: rhymes
Date: Wed Jan 10 16:29:05 2007
New Revision: 256
Removed:
code/pythonisti/trunk/pythonisti/template/geo/db.js
Modified:
code/pythonisti/trunk/pythonisti/geo/urls.py
code/pythonisti/trunk/pythonisti/geo/views.py
code/pythonisti/trunk/pythonisti/template/geo/map.xhtml
Log:
refactored urls and switched to Ajax to retrieve the JSON of the data for gmaps
Modified: code/pythonisti/trunk/pythonisti/geo/urls.py
==============================================================================
--- code/pythonisti/trunk/pythonisti/geo/urls.py (original)
+++ code/pythonisti/trunk/pythonisti/geo/urls.py Wed Jan 10 16:29:05 2007
@@ -4,6 +4,6 @@
urlpatterns = patterns('',
- (r'^db/', views.db_view),
- (r'^map/', views.map_view)
+ (r'^json/', views.json),
+ (r'^map/', views.gmap)
)
Modified: code/pythonisti/trunk/pythonisti/geo/views.py
==============================================================================
--- code/pythonisti/trunk/pythonisti/geo/views.py (original)
+++ code/pythonisti/trunk/pythonisti/geo/views.py Wed Jan 10 16:29:05 2007
@@ -1,37 +1,30 @@
-# 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.utils import simplejson
from django.conf import settings
from pythonisti.geo import models
-
-
-def db_view(request):
+def json(request):
locations = models.GeoLocation.objects.all()
- content = []
+ 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)
+ 'location': simplejson.loads(item.geolocation)
})
- return HttpResponse(t.render(c), mimetype='text/javascript')
+ json_locations = simplejson.dumps(content)
+ return HttpResponse(json_locations, mimetype='application/json')
-def map_view(request):
+def gmap(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/template/geo/map.xhtml
==============================================================================
--- code/pythonisti/trunk/pythonisti/template/geo/map.xhtml (original)
+++ code/pythonisti/trunk/pythonisti/template/geo/map.xhtml Wed Jan 10 16:29:05 2007
@@ -8,15 +8,20 @@
<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 src="/media/j/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
var center = {{ center }};
var zoom = {{ zoom }};
-
+
function load() {
+ $.getJSON("/geo/json", fillMap);
+ }
+
+ function fillMap(locations) {
if (GBrowserIsCompatible()) {
+
var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
Maggiori informazioni sulla lista
Commits