]> gitweb.michael.orlitzky.com - dead/census-tools.git/blobdiff - www/maps/maps/controllers/location.py
Added the postback_url parameter to the LocationController.
[dead/census-tools.git] / www / maps / maps / controllers / location.py
index c3e829858e5ea33699bd9c93b50d074c7a56a9f2..5bf517c0810212bfa43eca59cebceef3eeead3fc 100644 (file)
@@ -11,35 +11,48 @@ log = logging.getLogger(__name__)
 
 class LocationController(BaseController):
 
-    def index(self):
-        c.load_maps = False
+    def __init__(self):
+        c.postback_url = None
+        
+    def index(self):      
+        return render('/location/index.mako')
 
-        if request.method == 'POST':
-            c.load_maps = True
 
-            # Get the contents of the uploaded files.
-            producers_data = request.POST['producers'].value.splitlines()
-            consumers_data = request.POST['consumers'].value.splitlines()
-        
-            producers_csv = csv.DictReader(producers_data)
-            consumers_csv = csv.DictReader(consumers_data)
+    def route(self):
+        if request.method != 'POST':
+            return 'You should have posted some data.'
 
-            # Create a big json string to pass as a parameter to our
-            # javascript page.
-            json_objects = []
+        if (c.postback_url == None):
+            c.postback_url = '/directions/json_to_kml'
+            
+        # Get the contents of the uploaded files.
+        producers_data = request.POST['producers'].value.splitlines()
+        consumers_data = request.POST['consumers'].value.splitlines()
 
-            for row in producers_csv:
-                # Add the producers to the output, one at a time.
-                # But first, insert a 'type' field.
-                row['type'] = 'producer'
-                json_objects.append(row)
+        producers_csv = csv.DictReader(producers_data)
+        consumers_csv = csv.DictReader(consumers_data)
 
-            for row in consumers_csv:
-                # Do the same thing for the consumers.
-                row['type'] = 'consumer'
-                json_objects.append(row)
+        # Create a big json string to pass as a parameter to our
+        # javascript page.
+        json_objects = []
 
-            c.json = json.dumps(json_objects)
-        
-        return render('/location/index.mako')
+        for row in producers_csv:
+            # Add the producers to the output, one at a time.
+            # But first, insert a 'type' field.
+            row['type'] = 'producer'
+            json_objects.append(row)
 
+        for row in consumers_csv:
+            # Do the same thing for the consumers.
+            row['type'] = 'consumer'
+            json_objects.append(row)
+
+        c.json = json.dumps(json_objects)
+        c.js = render('javascript/routing.mako')
+        
+        return render('location/route.mako')
+        
+    def distance(self):
+        c.postback_url = '/directions/distances'
+        return self.route()
+