diff --git a/photoapp/daemon.py b/photoapp/daemon.py index bf96fdd..58db3c6 100644 --- a/photoapp/daemon.py +++ b/photoapp/daemon.py @@ -1,18 +1,24 @@ import os import cherrypy import logging +from datetime import datetime, timedelta from photoapp.library import PhotoLibrary from photoapp.types import Photo, PhotoSet, Tag, TagItem from jinja2 import Environment, FileSystemLoader, select_autoescape from sqlalchemy import desc from sqlalchemy.exc import IntegrityError -from sqlalchemy import func +from sqlalchemy import func, and_ import math APPROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "../")) +def tplglobals(): + print("###", cherrypy.request.path_info) + return dict(path=cherrypy.request.path_info) + + class PhotosWeb(object): def __init__(self, library, template_dir): self.library = library @@ -24,6 +30,7 @@ class PhotosWeb(object): self.thumb = ThumbnailView(self) self.photo = PhotoView(self) self.download = DownloadView(self) + self.date = DateView(self) def render(self, template, **kwargs): return self.tpl.get_template(template).render(**kwargs, **self.get_default_vars()) @@ -45,7 +52,8 @@ class PhotosWeb(object): "image/gif": "gif", "application/octet-stream-xmp": "xmp", "image/x-canon-cr2": "cr2", - "video/mp4": "mp4"}[mime] + "video/mp4": "mp4", + "video/quicktime": "mov"}[mime] @cherrypy.expose def index(self): @@ -57,7 +65,7 @@ class PhotosWeb(object): page, pgsize = int(page), int(pgsize) total_sets = s.query(func.count(PhotoSet.id)).first()[0] images = s.query(PhotoSet).order_by(PhotoSet.date.desc()).offset(pgsize * page).limit(pgsize).all() - yield self.render("feed.html", images=[i for i in images], page=page, pgsize=int(pgsize), total_sets=total_sets) + yield self.render("feed.html", images=[i for i in images], page=page, pgsize=int(pgsize), total_sets=total_sets, **tplglobals()) @cherrypy.expose def monthly(self): @@ -78,6 +86,37 @@ class PhotosWeb(object): yield self.render("map.html", images=query.all(), zoom=int(zoom)) +@cherrypy.popargs('date') +class DateView(object): + def __init__(self, master): + self.master = master + + @cherrypy.expose + def index(self, date=None, page=0): + s = self.master.session() + if date: + page = int(page) + pgsize = 100 + dt = datetime.strptime(date, "%Y-%m-%d") + dt_end = dt + timedelta(days=1) + total_sets = s.query(func.count(PhotoSet.id)). \ + filter(and_(PhotoSet.date >= dt, PhotoSet.date < dt_end)).first()[0] + images = s.query(PhotoSet).filter(and_(PhotoSet.date >= dt, + PhotoSet.date < dt_end)).order_by(PhotoSet.date). \ + offset(page * pgsize).limit(pgsize).all() + yield self.master.render("feed.html", page=page, pgsize=pgsize, total_sets=total_sets, + images=[i for i in images], **tplglobals()) + return + images = s.query(PhotoSet, func.strftime('%Y-%m-%d', + PhotoSet.date).label('gdate'), + func.count('photos.id'), + func.strftime('%Y', PhotoSet.date).label('year'), + func.strftime('%m', PhotoSet.date).label('month'), + func.strftime('%d', PhotoSet.date).label('day')). \ + group_by('gdate').order_by(desc('year'), 'month', 'day').all() + yield self.master.render("dates.html", images=images) + + @cherrypy.popargs('item_type', 'thumb_size', 'uuid') class ThumbnailView(object): def __init__(self, master): diff --git a/styles/less/main.less b/styles/less/main.less index 84d864c..eeb125c 100644 --- a/styles/less/main.less +++ b/styles/less/main.less @@ -246,3 +246,12 @@ ul.pager { } } } + +.date-feed { + a { + padding-right: 15px; + } + .many { + font-weight: bold; + } +} diff --git a/templates/dates.html b/templates/dates.html new file mode 100644 index 0000000..97a4a81 --- /dev/null +++ b/templates/dates.html @@ -0,0 +1,24 @@ +{% set title = "All photos" %} +{% set subtitle = "By date, descending" %} + +{% include "page-top.html" %} + +{% set locals = namespace() %} + +
+ {% set locals.year = "" %} + {% set locals.month = "" %} + {% for item, date, count, _, _, _ in images %} + {% if item.date.year != locals.year %} + {% set locals.year = item.date.year %} +

{{ item.date.year }}

+ {% endif %} + {% if item.date.month != locals.month %} + {% set locals.month = item.date.month %} +

{{ item.date.strftime("%B") }}

+ {% endif %} + {{ date }} ({{ count }}) + {% endfor %} +
+ +{% include "page-bottom.html" %} diff --git a/templates/feed.html b/templates/feed.html index 695c604..d0e8c72 100644 --- a/templates/feed.html +++ b/templates/feed.html @@ -1,4 +1,4 @@ -{% set title = "All photos" %} +{% set title = "Photos by date" %} {% set subtitle = "By date, descending" %} {% include "page-top.html" %} @@ -17,7 +17,7 @@ {% endif %}
- +
{% endfor %} @@ -26,21 +26,21 @@
Page
{% if page > 0 %} {% endif %}
{% if page + 1 < total_pages %} {% endif %} diff --git a/templates/page-top.html b/templates/page-top.html index c513b63..db2af74 100644 --- a/templates/page-top.html +++ b/templates/page-top.html @@ -15,7 +15,8 @@