Last active
February 13, 2020 13:19
-
-
Save Porter97/cfaac8372f3b1f61ca30028bc00b8df8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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