def edit_album(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": # Collect the form details. new_name = request.form["name"] description = request.form["description"] layout = request.form["format"] # Renaming the album? if new_name != album: ok = Photo.rename_album(album, new_name) if not ok: flash("Failed to rename album: already exists?") return redirect(url_for(".edit_album", album=album)) album = new_name # Update album settings. Photo.edit_album(album, dict( description=description, format=layout, )) return redirect(url_for(".albums")) g.info["album"] = album g.info["album_info"] = Photo.get_album(album) g.info["photos"] = photos return template("photos/edit_album.html")
def arrange_photos(album): """Rearrange the photos in an 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": order = request.form.get("order", "").split(";") Photo.order_photos(album, order) flash("The albums have been rearranged!") return redirect(url_for(".album_index", name=album)) g.info["album"] = album g.info["photos"] = photos return template("photos/arrange_photos.html")
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")
def album_index(name): """View the photos inside an album.""" photos = Photo.list_photos(name) if photos is None: flash("That album doesn't exist.") return redirect(url_for(".albums")) g.info["album"] = name g.info["album_info"] = Photo.get_album(name) g.info["markdown"] = render_markdown(g.info["album_info"]["description"]) g.info["photos"] = photos # Render Markdown descriptions for photos. for photo in g.info["photos"]: photo["data"]["markdown"] = render_markdown(photo["data"].get("description", "")) return template("photos/album.html")
def bulk_captions(album): """Bulk edit captions and titles in an 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: caption_key = "{}:caption".format(photo["key"]) desc_key = "{}:description".format(photo["key"]) if caption_key in request.form and desc_key in request.form: caption = request.form[caption_key] description = request.form[desc_key] Photo.edit_photo(photo['key'], dict(caption=caption, description=description)) flash("The photos have been updated.") return redirect(url_for(".albums")) g.info["album"] = album g.info["photos"] = photos return template("photos/edit_captions.html")