Ejemplo n.º 1
0
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")
Ejemplo n.º 2
0
def edit(key):
    """Edit a photo."""
    pic = Photo.get_photo(key)
    if not pic:
        flash("The photo wasn't found!")
        return redirect(url_for(".albums"))

    if request.method == "POST":
        caption     = request.form.get("caption", "")
        description = request.form.get("description", "")
        rotate      = request.form.get("rotate", "")
        Photo.edit_photo(key, dict(caption=caption, description=description))

        # Rotating the photo?
        if rotate in ["left", "right", "180"]:
            Photo.rotate_photo(key, rotate)

        flash("The photo has been updated.")
        return redirect(url_for(".view_photo", key=key))

    g.info["key"] = key
    g.info["photo"] = pic

    return template("photos/edit.html")