From 0e25b312ab324ed664b5ed387f3c9d43b2b8081b Mon Sep 17 00:00:00 2001 From: dave Date: Sun, 23 Sep 2018 13:04:50 -0700 Subject: [PATCH] misc auth functions --- photoapp/daemon.py | 18 +++++++++++++++++- photoapp/types.py | 2 +- templates/album.html | 2 ++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/photoapp/daemon.py b/photoapp/daemon.py index 8d1a87c..10ed467 100644 --- a/photoapp/daemon.py +++ b/photoapp/daemon.py @@ -87,7 +87,7 @@ class PhotosWeb(object): tagq = s.query(Tag).join(TagItem).join(PhotoSet) if not auth(): tagq = tagq.filter(PhotoSet.status == PhotoStatus.public) - tagq = tagq.order_by(Tag.title).all() # pragma: manual auth + tagq = tagq.filter(Tag.is_album == False).order_by(Tag.title).all() # pragma: manual auth albumq = s.query(Tag).join(TagItem).join(PhotoSet) if not auth(): @@ -388,6 +388,14 @@ class TagView(object): @cherrypy.expose @require_auth def op(self, uuid, op): + """ + Perform some action on this tag + - Promote: label this tag an album + - Demote: label this tag as only a tag and not an album + - Delete: remove this tag + - Make all public: mark all photos under this tag as public + - Make all private: mark all photos under this tag as private + """ s = self.master.session() tag = s.query(Tag).filter(Tag.uuid == uuid).first() if op == "Demote to tag": @@ -399,6 +407,14 @@ class TagView(object): s.delete(tag) s.commit() 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(): + 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(): + photo.status = PhotoStatus.private else: raise Exception("Invalid op: '{}'".format(op)) s.commit() diff --git a/photoapp/types.py b/photoapp/types.py index 5b2e911..844b1f7 100644 --- a/photoapp/types.py +++ b/photoapp/types.py @@ -61,7 +61,7 @@ class Tag(Base): uuid = Column(Unicode, unique=True, default=lambda: str(uuid.uuid4())) created = Column(DateTime, default=lambda: datetime.now()) modified = Column(DateTime, default=lambda: datetime.now()) - is_album = Column(Boolean) + is_album = Column(Boolean, default=False) title = Column(String, unique=True) slug = Column(String, unique=True) description = Column(String) diff --git a/templates/album.html b/templates/album.html index e409cb9..e04a62b 100644 --- a/templates/album.html +++ b/templates/album.html @@ -6,6 +6,8 @@
{% if tag.is_album %}{% else %} {% endif %} + +
{% endblock %}