]> gitweb.michael.orlitzky.com - dead/census-tools.git/blob - maps/maps/controllers/location.py
Added the linear program solving the midatlantic region.
[dead/census-tools.git] / 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 return render('/location/index.mako')
16
17
18 def route(self):
19 if request.method != 'POST':
20 return 'You should have posted some data.'
21
22 # Get the contents of the uploaded files.
23 producers_data = request.POST['producers'].value.splitlines()
24 consumers_data = request.POST['consumers'].value.splitlines()
25
26 producers_csv = csv.DictReader(producers_data)
27 consumers_csv = csv.DictReader(consumers_data)
28
29 # Create a big json string to pass as a parameter to our
30 # javascript page.
31 json_objects = []
32
33 for row in producers_csv:
34 # Add the producers to the output, one at a time.
35 # But first, insert a 'type' field.
36 row['type'] = 'producer'
37 json_objects.append(row)
38
39 for row in consumers_csv:
40 # Do the same thing for the consumers.
41 row['type'] = 'consumer'
42 json_objects.append(row)
43
44 c.json = json.dumps(json_objects)
45 c.js = render('javascript/routing.mako')
46
47 return render('location/route.mako')
48