Mercurial > hg > GlobalNeighbors
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 22:e69cb496324e | 23:6891c5523b69 |
|---|---|
| 178 try: | 178 try: |
| 179 geoid = int(request.path.strip('/')) | 179 geoid = int(request.path.strip('/')) |
| 180 city = self.cities.get(geoid) | 180 city = self.cities.get(geoid) |
| 181 if not city: | 181 if not city: |
| 182 return | 182 return |
| 183 variables = dict(city=city) | 183 variables = dict(city=city, neighbors=None) |
| 184 if self.neighbors: | 184 if self.neighbors: |
| 185 import pdb; pdb.set_trace() | 185 n_neighbors = request.GET.get('neighbors', 10) |
| 186 try: | |
| 187 n_neighbors = int(n_neighbors) | |
| 188 except ValueError as e: | |
| 189 n_neighbors = 10 | |
| 190 neighbors = self.neighbors.get(geoid, [])[:n_neighbors] | |
| 191 neighbors = [{'name': self.cities[geoid]['name'], | |
| 192 'geoid': geoid, | |
| 193 'distance': distance} | |
| 194 for geoid, distance in neighbors] | |
| 195 variables['neighbors'] = neighbors | |
| 196 | |
| 186 return Response(content_type=self.content_type, | 197 return Response(content_type=self.content_type, |
| 187 body=self.citypage.render(variables)) | 198 body=self.citypage.render(variables)) |
| 188 except ValueError: | 199 except ValueError: |
| 189 pass | 200 pass |
| 190 | 201 |
