Add endpoint to delete entire photo album
This commit is contained in:
parent
3e6e51e308
commit
95da4b19a1
|
@ -245,6 +245,27 @@ def arrange_albums():
|
|||
return template("photos/arrange_albums.html")
|
||||
|
||||
|
||||
@mod.route("/delete_album/<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/<album>", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def arrange_photos(album):
|
||||
|
|
|
@ -26,7 +26,10 @@
|
|||
|
||||
<ul>
|
||||
<li><a href="{{ url_for('photo.upload') }}">Upload a Photo</a></li>
|
||||
{% if photos|length > 0 %}<li><a href="{{ url_for('photo.arrange_photos', album=album) }}">Rearrange Photos</a></li>{% endif %}
|
||||
{% if photos|length > 0 %}
|
||||
<li><a href="{{ url_for('photo.arrange_photos', album=album) }}">Rearrange Photos</a></li>
|
||||
<li><a href="{{ url_for('photo.delete_album', album=album) }}">Delete Album</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
|
|
14
rophako/www/photos/delete_album.html
Normal file
14
rophako/www/photos/delete_album.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
{% extends "layout.html" %}
|
||||
{% block title %}Delete Album{% endblock %}
|
||||
{% block content %}
|
||||
|
||||
<h1>Delete Album</h1>
|
||||
|
||||
<form name="delete" action="{{ url_for('photo.delete_album', album=album) }}" method="POST">
|
||||
<input type="hidden" name="token" value="{{ csrf_token() }}">
|
||||
Are you <strong>sure</strong> you want to delete the album <strong>{{ album }}</strong>?<p>
|
||||
|
||||
<button type="submit">Yes, Delete This Album</button>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
37
scripts/orphaned-photos.py
Normal file
37
scripts/orphaned-photos.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""Locate any orphaned photos.
|
||||
|
||||
Usage: scripts/orphaned-photos.py <path/to/db> <path/to/static/photos>"""
|
||||
|
||||
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: {} <path/to/static/photos>".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()
|
Loading…
Reference in New Issue
Block a user