diff globalneighbors/web.py @ 23:6891c5523b69

load with neighbors :)
author Jeff Hammel <k0scist@gmail.com>
date Sun, 25 Jun 2017 18:13:43 -0700
parents e69cb496324e
children
line wrap: on
line diff
--- a/globalneighbors/web.py	Sun Jun 25 17:45:19 2017 -0700
+++ b/globalneighbors/web.py	Sun Jun 25 18:13:43 2017 -0700
@@ -180,9 +180,20 @@
                 city = self.cities.get(geoid)
                 if not city:
                     return
-                variables = dict(city=city)
+                variables = dict(city=city, neighbors=None)
                 if self.neighbors:
-                    import pdb; pdb.set_trace()
+                    n_neighbors = request.GET.get('neighbors', 10)
+                    try:
+                        n_neighbors = int(n_neighbors)
+                    except ValueError as e:
+                        n_neighbors = 10
+                    neighbors = self.neighbors.get(geoid, [])[:n_neighbors]
+                    neighbors = [{'name': self.cities[geoid]['name'],
+                                  'geoid': geoid,
+                                  'distance': distance}
+                                 for geoid, distance in neighbors]
+                    variables['neighbors'] = neighbors
+
                 return Response(content_type=self.content_type,
                                 body=self.citypage.render(variables))
             except ValueError: