Mercurial > hg > GlobalNeighbors
comparison globalneighbors/web.py @ 15:21095c9006e5
city page is now functional + linky
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 25 Jun 2017 14:55:53 -0700 |
parents | 27925261c137 |
children | 2fef925fbf37 |
comparison
equal
deleted
inserted
replaced
14:27925261c137 | 15:21095c9006e5 |
---|---|
56 if startswith: | 56 if startswith: |
57 retval = [] | 57 retval = [] |
58 for i in cities: | 58 for i in cities: |
59 if i[name].startswith(startswith): | 59 if i[name].startswith(startswith): |
60 retval.append({"name": i[name], | 60 retval.append({"name": i[name], |
61 "country code": i["country code"], | |
62 "population": i['population'], | |
61 "geonameid": i['geonameid']}) | 63 "geonameid": i['geonameid']}) |
62 else: | 64 else: |
63 retval = [{"name": i[name], | 65 retval = [{"name": i[name], |
64 "geonameid": i['geonameid']} | 66 "country code": i["country code"], |
67 "population": i['population'], | |
68 "geonameid": i['geonameid']} | |
65 for i in cities] | 69 for i in cities] |
66 return sorted(retval, key=lambda x: x['name'])[:limit] | 70 return sorted(retval, |
71 key=lambda x: (x['name'], | |
72 -x['population']) | |
73 )[:limit] | |
67 | 74 |
68 | 75 |
69 class Handler(object): | 76 class Handler(object): |
70 """base class for HTTP handler""" | 77 """base class for HTTP handler""" |
71 | 78 |
150 try: | 157 try: |
151 geoid = int(request.path.strip('/')) | 158 geoid = int(request.path.strip('/')) |
152 city = self.cities.get(geoid) | 159 city = self.cities.get(geoid) |
153 if not city: | 160 if not city: |
154 return | 161 return |
162 variables = dict(city=city) | |
155 return Response(content_type=self.content_type, | 163 return Response(content_type=self.content_type, |
156 body=self.citypage.render(**city)) | 164 body=self.citypage.render(variables)) |
157 except ValueError: | 165 except ValueError: |
158 pass | 166 pass |
159 | 167 |
160 | 168 |
161 | 169 |