pngtile.store: change list() to yield name, type tuples rather than appending / to dirs
authorTero Marttila <terom@qmsk.net>
Sat, 04 Oct 2014 15:13:56 +0300
changeset 176 ad32cf3a25fa
parent 175 16ab69a5569a
child 177 b2768f3982f3
pngtile.store: change list() to yield name, type tuples rather than appending / to dirs
pngtile/image.py
pngtile/store.py
--- a/pngtile/image.py	Sat Oct 04 03:28:57 2014 +0300
+++ b/pngtile/image.py	Sat Oct 04 15:13:56 2014 +0300
@@ -76,6 +76,13 @@
 
                 yield html.li(html.a(href=href(*path), *[part]))
 
+    def render_dir_item (self, name, type):
+        if type:
+            return html.a(href=name, *[name])
+        else:
+            dir = name + '/'
+            return html.a(href=dir, *[dir])
+
     def render_dir (self, request, name, items):
         """
             request:    werkzeug.Request
@@ -97,10 +104,11 @@
                         html.ol(class_='breadcrumb', *self.render_dir_breadcrumb(name)),
                     ]),
                     html.div(class_='list', *[
-                        html.ul(class_='list-group', *[html.li(class_='list-group-item', *[
-                                html.a(href=item, *[item])
-                            ]) for item in items]
-                        ),
+                        html.ul(class_='list-group', *[
+                            html.li(class_='list-group-item', *[
+                                self.render_dir_item(name, type) for name, type in items
+                            ]) for name, type in items
+                        ]),
                     ]),
                 ]),
             ),
--- a/pngtile/store.py	Sat Oct 04 03:28:57 2014 +0300
+++ b/pngtile/store.py	Sat Oct 04 15:13:56 2014 +0300
@@ -102,7 +102,7 @@
                     # skip inaccessible dirs
                     continue
 
-                yield name + '/'
+                yield name, None
 
             # examine ext
             if '.' in name:
@@ -113,7 +113,7 @@
 
             # show .png files with a .cache file
             if name_type in self.IMAGE_TYPES and os.path.exists(os.path.join(root, name_base + '.cache')):
-                yield name
+                yield name, name_type
 
     def open (self, url):
         """