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