diff --git a/.gitignore b/.gitignore index a235ff1..b011a47 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +__pycache__ build/ cache/ dist/ diff --git a/photoapp/daemon.py b/photoapp/daemon.py index 6c7d98f..2234cd9 100644 --- a/photoapp/daemon.py +++ b/photoapp/daemon.py @@ -193,7 +193,7 @@ class PhotosWeb(object): s.commit() if newtag: - s.add(Tag(title=newtag, description=newtag.capitalize(), slug=slugify(newtag))) + s.add(Tag(title=newtag.capitalize(), name=newtag, slug=slugify(newtag))) s.commit() photos, num_photos = get_photos() @@ -230,6 +230,10 @@ class PhotosWeb(object): else urlparse(cherrypy.request.headers["Referer"]).path raise cherrypy.HTTPRedirect(dest, 302) + @cherrypy.expose + def error(self, status, message, traceback, version): + yield self.render("error.html", status=status, message=message, traceback=traceback) + @cherrypy.popargs('date') class DateView(object): @@ -345,11 +349,20 @@ class PhotoView(object): # uuid = uuid.split(".")[0] s = self.master.session() photo = photo_auth_filter(s.query(PhotoSet)).filter(or_(PhotoSet.uuid == uuid, PhotoSet.slug == uuid)).first() + if not photo: + raise cherrypy.HTTPError(404) yield self.master.render("photo.html", image=photo) @cherrypy.expose @require_auth def op(self, uuid, op, title=None, description=None, offset=None): + """ + Modify a photo + :param op: operation to perform: + * "Make public": + * "Make private": + * "Save": update the photo's title, description, and date_offset fields + """ s = self.master.session() photo = s.query(PhotoSet).filter(PhotoSet.uuid == uuid).first() if op == "Make public": @@ -464,7 +477,8 @@ def main(): tpl_dir = os.path.join(APPROOT, "templates") if not args.debug else "templates" web = PhotosWeb(library, tpl_dir) - web_config = {} + web_config = {'error_page.403': web.error, + 'error_page.404': web.error} def validate_password(realm, username, password): print("I JUST VALIDATED {}:{} ({})".format(username, password, realm)) diff --git a/photoapp/dateoffset.py b/photoapp/dateoffset.py new file mode 100644 index 0000000..f82603d --- /dev/null +++ b/photoapp/dateoffset.py @@ -0,0 +1,27 @@ +import argparse +from photoapp.library import PhotoLibrary +from photoapp.types import PhotoSet +from datetime import timedelta + + +def set_offset(library, uuid, offset): + s = library.session() + photo = s.query(PhotoSet).filter(PhotoSet.uuid == uuid).first() + print("Original date: {}".format(photo.date)) + photo.date_offset = offset + photo.date = photo.date_real + timedelta(minutes=offset) + print("New date: {}".format(photo.date)) + s.commit() + + +def main(): + parser = argparse.ArgumentParser(description="Photo date offset manipulation tool") + parser.add_argument("-u", "--uuid", required=True, help="photo uuid") + parser.add_argument("-o", "--offset", required=True, type=int, help="offset in minutes") + args = parser.parse_args() + library = PhotoLibrary("photos.db", "./library/", "./cache/") + set_offset(library, args.uuid, args.offset) + + +if __name__ == '__main__': + main() diff --git a/templates/create_tags.html b/templates/create_tags.html index 7470cc7..da44136 100644 --- a/templates/create_tags.html +++ b/templates/create_tags.html @@ -1,6 +1,7 @@ {% extends "page.html" %} -{% set title = "Placeholder Title" %} -{% set subtitle = "Foobar" %} +{% block title %}Tagging {{ num_photos }} photo{% if num_photos > 1 %}s{% endif %}{% endblock %} +{% block subtitle %}{% endblock %} +{% block buttons %}{% endblock %} {% block body %} @@ -25,7 +26,7 @@ {% if fromdate %}{% endif %} {% if uuid %}{% endif %} - + {% endfor %} @@ -40,7 +41,7 @@ {% if fromdate %}{% endif %} {% if uuid %}{% endif %} - + {% endfor %} diff --git a/templates/error.html b/templates/error.html new file mode 100644 index 0000000..88544d4 --- /dev/null +++ b/templates/error.html @@ -0,0 +1,17 @@ +{% extends "page.html" %} +{% block title %}{{ status }}{% endblock %} +{% block subtitle %}{% endblock %} +{% block buttons %}{% endblock %} + +{% block body %} + +
+
+

{{ message }}

+
+
+
{{ traceback }}
+
+
+ +{% endblock %}