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