nice http error pages
This commit is contained in:
parent
b81cad8b71
commit
aff62835ec
|
@ -1,3 +1,4 @@
|
||||||
|
__pycache__
|
||||||
build/
|
build/
|
||||||
cache/
|
cache/
|
||||||
dist/
|
dist/
|
||||||
|
|
|
@ -193,7 +193,7 @@ class PhotosWeb(object):
|
||||||
s.commit()
|
s.commit()
|
||||||
|
|
||||||
if newtag:
|
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()
|
s.commit()
|
||||||
|
|
||||||
photos, num_photos = get_photos()
|
photos, num_photos = get_photos()
|
||||||
|
@ -230,6 +230,10 @@ class PhotosWeb(object):
|
||||||
else urlparse(cherrypy.request.headers["Referer"]).path
|
else urlparse(cherrypy.request.headers["Referer"]).path
|
||||||
raise cherrypy.HTTPRedirect(dest, 302)
|
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')
|
@cherrypy.popargs('date')
|
||||||
class DateView(object):
|
class DateView(object):
|
||||||
|
@ -345,11 +349,20 @@ class PhotoView(object):
|
||||||
# uuid = uuid.split(".")[0]
|
# uuid = uuid.split(".")[0]
|
||||||
s = self.master.session()
|
s = self.master.session()
|
||||||
photo = photo_auth_filter(s.query(PhotoSet)).filter(or_(PhotoSet.uuid == uuid, PhotoSet.slug == uuid)).first()
|
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)
|
yield self.master.render("photo.html", image=photo)
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
@require_auth
|
@require_auth
|
||||||
def op(self, uuid, op, title=None, description=None, offset=None):
|
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()
|
s = self.master.session()
|
||||||
photo = s.query(PhotoSet).filter(PhotoSet.uuid == uuid).first()
|
photo = s.query(PhotoSet).filter(PhotoSet.uuid == uuid).first()
|
||||||
if op == "Make public":
|
if op == "Make public":
|
||||||
|
@ -464,7 +477,8 @@ def main():
|
||||||
tpl_dir = os.path.join(APPROOT, "templates") if not args.debug else "templates"
|
tpl_dir = os.path.join(APPROOT, "templates") if not args.debug else "templates"
|
||||||
|
|
||||||
web = PhotosWeb(library, tpl_dir)
|
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):
|
def validate_password(realm, username, password):
|
||||||
print("I JUST VALIDATED {}:{} ({})".format(username, password, realm))
|
print("I JUST VALIDATED {}:{} ({})".format(username, password, realm))
|
||||||
|
|
|
@ -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()
|
|
@ -1,6 +1,7 @@
|
||||||
{% extends "page.html" %}
|
{% extends "page.html" %}
|
||||||
{% set title = "Placeholder Title" %}
|
{% block title %}Tagging {{ num_photos }} photo{% if num_photos > 1 %}s{% endif %}{% endblock %}
|
||||||
{% set subtitle = "Foobar" %}
|
{% block subtitle %}{% endblock %}
|
||||||
|
{% block buttons %}{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
@ -25,7 +26,7 @@
|
||||||
{% if fromdate %}<input type="hidden" name="fromdate" value="{{ fromdate }}" />{% endif %}
|
{% if fromdate %}<input type="hidden" name="fromdate" value="{{ fromdate }}" />{% endif %}
|
||||||
{% if uuid %}<input type="hidden" name="uuid" value="{{ uuid }}" />{% endif %}
|
{% if uuid %}<input type="hidden" name="uuid" value="{{ uuid }}" />{% endif %}
|
||||||
<input type="hidden" name="remove" value="{{ tagi.tag.uuid }}" />
|
<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>
|
</form>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -40,7 +41,7 @@
|
||||||
{% if fromdate %}<input type="hidden" name="fromdate" value="{{ fromdate }}" />{% endif %}
|
{% if fromdate %}<input type="hidden" name="fromdate" value="{{ fromdate }}" />{% endif %}
|
||||||
{% if uuid %}<input type="hidden" name="uuid" value="{{ uuid }}" />{% endif %}
|
{% if uuid %}<input type="hidden" name="uuid" value="{{ uuid }}" />{% endif %}
|
||||||
<input type="hidden" name="tag" value="{{ tag.uuid }}" />
|
<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>
|
</form>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -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 %}
|
Loading…
Reference in New Issue