Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from flask import current_app, render_template, flash, redirect, url_for, abort
#...
@main.route('/edit-collection/<int:id>', methods=['GET', 'POST'])
@login_required
def edit_collection(id):
collection = Collection.query.get_or_404(id)
if current_user != collection.author and \
not current_user.can(Permission.ADMIN):
abort(403)
form = CollectionForm()
if form.validate_on_submit():
# Update Database
collection.name = form.name.data
collection.description = form.description.data
db.session.commit()
# Update Stream Activity
if collection.update_stream():
return redirect(url_for('.edit_collection', id=id))
form.name.data = collection.name
form.description.data = collection.description
return render_template('edit_collection.html', collection=collection, form=form)
@main.route('/delete-collection/<int:id>', methods=['GET', 'POST'])
@login_required
def delete_collection(id):
collection = Collection.query.get_or_404(id)
if current_user != collection.author and \
not current_user.can(Permission.ADMIN):
abort(403)
if collection.delete_from_stream():
db.session.delete(collection)
db.session.commit()
flash('Your Collection has been deleted.')
return redirect(url_for('.index'))
else:
flash("An error occurred, please try again")
return redirect(url_for('.edit_collection', id=collection.id))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.