Exemple #1
0
def new_collection():
    """ Allow user to create new collection """
    form = CollectionForm(request.form)

    if request.method == 'POST' and form.validate():

        collection = Collection()
        form.populate_obj(collection)

        current_user.collections.append(collection)
        db.session.add(collection)

        collection = Collection.query.filter_by(name=collection.name).first()
        collection.name = collection.name.replace(" ", "_")
        db.session.commit()

        return redirect(
            url_for("contribute.upload_files", collection=collection.name))

    return render_template("contribute/new.html", form=form)
Exemple #2
0
def edit_collection(collection_name):
    """ Allow owner to edit collection """
    collection = Collection.query.filter_by(name=collection_name).first()
    if collection is None:
        abort(404)

    user = User.query.filter_by(id=collection.user_id).first()
    # only owner can view
    if user != current_user:
        abort(404)

    form = CollectionForm(obj=collection)
    del form.name
    if request.method == 'POST' and form.validate():
        form.populate_obj(collection)
        db.session.commit()

        return redirect(
            url_for("contribute.collection", collection_name=collection.name))

    return render_template(
        "contribute/edit.html",
        collection=collection,
        form=form)