示例#1
0
def crop(photo):
    pic = Photo.get_photo(photo)
    if not pic:
        flash("The photo you want to crop wasn't found!")
        return redirect(url_for(".albums"))

    # Saving?
    if request.method == "POST":
        try:
            x      = int(request.form.get("x", 0))
            y      = int(request.form.get("y", 0))
            length = int(request.form.get("length", 0))
        except:
            flash("Error with form inputs.")
            return redirect(url_for(".crop", photo=photo))

        # Re-crop the photo!
        Photo.crop_photo(photo, x, y, length)
        flash("The photo has been cropped!")
        return redirect(url_for(".albums")) # TODO go to photo

    # Get the photo's true size.
    true_width, true_height = Photo.get_image_dimensions(pic)
    g.info["true_width"] = true_width
    g.info["true_height"] = true_height
    g.info["photo"] = photo
    g.info["preview"] = pic["large"]
    return template("photos/crop.html")
示例#2
0
def get_picture(uid):
    """Get the chosen profile photo for the user."""
    data = get_user(uid=uid)
    pic = data["picture"]
    if len(pic):
        photo = Photo.get_photo(pic)
        if photo:
            return photo["avatar"]
    return None
示例#3
0
def set_cover(album, key):
    """Set the pic as the album cover."""
    pic = Photo.get_photo(key)
    if not pic:
        flash("The photo you want to crop wasn't found!")
        return redirect(url_for(".albums"))

    Photo.set_album_cover(album, key)
    flash("Album cover has been set.")
    return redirect(url_for(".albums"))
示例#4
0
def set_profile(key):
    """Set the pic as your profile picture."""
    pic = Photo.get_photo(key)
    if not pic:
        flash("The photo wasn't found!")
        return redirect(url_for(".albums"))

    uid = g.info["session"]["uid"]
    User.update_user(uid, dict(picture=key))
    flash("Your profile picture has been updated.")
    return redirect(url_for(".view_photo", key=key))
示例#5
0
def view_photo(key):
    """View a specific photo."""
    photo = Photo.get_photo(key)
    if photo is None:
        flash("That photo wasn't found!")
        return redirect(url_for(".albums"))

    # Get the author info.
    author = User.get_user(uid=photo["author"])
    if author:
        g.info["author"] = author

    g.info["photo"] = photo
    g.info["photo"]["key"] = key
    g.info["photo"]["pretty_time"] = pretty_time(Config.photo.time_format, photo["uploaded"])
    g.info["photo"]["markdown"] = render_markdown(photo.get("description", ""))
    return template("photos/view.html")
示例#6
0
def delete(key):
    """Delete 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":
        # Do it.
        Photo.delete_photo(key)
        flash("The photo has been deleted.")
        return redirect(url_for(".albums"))

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

    return template("photos/delete.html")
示例#7
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")