changeset 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 4583d0d9331a
files globalneighbors/grid.py globalneighbors/templates/city.html globalneighbors/web.py
diffstat 3 files changed, 26 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/globalneighbors/grid.py	Sun Jun 25 14:29:18 2017 -0700
+++ b/globalneighbors/grid.py	Sun Jun 25 14:55:53 2017 -0700
@@ -70,3 +70,5 @@
 
     def __init__(self, locations):
         raise NotImplementedError('TODO')
+
+def main(
--- a/globalneighbors/templates/city.html	Sun Jun 25 14:29:18 2017 -0700
+++ b/globalneighbors/templates/city.html	Sun Jun 25 14:55:53 2017 -0700
@@ -1,19 +1,28 @@
 <!DOCTYPE html>
 <html>
   <head>
-    <title>{{ name }}</title>
+    <title>{{ city.name }}</title>
   </head>
   <body>
     <a href="/"
        title="back to Global Niehgbors">Home</a>
 
-    <h1>{{ name }}</h1>
+    <h1>{{ city.name }}</h1>
 
-    <h2 title="location">{{latitude}},{{longitude}}</h2>
+    <!-- give a link to Google maps, for fun -->
+    <h2>
+      <a href="https://www.google.com/maps/?ll={{city.latitude}},{{city.longitude}}"
+         target="_blank"
+         title="location">{{city.latitude}},{{city.longitude}}
+      </a>
+    </h2>
 
     <dl>
       <dt>Population:</dt>
-      <dd>{{ population }}</dd>
+      <dd>{{ city.population }}</dd>
+
+      <dt>Country:</dt>
+      <dd>{{ city['country code'] }}
     </dl>
   </body>
 </html>
--- a/globalneighbors/web.py	Sun Jun 25 14:29:18 2017 -0700
+++ b/globalneighbors/web.py	Sun Jun 25 14:55:53 2017 -0700
@@ -58,12 +58,19 @@
         for i in cities:
             if i[name].startswith(startswith):
                 retval.append({"name": i[name],
+                               "country code": i["country code"],
+                               "population": i['population'],
                                "geonameid": i['geonameid']})
     else:
         retval = [{"name": i[name],
-                  "geonameid": i['geonameid']}
+                   "country code": i["country code"],
+                   "population": i['population'],
+                   "geonameid": i['geonameid']}
                    for i in cities]
-    return sorted(retval, key=lambda x: x['name'])[:limit]
+    return sorted(retval,
+                  key=lambda x: (x['name'],
+                                 -x['population'])
+                  )[:limit]
 
 
 class Handler(object):
@@ -152,8 +159,9 @@
                 city = self.cities.get(geoid)
                 if not city:
                     return
+                variables = dict(city=city)
                 return Response(content_type=self.content_type,
-                                body=self.citypage.render(**city))
+                                body=self.citypage.render(variables))
             except ValueError:
                 pass