[Commits] python.it commit r248 - code/pythonisti/trunk/pythonisti/geo

commit a svn.python.it commit a svn.python.it
Sab 30 Dic 2006 22:48:56 CET


Author: manlio
Date: Sat Dec 30 22:48:55 2006
New Revision: 248

Modified:
   code/pythonisti/trunk/pythonisti/geo/google.py
   code/pythonisti/trunk/pythonisti/geo/models.py
Log:
Modificata funzione get_geo_location in modo che non restituisca una lista.
Definito modello per la gestione della geo locazione, con supporto all'interfaccia amministrativa di Django.


Modified: code/pythonisti/trunk/pythonisti/geo/google.py
==============================================================================
--- code/pythonisti/trunk/pythonisti/geo/google.py	(original)
+++ code/pythonisti/trunk/pythonisti/geo/google.py	Sat Dec 30 22:48:55 2006
@@ -62,4 +62,4 @@
     if status['code'] != 200:
         raise AddressNotFound()
 
-    return response['Placemark']
+    return response['Placemark'][0]

Modified: code/pythonisti/trunk/pythonisti/geo/models.py
==============================================================================
--- code/pythonisti/trunk/pythonisti/geo/models.py	(original)
+++ code/pythonisti/trunk/pythonisti/geo/models.py	Sat Dec 30 22:48:55 2006
@@ -1,3 +1,34 @@
+from simplejson import dumps
+
 from django.db import models
+from django.contrib.auth.models import User
+
+from pythonisti.geo import google
+
+
+class GeoLocation(models.Model):
+    username = models.OneToOneField(User)
+    # The address of the user
+    location = models.CharField(maxlength=50)
+    # The normalized address of the user
+    address = models.CharField(maxlength=50, editable=False)
+    # The geo location of the user, in the format '(lat, long')
+    geolocation = models.CharField(maxlength=50, editable=False)
+    # The geo location detail, in JSON format as returned by the
+    # Google Geocoder
+    geolocation_detail = models.CharField(maxlength=256, editable=False)
+ 
+
+    def save(self):
+        # Setup the computed fields
+        response = google.get_geo_location(self.location)
+        coordinates = response['Point']['coordinates'][:-1]
+
+        self.address = response['address']
+        self.geolocation = dumps(coordinates)
+        self.geolocation_detail = dumps(response)
+        
+        return super(GeoLocation, self).save()
 
-# Create your models here.
+    class Admin:
+        list_display = ('address', 'geolocation')


Maggiori informazioni sulla lista Commits