album view for map & cleanup

This commit is contained in:
dave 2018-09-23 18:26:36 -07:00
parent 26dfc8fb6c
commit 5828939015
5 changed files with 30 additions and 17 deletions

4
.gitignore vendored
View File

@ -11,3 +11,7 @@ styles/css/
styles/dist/ styles/dist/
styles/mincss/ styles/mincss/
testenv/ testenv/
cache
dropbox
library
tools/

View File

@ -148,13 +148,16 @@ class PhotosWeb(object):
yield self.render("monthly.html", images=images, tsize=tsize) yield self.render("monthly.html", images=images, tsize=tsize)
@cherrypy.expose @cherrypy.expose
def map(self, i=None, zoom=3): def map(self, i=None, a=None, zoom=3):
""" """
/map - show all photos on the a map, or a single point if $i is passed /map - show all photos on the a map. Passing $i will show a single photo, or passing $a will show photos under
the given tag.
TODO using so many coordinates is slow in the browser. dedupe them somehow. TODO using so many coordinates is slow in the browser. dedupe them somehow.
""" """
s = self.session() s = self.session()
query = photo_auth_filter(s.query(PhotoSet)).filter(PhotoSet.lat != 0, PhotoSet.lon != 0) query = photo_auth_filter(s.query(PhotoSet)).filter(PhotoSet.lat != 0, PhotoSet.lon != 0)
if a:
query = query.join(TagItem).join(Tag).filter(Tag.uuid == a)
if i: if i:
query = query.filter(PhotoSet.uuid == i) query = query.filter(PhotoSet.uuid == i)
yield self.render("map.html", images=query.all(), zoom=int(zoom)) yield self.render("map.html", images=query.all(), zoom=int(zoom))
@ -277,7 +280,6 @@ class ThumbnailView(object):
""" """
def __init__(self, master): def __init__(self, master):
self.master = master self.master = master
self._cp_config = {"tools.trailing_slash.on": False}
@cherrypy.expose @cherrypy.expose
def index(self, item_type, thumb_size, uuid): def index(self, item_type, thumb_size, uuid):
@ -293,6 +295,7 @@ class ThumbnailView(object):
assert query assert query
# prefer making thumbs from jpeg to avoid loading large raws # prefer making thumbs from jpeg to avoid loading large raws
# jk we can't load raws anyway
first = None first = None
best = None best = None
for photo in query.all(): for photo in query.all():
@ -320,7 +323,6 @@ class DownloadView(object):
""" """
def __init__(self, master): def __init__(self, master):
self.master = master self.master = master
self._cp_config = {"tools.trailing_slash.on": False}
@cherrypy.expose @cherrypy.expose
def index(self, item_type, uuid, preview=False): def index(self, item_type, uuid, preview=False):
@ -348,7 +350,6 @@ class PhotoView(object):
""" """
def __init__(self, master): def __init__(self, master):
self.master = master self.master = master
self._cp_config = {"tools.trailing_slash.on": False}
@cherrypy.expose @cherrypy.expose
def index(self, uuid): def index(self, uuid):
@ -398,7 +399,6 @@ class TagView(object):
""" """
def __init__(self, master): def __init__(self, master):
self.master = master self.master = master
# self._cp_config = {"tools.trailing_slash.on": False}
@cherrypy.expose @cherrypy.expose
def index(self, uuid, page=0): def index(self, uuid, page=0):
@ -427,7 +427,7 @@ class TagView(object):
@cherrypy.expose @cherrypy.expose
@require_auth @require_auth
def op(self, uuid, op): def op(self, uuid, op, title=None, description=None):
""" """
Perform some action on this tag Perform some action on this tag
- Promote: label this tag an album - Promote: label this tag an album
@ -455,10 +455,21 @@ class TagView(object):
# TODO smarter query # TODO smarter query
for photo in s.query(PhotoSet).join(TagItem).join(Tag).filter(Tag.id == tag.id).all(): for photo in s.query(PhotoSet).join(TagItem).join(Tag).filter(Tag.id == tag.id).all():
photo.status = PhotoStatus.private photo.status = PhotoStatus.private
elif op == "Save":
tag.title = title
tag.description = description
tag.slug = slugify(title)
else: else:
raise Exception("Invalid op: '{}'".format(op)) raise Exception("Invalid op: '{}'".format(op))
s.commit() s.commit()
raise cherrypy.HTTPRedirect('/tag/{}'.format(tag.uuid), 302) raise cherrypy.HTTPRedirect('/tag/{}'.format(tag.slug or tag.uuid), 302)
@cherrypy.expose
@require_auth
def edit(self, uuid):
s = self.master.session()
tag = s.query(Tag).filter(Tag.uuid == uuid).first()
yield self.master.render("tag_edit.html", tag=tag)
def main(): def main():
@ -483,8 +494,6 @@ 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 = {'error_page.403': web.error,
'error_page.404': web.error}
def validate_password(realm, username, password): def validate_password(realm, username, password):
s = library.session() s = library.session()
@ -492,7 +501,9 @@ def main():
return True return True
return False return False
cherrypy.tree.mount(web, '/', {'/': web_config, cherrypy.tree.mount(web, '/', {'/': {'tools.trailing_slash.on': False,
'error_page.403': web.error,
'error_page.404': web.error},
'/static': {"tools.staticdir.on": True, '/static': {"tools.staticdir.on": True,
"tools.staticdir.dir": os.path.join(APPROOT, "styles/dist") "tools.staticdir.dir": os.path.join(APPROOT, "styles/dist")
if not args.debug else os.path.abspath("styles/dist")}, if not args.debug else os.path.abspath("styles/dist")},

View File

@ -10,6 +10,8 @@
<input type="submit" class="secondary-button pure-button" name="op" value="Make all private" /> <input type="submit" class="secondary-button pure-button" name="op" value="Make all private" />
<input type="submit" class="secondary-button pure-button" name="op" value="Delete tag" /> <input type="submit" class="secondary-button pure-button" name="op" value="Delete tag" />
</form> </form>
<a href="/map?zoom=6&a={{ tag.uuid }}"><button class="secondary-button pure-button">Map</button></a>
<a href="/tag/{{ tag.uuid }}/edit"><button class="secondary-button pure-button">Edit</button></a>
{% endblock %} {% endblock %}
{% block body %} {% block body %}

View File

@ -52,11 +52,7 @@
</div> </div>
{% if auth %} {% if auth %}
<div class="email-content-controls pure-u-1-2"> <div class="email-content-controls pure-u-1-2">
{% block buttons %} {% block buttons %}{% endblock %}
<button class="secondary-button pure-button">420</button>
<button class="secondary-button pure-button">Blaze</button>
<button class="secondary-button pure-button">It</button>
{% endblock %}
</div> </div>
{% endif %} {% endif %}
</div> </div>

View File

@ -1,5 +1,5 @@
{% extends "page.html" %} {% extends "page.html" %}
{% block title %}Editing {{ image.uuid }}{% endblock %} {% block title %}Editing {{ image.title or image.uuid }}{% endblock %}
{% block subtitle %}{{ image.date }}{% endblock %} {% block subtitle %}{{ image.date }}{% endblock %}
{% block buttons %} {% block buttons %}