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
from .forms import EditProfileForm, EditProfileAdminForm, CollectionForm
from .. import db
from ..models import User, Role, Collection, Permission
import stream
#...
@main.route('/collection/<int:id>', methods=['GET'])
def get_collection(id):
collection = Collection.query.get_or_404(id)
return render_template('collection.html', collection=collection)
@main.route('/new-collection/', methods=['GET', 'POST'])
@login_required
def new_collection():
form = CollectionForm()
if current_user.can(Permission.WRITE) and form.validate_on_submit():
collection = Collection(name=form.name.data,
description=form.description.data,
author=current_user._get_current_object())
db.session.add(collection)
if collection.add_to_stream():
db.session.commit()
flash("You have created a new Collection!")
return redirect(url_for('.get_collection', id=collection.id))
else:
db.session.delete(collection)
db.session.commit()
flash("An error occurred, please try again")
return redirect(url_for('.new_collection'))
return render_template('new_collection.html', form=form)
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.