Skip to content

Instantly share code, notes, and snippets.

@Porter97
Last active February 13, 2020 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Porter97/d4340e5c477ab650f51f50da7aa3de57 to your computer and use it in GitHub Desktop.
Save Porter97/d4340e5c477ab650f51f50da7aa3de57 to your computer and use it in GitHub Desktop.
#...
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