This commit is contained in:
dave 2018-09-13 22:59:37 -07:00
parent 063f30ef0b
commit 0789de35ff
5 changed files with 82 additions and 8 deletions

View File

@ -26,6 +26,8 @@ class PhotosWeb(object):
self.photo = PhotoView(self)
self.download = DownloadView(self)
self.date = DateView(self)
self.tag = TagView(self)
self.album = self.tag
def render(self, template, **kwargs):
return self.tpl.get_template(template).render(**kwargs, **self.get_default_vars())
@ -33,7 +35,9 @@ class PhotosWeb(object):
def get_default_vars(self):
s = self.session()
ret = {
"all_tags": s.query(Tag).order_by(Tag.title).all()
"all_tags": s.query(Tag).order_by(Tag.title).all(),
"all_albums": s.query(Tag).filter(Tag.is_album == True).order_by(Tag.title).all(),
"path": cherrypy.request.path_info
}
return ret
@ -60,7 +64,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, **tplglobals())
yield self.render("feed.html", images=[i for i in images], page=page, pgsize=int(pgsize), total_sets=total_sets)
@cherrypy.expose
def monthly(self):
@ -137,8 +141,8 @@ class DateView(object):
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())
yield self.master.render("date.html", page=page, pgsize=pgsize, total_sets=total_sets,
images=[i for i in images], date=dt)
return
images = s.query(PhotoSet, func.strftime('%Y-%m-%d',
PhotoSet.date).label('gdate'),
@ -149,6 +153,17 @@ class DateView(object):
group_by('gdate').order_by(desc('year'), 'month', 'day').all()
yield self.master.render("dates.html", images=images)
@cherrypy.expose
def tag(self, date):
raise Exception("Who am i")
s = self.master.session()
dt = datetime.strptime(date, "%Y-%m-%d")
dt_end = dt + timedelta(days=1)
photos = s.query(PhotoSet).filter(and_(PhotoSet.date >= dt,
PhotoSet.date < dt_end)).order_by(PhotoSet.date).all()
alltags = s.query(Tag).order_by(Tag.title).all()
yield self.master.render("create_tags.html", images=photos, alltags=alltags)
@cherrypy.popargs('item_type', 'thumb_size', 'uuid')
class ThumbnailView(object):

View File

@ -17,7 +17,7 @@ class PhotoLibrary(object):
self.path = lib_path
self.cache_path = cache_path
self.engine = create_engine('sqlite:///{}'.format(db_path),
connect_args={'check_same_thread': False}, poolclass=StaticPool, echo=False)
connect_args={'check_same_thread': False}, poolclass=StaticPool)
Base.metadata.create_all(self.engine)
self.session = sessionmaker()
self.session.configure(bind=self.engine)

View File

@ -55,4 +55,3 @@
</div>
{% endblock %}

59
templates/date.html Normal file
View File

@ -0,0 +1,59 @@
{% extends "page.html" %}
{% set title = "Photos on {}".format(date.strftime("%b %d, %Y")) %}
{% set subtitle = "By date, descending" %}
{% block buttons %}
<form action="/create_tags" method="post">
<input type="hidden" name="fromdate" value="{{ date.strftime("%Y-%m-%d") }}">
<input type="submit" class="secondary-button pure-button" value="Tag all" />
</form>
{% endblock %}
{% block body %}
{% set locals = namespace() %}
{% set total_pages = (total_sets/pgsize)|ceil %}
<div class="photo-feed">
{% set locals.im_date = "" %}
{% for item in images %}
{% set newdate = item.date.strftime("%b %d, %Y") %}
{% if newdate != locals.im_date %}
{% set locals.im_date = newdate %}
<div class="feed-divider year"><h4>{{ locals.im_date }}</h4></div>
{% endif %}
<div class="photo">
<a href="/photo/{{ item.uuid }}">
<img src="/thumb/set/feed/{{ item.uuid }}.jpg" />
</a>
</div>
{% endfor %}
<br style="clear:both" />
<div class="pager">
<h6>Page</h6>
{% if page > 0 %}
<div class="nav-prev">
<a href="{{path}}?page={{ page - 1 }}">Previous</a>
</div>
{% endif %}
<div class="pages">
<ul class="pager">
{% for pgnum in range(0, total_pages) %}
<li{% if pgnum == page %} class="current"{% endif %}>
<a href="{{path}}?page={{ pgnum }}">{{ pgnum }}</a>
</li>
{% endfor %}
</ul>
</div>
{% if page + 1 < total_pages %}
<div class="nav-next">
<a href="{{path}}?page={{ page + 1 }}">Next</a>
</div>
{% endif %}
</div>
</div>
{% endblock %}

View File

@ -20,8 +20,9 @@
<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-heading">Albums</li>
<li class="pure-menu-item"><a href="/albums" class="pure-menu-link">Foo</a></li>
<li class="pure-menu-item"><a href="/albums" class="pure-menu-link">Bar</a></li>
{% for tag in all_albums %}
<li class="pure-menu-item"><a href="/album/{{ tag.uuid }}" class="pure-menu-link"><span class="tag-icon tag-icon-mod-6-{{ tag.id % 6 }}"></span>{{ tag.title }}</a></li>
{% endfor %}
<li class="pure-menu-heading">Tags</li>
{% for tag in all_tags %}
<li class="pure-menu-item"><a href="/tag/{{ tag.uuid }}" class="pure-menu-link"><span class="tag-icon tag-icon-mod-6-{{ tag.id % 6 }}"></span>{{ tag.title }}</a></li>