]> gitweb.michael.orlitzky.com - dead/census-tools.git/blob - www/maps/maps/controllers/location.py
Added the "maps" Pylons project.
[dead/census-tools.git] / www / maps / maps / controllers / location.py
1 import csv
2 import json
3 import logging
4
5 from pylons import request, response, session, tmpl_context as c
6 from pylons.controllers.util import abort, redirect_to
7
8 from maps.lib.base import BaseController, render
9
10 log = logging.getLogger(__name__)
11
12 class LocationController(BaseController):
13
14 def index(self):
15 c.load_maps = False
16
17 if request.method == 'POST':
18 c.load_maps = True
19
20 # Get the contents of the uploaded files.
21 producers_data = request.POST['producers'].value.splitlines()
22 consumers_data = request.POST['consumers'].value.splitlines()
23
24 producers_csv = csv.DictReader(producers_data)
25 consumers_csv = csv.DictReader(consumers_data)
26
27 # Create a big json string to pass as a parameter to our
28 # javascript page.
29 json_objects = []
30
31 for row in producers_csv:
32 # Add the producers to the output, one at a time.
33 # But first, insert a 'type' field.
34 row['type'] = 'producer'
35 json_objects.append(row)
36
37 for row in consumers_csv:
38 # Do the same thing for the consumers.
39 row['type'] = 'consumer'
40 json_objects.append(row)
41
42 c.json = json.dumps(json_objects)
43
44 return render('/location/index.mako')
45