def edit(id): movie = get_model().read(id) if request.method == 'POST': data = request.form.to_dict(flat=True) image_url = upload_image_file(request.files.get('image')) if image_url: data['imageUrl'] = image_url movie = get_model().update(data, id) return redirect(url_for('.view', id=movie['id'])) return render_template("form.html", action="Edit", movie=movie)
def list(): token = request.args.get('page_token', None) if token: token = token.encode('utf-8') movies, next_page_token = get_model().list(cursor=token) return render_template("list.html", movies=movies, next_page_token=next_page_token)
def list_mine(): token = request.args.get('page_token', None) if token: token = token.encode('utf-8') movies, next_page_token = get_model().list_by_user( user_id=session['profile']['id'], cursor=token) return render_template("list.html", movies=movies, next_page_token=next_page_token)
def asc_filtered_list(): token = request.args.get('page_token', None) if token: token = token.encode('utf-8') movies, next_page_token = get_model().list(cursor=token) movies = sorted(movies, key=lambda x: x['releaseDate']) return render_template( "list.html", movies=movies, next_page_token=next_page_token)
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. image_url = upload_image_file(request.files.get('image')) if image_url: data['imageUrl'] = image_url # If the user is logged in, associate their profile with the new movie. if 'profile' in session: data['createdBy'] = session['profile']['displayName'] data['createdById'] = session['profile']['id'] movie = get_model().create(data) return redirect(url_for('.view', id=movie['id'])) return render_template("form.html", action="Add", movie={})
def view(id): movie = get_model().read(id) return render_template("view.html", movie=movie)
def delete(id): get_model().delete(id) return redirect(url_for('.list'))