From 95da4b19a1dc9b64ce76c60d381e2abf95808c6f Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Fri, 20 Jun 2014 19:37:48 -0700 Subject: [PATCH] Add endpoint to delete entire photo album --- rophako/modules/photo.py | 21 ++++++++++++++++ rophako/www/photos/album.html | 5 +++- rophako/www/photos/delete_album.html | 14 +++++++++++ scripts/orphaned-photos.py | 37 ++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 rophako/www/photos/delete_album.html create mode 100644 scripts/orphaned-photos.py diff --git a/rophako/modules/photo.py b/rophako/modules/photo.py index 32d6c04..b571201 100644 --- a/rophako/modules/photo.py +++ b/rophako/modules/photo.py @@ -245,6 +245,27 @@ def arrange_albums(): return template("photos/arrange_albums.html") +@mod.route("/delete_album/", methods=["GET", "POST"]) +@login_required +def delete_album(album): + """Delete an entire album.""" + photos = Photo.list_photos(album) + if photos is None: + flash("That album doesn't exist.") + return redirect(url_for(".albums")) + + if request.method == "POST": + # Do it. + for photo in photos: + Photo.delete_photo(photo["key"]) + flash("The album has been deleted.") + return redirect(url_for(".albums")) + + g.info["album"] = album + + return template("photos/delete_album.html") + + @mod.route("/arrange_photos/", methods=["GET", "POST"]) @login_required def arrange_photos(album): diff --git a/rophako/www/photos/album.html b/rophako/www/photos/album.html index dadde16..86143dd 100644 --- a/rophako/www/photos/album.html +++ b/rophako/www/photos/album.html @@ -26,7 +26,10 @@ {% endif %} diff --git a/rophako/www/photos/delete_album.html b/rophako/www/photos/delete_album.html new file mode 100644 index 0000000..ef098c6 --- /dev/null +++ b/rophako/www/photos/delete_album.html @@ -0,0 +1,14 @@ +{% extends "layout.html" %} +{% block title %}Delete Album{% endblock %} +{% block content %} + +

Delete Album

+ +
+ + Are you sure you want to delete the album {{ album }}?

+ + +

+ +{% endblock %} \ No newline at end of file diff --git a/scripts/orphaned-photos.py b/scripts/orphaned-photos.py new file mode 100644 index 0000000..61e073b --- /dev/null +++ b/scripts/orphaned-photos.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +"""Locate any orphaned photos. + +Usage: scripts/orphaned-photos.py """ + +import sys +import os +import codecs +import json +import glob + +sys.path.append(".") +import rophako.jsondb as JsonDB + +def main(): + if len(sys.argv) == 1: + print "Usage: {} ".format(__file__) + sys.exit(1) + + photo_root = sys.argv[1] + + db = JsonDB.get("photos/index") + photos = set() + for album in db["albums"]: + for key, data in db["albums"][album].iteritems(): + for img in ["large", "thumb", "avatar"]: + photos.add(data[img]) + + # Get all the images and compare. + for img in glob.glob("{}/*.*".format(photo_root)): + fname = img.split("/")[-1] + if not fname in photos: + print "Orphan:", fname + +if __name__ == "__main__": + main() \ No newline at end of file