]> gitweb.michael.orlitzky.com - dead/census-tools.git/commitdiff
Made the routing Javascript render inline on a new view, location/route.
authorMichael Orlitzky <michael@orlitzky.com>
Fri, 19 Feb 2010 13:56:05 +0000 (08:56 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Fri, 19 Feb 2010 13:56:05 +0000 (08:56 -0500)
www/maps/maps/controllers/location.py
www/maps/maps/templates/base.mako
www/maps/maps/templates/location/index.mako

index c3e829858e5ea33699bd9c93b50d074c7a56a9f2..dc38833e56032a9f80abeecaea2a2cde0596ba3f 100644 (file)
@@ -11,35 +11,38 @@ log = logging.getLogger(__name__)
 
 class LocationController(BaseController):
 
-    def index(self):
-        c.load_maps = False
+    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.'
+            
+        # Get the contents of the uploaded files.
+        producers_data = request.POST['producers'].value.splitlines()
+        consumers_data = request.POST['consumers'].value.splitlines()
 
-            # Create a big json string to pass as a parameter to our
-            # javascript page.
-            json_objects = []
+        producers_csv = csv.DictReader(producers_data)
+        consumers_csv = csv.DictReader(consumers_data)
 
-            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)
+        # Create a big json string to pass as a parameter to our
+        # javascript page.
+        json_objects = []
 
-            for row in consumers_csv:
-                # Do the same thing for the consumers.
-                row['type'] = 'consumer'
-                json_objects.append(row)
+        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)
 
-            c.json = json.dumps(json_objects)
-        
-        return render('/location/index.mako')
+        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')
+        
index 0b1404577e173a6737ca369a49447db86a0f0109..6b0c649e2a061ede3419fac290bc6093d7ff6231 100644 (file)
 
       ${h.stylesheet_link('/stylesheets/reset.css')}
       ${h.stylesheet_link('/stylesheets/common.css')}
-      
-      % if c.load_maps:
-      <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
-      <script type="text/javascript"
-              src="/javascript/routing?json=${c.json}">
-      </script>
-      
-      % endif    
+
+      ${next.scripts()}
   </head>
   
   <body>
index 4f80d54a2f1738875cc1c2d8f0ac604cfc2eb7b3..c65e7e530bb3d6c7e5ec8e7ca0ecfb598d16b098 100644 (file)
@@ -1,8 +1,11 @@
 <%inherit file="/base.mako"/>\
 
+<%def name="scripts()">
+</%def>
+
 <h1>Generate KML Routes</h1>
 
-<form method="post" action="" enctype="multipart/form-data">
+<form method="post" action="location/route" enctype="multipart/form-data">
   <fieldset>
     <legend>Producer/Consumer Upload</legend>