diff --git a/photoapp/daemon.py b/photoapp/daemon.py index cda3458..6c7d98f 100644 --- a/photoapp/daemon.py +++ b/photoapp/daemon.py @@ -6,7 +6,7 @@ from photoapp.library import PhotoLibrary from photoapp.types import Photo, PhotoSet, Tag, TagItem, PhotoStatus from jinja2 import Environment, FileSystemLoader, select_autoescape from sqlalchemy import desc -from sqlalchemy import func, and_ +from sqlalchemy import func, and_, or_ import math from urllib.parse import urlparse @@ -342,22 +342,34 @@ class PhotoView(object): @cherrypy.expose def index(self, uuid): - uuid = uuid.split(".")[0] + # uuid = uuid.split(".")[0] s = self.master.session() - photo = photo_auth_filter(s.query(PhotoSet)).filter(PhotoSet.uuid == uuid).first() + photo = photo_auth_filter(s.query(PhotoSet)).filter(or_(PhotoSet.uuid == uuid, PhotoSet.slug == uuid)).first() yield self.master.render("photo.html", image=photo) @cherrypy.expose @require_auth - def op(self, uuid, op): + def op(self, uuid, op, title=None, description=None, offset=None): s = self.master.session() photo = s.query(PhotoSet).filter(PhotoSet.uuid == uuid).first() if op == "Make public": photo.status = PhotoStatus.public elif op == "Make private": photo.status = PhotoStatus.private + elif op == "Save": + photo.title = title + photo.description = description + photo.slug = slugify(title) or None + photo.date_offset = int(offset) if offset else 0 s.commit() - raise cherrypy.HTTPRedirect('/photo/{}'.format(photo.uuid), 302) + raise cherrypy.HTTPRedirect('/photo/{}'.format(photo.slug or photo.uuid), 302) + + @cherrypy.expose + @require_auth + def edit(self, uuid): + s = self.master.session() + photo = photo_auth_filter(s.query(PhotoSet)).filter(PhotoSet.uuid == uuid).first() + yield self.master.render("photo_edit.html", image=photo) @cherrypy.popargs('uuid') @@ -379,14 +391,18 @@ class TagView(object): numphotos = photo_auth_filter(s.query(func.count(PhotoSet.id))). \ filter(~PhotoSet.id.in_(s.query(TagItem.set_id))).scalar() photos = photo_auth_filter(s.query(PhotoSet)).filter(~PhotoSet.id.in_(s.query(TagItem.set_id))).\ - offset(page * pgsize).limit(pgsize).all() + offset(page * pgsize). \ + limit(pgsize).all() yield self.master.render("untagged.html", images=photos, total_items=numphotos, pgsize=pgsize, page=page) else: - tag = s.query(Tag).filter(Tag.uuid == uuid).first() + tag = s.query(Tag).filter(or_(Tag.uuid == uuid, Tag.slug == uuid)).first() numphotos = photo_auth_filter(s.query(func.count(Tag.id)).join(TagItem).join(PhotoSet)). \ - filter(Tag.uuid == uuid).scalar() - photos = photo_auth_filter(s.query(PhotoSet)).join(TagItem).join(Tag).filter(Tag.uuid == uuid). \ - order_by(PhotoSet.date.desc()).offset(page * pgsize).limit(pgsize).all() + filter(Tag.id == tag.id).scalar() + photos = photo_auth_filter(s.query(PhotoSet)).join(TagItem).join(Tag). \ + filter(Tag.id == tag.id). \ + order_by(PhotoSet.date.desc()). \ + offset(page * pgsize). \ + limit(pgsize).all() yield self.master.render("album.html", tag=tag, images=photos, total_items=numphotos, pgsize=pgsize, page=page) @@ -402,7 +418,7 @@ class TagView(object): - Make all private: mark all photos under this tag as private """ s = self.master.session() - tag = s.query(Tag).filter(Tag.uuid == uuid).first() + tag = s.query(Tag).filter(or_(Tag.uuid == uuid, Tag.slug == uuid)).first() if op == "Demote to tag": tag.is_album = 0 elif op == "Promote to album": @@ -414,11 +430,11 @@ class TagView(object): raise cherrypy.HTTPRedirect('/', 302) elif op == "Make all public": # TODO smarter query - for photo in s.query(PhotoSet).join(TagItem).join(Tag).filter(Tag.uuid == uuid).all(): + for photo in s.query(PhotoSet).join(TagItem).join(Tag).filter(Tag.id == tag.id).all(): photo.status = PhotoStatus.public elif op == "Make all private": # TODO smarter query - for photo in s.query(PhotoSet).join(TagItem).join(Tag).filter(Tag.uuid == uuid).all(): + for photo in s.query(PhotoSet).join(TagItem).join(Tag).filter(Tag.id == tag.id).all(): photo.status = PhotoStatus.private else: raise Exception("Invalid op: '{}'".format(op)) diff --git a/setup.py b/setup.py index af628f3..1707d71 100644 --- a/setup.py +++ b/setup.py @@ -25,5 +25,6 @@ setup(name='photoapp', }, include_package_data=True, package_data={'photoapp': ['../templates/*.html', + '../templates/fragments/*.html', '../styles/dist/*']}, zip_safe=False) diff --git a/styles/less/main.less b/styles/less/main.less index d856093..f3c21ce 100644 --- a/styles/less/main.less +++ b/styles/less/main.less @@ -124,9 +124,12 @@ a { .email-content-controls { margin-top: 2em; text-align: right; -} -.email-content-controls .secondary-button { - margin-bottom: 0.3em; + .secondary-button { + margin-bottom: 0.3em; + } + form { + display: inline-block; + } } .email-avatar { diff --git a/templates/album.html b/templates/album.html index e04a62b..d102ccf 100644 --- a/templates/album.html +++ b/templates/album.html @@ -1,6 +1,6 @@ {% extends "page.html" %} -{% set title = "Photos by date" %} -{% set subtitle = "By date, descending" %} +{% block title %}{{ tag.title or tag.name }}{% endblock %} +{% block subtitle %}{{ tag.description }}{% endblock %} {% block buttons %}
@@ -25,11 +25,7 @@ {% set locals.im_date = newdate %}

{{ locals.im_date }}

{% endif %} -
- - - -
+ {% include "fragments/feed-photo.html" %} {% endfor %}
diff --git a/templates/date.html b/templates/date.html index 74e372b..b9d977b 100644 --- a/templates/date.html +++ b/templates/date.html @@ -1,6 +1,6 @@ {% extends "page.html" %} -{% set title = "Photos on {}".format(date.strftime("%b %d, %Y")) %} -{% set subtitle = "By date, descending" %} +{% block title %}{{ "Photos on {}".format(date.strftime("%b %d, %Y")) }}{% endblock %} +{% block subtitle %}{% endblock %} {% block buttons %} @@ -25,11 +25,7 @@ {% set locals.im_date = newdate %}

{{ locals.im_date }}

{% endif %} -
- - - -
+ {% include "fragments/feed-photo.html" %} {% endfor %}
diff --git a/templates/dates.html b/templates/dates.html index 3ab0b6f..dcac9d5 100644 --- a/templates/dates.html +++ b/templates/dates.html @@ -1,6 +1,6 @@ {% extends "page.html" %} -{% set title = "All photos" %} -{% set subtitle = "By date, descending" %} +{% block title %}Photo Dates{% endblock %} +{% block subtitle %}Count per day{% endblock %} {% block buttons %} xxx diff --git a/templates/feed.html b/templates/feed.html index 12e5cf2..a5f1ced 100644 --- a/templates/feed.html +++ b/templates/feed.html @@ -1,10 +1,7 @@ {% extends "page.html" %} -{% set title = "Photos by date" %} -{% set subtitle = "By date, descending" %} - -{% block buttons %} - xxx -{% endblock %} +{% block title %}Photos by date{% endblock %} +{% block subtitle %}By date, descending{% endblock %} +{% block buttons %}{% endblock %} {% block body %} @@ -20,11 +17,7 @@ {% set locals.im_date = newdate %}

{{ locals.im_date }}

{% endif %} -
- - - -
+ {% include "fragments/feed-photo.html" %} {% endfor %}
{% include "pager.html" %} diff --git a/templates/fragments/feed-photo.html b/templates/fragments/feed-photo.html new file mode 100644 index 0000000..e93c9d9 --- /dev/null +++ b/templates/fragments/feed-photo.html @@ -0,0 +1,5 @@ + diff --git a/templates/map.html b/templates/map.html index 9714c9a..61f0e0d 100644 --- a/templates/map.html +++ b/templates/map.html @@ -1,10 +1,7 @@ {% extends "page.html" %} -{% set title = "Photo map" %} -{% set subtitle = "GPS data" %} - -{% block buttons %} - xxx -{% endblock %} +{% block title %}Photo map{% endblock %} +{% block subtitle %}GPS data{% endblock %} +{% block buttons %}{% endblock %} {% block body %} diff --git a/templates/monthly.html b/templates/monthly.html index f31af38..3813c2b 100644 --- a/templates/monthly.html +++ b/templates/monthly.html @@ -1,10 +1,7 @@ {% extends "page.html" %} -{% set title = "Server statistics" %} -{% set subtitle = "Placeholder" %} - -{% block buttons %} - xxx -{% endblock %} +{% block title %}Server statistics{% endblock %} +{% block subtitle %}{% endblock %} +{% block buttons %}{% endblock %} {% block body %} diff --git a/templates/page.html b/templates/page.html index b0c5164..10f37fa 100644 --- a/templates/page.html +++ b/templates/page.html @@ -22,11 +22,11 @@
  • Trash
  • Albums
  • {% for tag in all_albums %} -
  • {{ tag.title }}
  • +
  • {{ tag.name }}
  • {% endfor %}
  • Tags
  • {% for tag in all_tags %} -
  • {{ tag.title }}
  • +
  • {{ tag.name }}
  • {% endfor %}
    @@ -45,9 +45,9 @@