]> gitweb.michael.orlitzky.com - dead/census-tools.git/blobdiff - www/maps/maps/controllers/location.py
Added the "maps" Pylons project.
[dead/census-tools.git] / www / maps / maps / controllers / location.py
diff --git a/www/maps/maps/controllers/location.py b/www/maps/maps/controllers/location.py
new file mode 100644 (file)
index 0000000..c3e8298
--- /dev/null
@@ -0,0 +1,45 @@
+import csv
+import json
+import logging
+
+from pylons import request, response, session, tmpl_context as c
+from pylons.controllers.util import abort, redirect_to
+
+from maps.lib.base import BaseController, render
+
+log = logging.getLogger(__name__)
+
+class LocationController(BaseController):
+
+    def index(self):
+        c.load_maps = False
+
+        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)
+
+            # Create a big json string to pass as a parameter to our
+            # javascript page.
+            json_objects = []
+
+            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)
+        
+        return render('/location/index.mako')
+