X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=www%2Fmaps%2Fmaps%2Fcontrollers%2Flocation.py;h=5bf517c0810212bfa43eca59cebceef3eeead3fc;hb=a1ff47b818567962b111e77bdbf08b2966fb2691;hp=c3e829858e5ea33699bd9c93b50d074c7a56a9f2;hpb=5485afbd4da2182072ef9756c65137729bf1eee5;p=dead%2Fcensus-tools.git diff --git a/www/maps/maps/controllers/location.py b/www/maps/maps/controllers/location.py index c3e8298..5bf517c 100644 --- a/www/maps/maps/controllers/location.py +++ b/www/maps/maps/controllers/location.py @@ -11,35 +11,48 @@ log = logging.getLogger(__name__) class LocationController(BaseController): - def index(self): - c.load_maps = False + def __init__(self): + c.postback_url = None + + 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.' - # Create a big json string to pass as a parameter to our - # javascript page. - json_objects = [] + if (c.postback_url == None): + c.postback_url = '/directions/json_to_kml' + + # Get the contents of the uploaded files. + producers_data = request.POST['producers'].value.splitlines() + consumers_data = request.POST['consumers'].value.splitlines() - 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) + producers_csv = csv.DictReader(producers_data) + consumers_csv = csv.DictReader(consumers_data) - for row in consumers_csv: - # Do the same thing for the consumers. - row['type'] = 'consumer' - json_objects.append(row) + # Create a big json string to pass as a parameter to our + # javascript page. + json_objects = [] - c.json = json.dumps(json_objects) - - return render('/location/index.mako') + 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) + c.js = render('javascript/routing.mako') + + return render('location/route.mako') + + def distance(self): + c.postback_url = '/directions/distances' + return self.route() +