add dates view
This commit is contained in:
parent
c952471b33
commit
69902d942d
|
@ -1,18 +1,24 @@
|
||||||
import os
|
import os
|
||||||
import cherrypy
|
import cherrypy
|
||||||
import logging
|
import logging
|
||||||
|
from datetime import datetime, timedelta
|
||||||
from photoapp.library import PhotoLibrary
|
from photoapp.library import PhotoLibrary
|
||||||
from photoapp.types import Photo, PhotoSet, Tag, TagItem
|
from photoapp.types import Photo, PhotoSet, Tag, TagItem
|
||||||
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
||||||
from sqlalchemy import desc
|
from sqlalchemy import desc
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
from sqlalchemy import func
|
from sqlalchemy import func, and_
|
||||||
import math
|
import math
|
||||||
|
|
||||||
|
|
||||||
APPROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "../"))
|
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):
|
class PhotosWeb(object):
|
||||||
def __init__(self, library, template_dir):
|
def __init__(self, library, template_dir):
|
||||||
self.library = library
|
self.library = library
|
||||||
|
@ -24,6 +30,7 @@ class PhotosWeb(object):
|
||||||
self.thumb = ThumbnailView(self)
|
self.thumb = ThumbnailView(self)
|
||||||
self.photo = PhotoView(self)
|
self.photo = PhotoView(self)
|
||||||
self.download = DownloadView(self)
|
self.download = DownloadView(self)
|
||||||
|
self.date = DateView(self)
|
||||||
|
|
||||||
def render(self, template, **kwargs):
|
def render(self, template, **kwargs):
|
||||||
return self.tpl.get_template(template).render(**kwargs, **self.get_default_vars())
|
return self.tpl.get_template(template).render(**kwargs, **self.get_default_vars())
|
||||||
|
@ -45,7 +52,8 @@ class PhotosWeb(object):
|
||||||
"image/gif": "gif",
|
"image/gif": "gif",
|
||||||
"application/octet-stream-xmp": "xmp",
|
"application/octet-stream-xmp": "xmp",
|
||||||
"image/x-canon-cr2": "cr2",
|
"image/x-canon-cr2": "cr2",
|
||||||
"video/mp4": "mp4"}[mime]
|
"video/mp4": "mp4",
|
||||||
|
"video/quicktime": "mov"}[mime]
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def index(self):
|
def index(self):
|
||||||
|
@ -57,7 +65,7 @@ class PhotosWeb(object):
|
||||||
page, pgsize = int(page), int(pgsize)
|
page, pgsize = int(page), int(pgsize)
|
||||||
total_sets = s.query(func.count(PhotoSet.id)).first()[0]
|
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()
|
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
|
@cherrypy.expose
|
||||||
def monthly(self):
|
def monthly(self):
|
||||||
|
@ -78,6 +86,37 @@ class PhotosWeb(object):
|
||||||
yield self.render("map.html", images=query.all(), zoom=int(zoom))
|
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')
|
@cherrypy.popargs('item_type', 'thumb_size', 'uuid')
|
||||||
class ThumbnailView(object):
|
class ThumbnailView(object):
|
||||||
def __init__(self, master):
|
def __init__(self, master):
|
||||||
|
|
|
@ -246,3 +246,12 @@ ul.pager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.date-feed {
|
||||||
|
a {
|
||||||
|
padding-right: 15px;
|
||||||
|
}
|
||||||
|
.many {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
{% set title = "All photos" %}
|
||||||
|
{% set subtitle = "By date, descending" %}
|
||||||
|
|
||||||
|
{% include "page-top.html" %}
|
||||||
|
|
||||||
|
{% set locals = namespace() %}
|
||||||
|
|
||||||
|
<div class="date-feed">
|
||||||
|
{% set locals.year = "" %}
|
||||||
|
{% set locals.month = "" %}
|
||||||
|
{% for item, date, count, _, _, _ in images %}
|
||||||
|
{% if item.date.year != locals.year %}
|
||||||
|
{% set locals.year = item.date.year %}
|
||||||
|
<div class="feed-divider year"><h4>{{ item.date.year }}</h4></div>
|
||||||
|
{% endif %}
|
||||||
|
{% if item.date.month != locals.month %}
|
||||||
|
{% set locals.month = item.date.month %}
|
||||||
|
<div class="feed-divider month"><h4>{{ item.date.strftime("%B") }}</h4></div>
|
||||||
|
{% endif %}
|
||||||
|
<a class="date-item{% if count > 50 %} many{% endif %}" href="/date/{{ date }}">{{ date }} ({{ count }})</a>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% include "page-bottom.html" %}
|
|
@ -1,4 +1,4 @@
|
||||||
{% set title = "All photos" %}
|
{% set title = "Photos by date" %}
|
||||||
{% set subtitle = "By date, descending" %}
|
{% set subtitle = "By date, descending" %}
|
||||||
|
|
||||||
{% include "page-top.html" %}
|
{% include "page-top.html" %}
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="photo">
|
<div class="photo">
|
||||||
<a href="/photo/{{ item.uuid }}">
|
<a href="/photo/{{ item.uuid }}">
|
||||||
<img src="thumb/set/feed/{{ item.uuid }}.jpg" />
|
<img src="/thumb/set/feed/{{ item.uuid }}.jpg" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -26,21 +26,21 @@
|
||||||
<h6>Page</h6>
|
<h6>Page</h6>
|
||||||
{% if page > 0 %}
|
{% if page > 0 %}
|
||||||
<div class="nav-prev">
|
<div class="nav-prev">
|
||||||
<a href="feed?page={{ page - 1 }}">Previous</a>
|
<a href="{{path}}?page={{ page - 1 }}">Previous</a>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="pages">
|
<div class="pages">
|
||||||
<ul class="pager">
|
<ul class="pager">
|
||||||
{% for pgnum in range(0, total_pages) %}
|
{% for pgnum in range(0, total_pages) %}
|
||||||
<li{% if pgnum == page %} class="current"{% endif %}>
|
<li{% if pgnum == page %} class="current"{% endif %}>
|
||||||
<a href="/feed?page={{ pgnum }}">{{ pgnum }}</a>
|
<a href="{{path}}?page={{ pgnum }}">{{ pgnum }}</a>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
{% if page + 1 < total_pages %}
|
{% if page + 1 < total_pages %}
|
||||||
<div class="nav-next">
|
<div class="nav-next">
|
||||||
<a href="feed?page={{ page + 1 }}">Next</a>
|
<a href="{{path}}?page={{ page + 1 }}">Next</a>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -15,7 +15,8 @@
|
||||||
<ul class="pure-menu-list">
|
<ul class="pure-menu-list">
|
||||||
<li class="pure-menu-item"><a href="/" class="pure-menu-link">All photos</a></li>
|
<li class="pure-menu-item"><a href="/" class="pure-menu-link">All photos</a></li>
|
||||||
<li class="pure-menu-item"><a href="/albums" class="pure-menu-link">Albums</a></li>
|
<li class="pure-menu-item"><a href="/albums" class="pure-menu-link">Albums</a></li>
|
||||||
<li class="pure-menu-item"><a href="/monthly" class="pure-menu-link">By month</a></li>
|
<li class="pure-menu-item"><a href="/date" class="pure-menu-link">Dates</a></li>
|
||||||
|
<li class="pure-menu-item"><a href="/monthly" class="pure-menu-link">Stats</a></li>
|
||||||
<li class="pure-menu-item"><a href="/map" class="pure-menu-link">Map</a></li>
|
<li class="pure-menu-item"><a href="/map" class="pure-menu-link">Map</a></li>
|
||||||
<li class="pure-menu-item"><a href="/admin/trash" class="pure-menu-link">Trash</a></li>
|
<li class="pure-menu-item"><a href="/admin/trash" class="pure-menu-link">Trash</a></li>
|
||||||
<li class="pure-menu-heading">Albums</li>
|
<li class="pure-menu-heading">Albums</li>
|
||||||
|
|
Loading…
Reference in New Issue