示例#1
0
def upload():
    """Upload a photo."""

    if request.method == "POST":
        # We're posting the upload.

        # Is this an ajax post or a direct post?
        is_ajax = request.form.get("__ajax", "false") == "true"

        # Album name.
        album = request.form.get("album") or request.form.get("new-album")

        # What source is the pic from?
        result = None
        location = request.form.get("location")
        if location == "pc":
            # An upload from the PC.
            result = Photo.upload_from_pc(request)
        elif location == "www":
            # An upload from the Internet.
            result = Photo.upload_from_www(request.form)
        else:
            flash("Stop messing around.")
            return redirect(url_for(".upload"))

        # How'd it go?
        if result["success"] is not True:
            if is_ajax:
                return ajax_response(False, result["error"])
            else:
                flash("The upload has failed: {}".format(result["error"]))
                return redirect(url_for(".upload"))

        # Good!
        if is_ajax:
            # Was it a multiple upload?
            if result.get("multi"):
                return ajax_response(True, url_for(".album_index", name=album))
            else:
                return ajax_response(True, url_for(".crop", photo=result["photo"]))
        else:
            if result["multi"]:
                return redirect(url_for(".album_index", name=album))
            else:
                return redirect(url_for(".crop", photo=result["photo"]))

    # Get the list of available albums.
    g.info["album_list"] = [
        "My Photos", # the default
    ]
    g.info["selected"] = Config.photo.default_album
    albums = Photo.list_albums()
    if len(albums):
        g.info["album_list"] = [ x["name"] for x in albums ]
        g.info["selected"] = albums[0]

    return template("photos/upload.html")
示例#2
0
def albums():
    """View the index of the photo albums."""
    albums = Photo.list_albums()

    # If there's only one album, jump directly to that one.
    if len(albums) == 1:
        return redirect(url_for(".album_index", name=albums[0]["name"]))

    g.info["albums"] = albums
    return template("photos/albums.html")
示例#3
0
def arrange_albums():
    """Rearrange the photo album order."""
    albums = Photo.list_albums()
    if len(albums) == 0:
        flash("There are no albums yet.")
        return redirect(url_for(".albums"))

    if request.method == "POST":
        order = request.form.get("order", "").split(";")
        Photo.order_albums(order)
        flash("The albums have been rearranged!")
        return redirect(url_for(".albums"))

    g.info["albums"] = albums
    return template("photos/arrange_albums.html")