+
+ def directions_result_to_csv(self, result):
+ rows = []
+
+ for trip in result['trips']:
+
+ for route in trip['routes']:
+ route_start = self.get_route_address(route, True)
+ route_end = self.get_route_address(route, False)
+ row = '"' + route_start + '"'
+ row += ', '
+ row += '"' + route_end + '"'
+ row += ', '
+ row += str(float(route['distance']['value']) / 1000)
+ rows.append(row)
+
+ return rows
+
+
+ def distances(self):
+ directions_array = json.loads(request.POST['data'])
+ csv_rows = []
+
+ for result in directions_array:
+ csv_rows += self.directions_result_to_csv(result)
+
+ response.content_type = 'text/csv'
+ response.headers['Content-disposition'] = 'attachment; filename=distances.csv'
+ return "\n".join(csv_rows)
+