nice http error pages

This commit is contained in:
dave 2018-09-23 15:26:41 -07:00
parent b81cad8b71
commit aff62835ec
5 changed files with 66 additions and 6 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
__pycache__
build/
cache/
dist/

View File

@ -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))

27
photoapp/dateoffset.py Normal file
View File

@ -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()

View File

@ -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 %}<input type="hidden" name="fromdate" value="{{ fromdate }}" />{% endif %}
{% if uuid %}<input type="hidden" name="uuid" value="{{ uuid }}" />{% endif %}
<input type="hidden" name="remove" value="{{ tagi.tag.uuid }}" />
<input class="submit-link" type="submit" value="{{ tagi.tag.title }}" />
<input class="submit-link" type="submit" value="{{ tagi.tag.name }}" />
</form>
</li>
{% endfor %}
@ -40,7 +41,7 @@
{% if fromdate %}<input type="hidden" name="fromdate" value="{{ fromdate }}" />{% endif %}
{% if uuid %}<input type="hidden" name="uuid" value="{{ uuid }}" />{% endif %}
<input type="hidden" name="tag" value="{{ tag.uuid }}" />
<input class="submit-link" type="submit" value="{{ tag.title }}" />
<input class="submit-link" type="submit" value="{{ tag.name }}" />
</form>
</li>
{% endfor %}

17
templates/error.html Normal file
View File

@ -0,0 +1,17 @@
{% extends "page.html" %}
{% block title %}{{ status }}{% endblock %}
{% block subtitle %}{% endblock %}
{% block buttons %}{% endblock %}
{% block body %}
<div class="photo-feed">
<div>
<p>{{ message }}</p>
</div>
<div>
<pre>{{ traceback }}</pre>
</div>
</div>
{% endblock %}