Beispiel #1
0
def edit(id):
    artwork = get_model().read(id)

    if request.method == 'POST':
        data = request.form.to_dict(flat=True)

        image_url = upload_image_file(request.files.get('photo'))

        if image_url:
            data['photoUrl'] = image_url

        artwork = get_model().update(data, id)

        return redirect(url_for('.view', id=artwork['id']))

    return render_template("form.html", action="Edit", artwork=artwork)
Beispiel #2
0
def list():
    token = request.args.get('page_token', None)
    if token:
        token = token.encode('utf-8')

    artworks, next_page_token = get_model().list(cursor=token)

    return render_template(
        "list.html",
        artworks=artworks,
        next_page_token=next_page_token)
Beispiel #3
0
def add():
    if request.method == 'POST':
        data = request.form.to_dict(flat=True)

        # If an image was uploaded, update the data to point to the new image.
        # [START image_url]
        image_url = upload_image_file(request.files.get('photo'))
        # [END image_url]

        # [START image_url2]
        if image_url:
            data['photoUrl'] = image_url
        # [END image_url2]

        artwork = get_model().create(data)

        return redirect(url_for('.view', id=artwork['id']))

    return render_template("form.html", action="Add", artwork={})
Beispiel #4
0
def view(id):
    artwork = get_model().read(id)
    return render_template("view.html", artwork=artwork)
Beispiel #5
0
def delete(id):
    get_model().delete(id)
    return redirect(url_for('.list'))