From 15719c20b5b76ab20aca5476880e8a64cfa6fcbd Mon Sep 17 00:00:00 2001 From: Gyrfalcon Date: Fri, 13 May 2016 18:21:00 -0500 Subject: [PATCH] gallery: Sort by screenshots modification time --- src/dcow/gallery.py | 6 ++++-- src/dcow/templates/gallery.html.j2 | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/dcow/gallery.py b/src/dcow/gallery.py index cc57ca5..bdce3df 100644 --- a/src/dcow/gallery.py +++ b/src/dcow/gallery.py @@ -33,7 +33,8 @@ def get_images(path, extensions=None): try: for f in os.listdir(path): if os.path.splitext(f)[1] in extensions: - yield f + st = os.stat(os.path.join(path, f)) + yield (st.st_mtime, f) except OSError: raise StopIteration @@ -42,7 +43,8 @@ class GalleryController(milla.controllers.HTTPVerbController): def GET(self, request): response = request.ResponseClass() + images = get_images(request.config['gallery.screenshot_dir']) response.text = render(request, 'gallery.html.j2', { - 'images': get_images(request.config['gallery.screenshot_dir']), + 'images': (i for m, i in sorted(images)), }) return response diff --git a/src/dcow/templates/gallery.html.j2 b/src/dcow/templates/gallery.html.j2 index eb4f78a..7530fce 100644 --- a/src/dcow/templates/gallery.html.j2 +++ b/src/dcow/templates/gallery.html.j2 @@ -15,7 +15,7 @@
-{% for image in images %} +{% for image in images|reverse %}