Пример #1
0
def add():
    """
    Add a new collection
    """
    form = CollectionForm(exclude=['creator'])
    if form.validate_on_submit():
        model = SuperCollection()
        form.populate_obj(model)
        model.save()
        flash("Collection created")
        return redirect(url_for("collection.list"))
    return render_template('collection/edit.html',
                           title='Start a Collection',
                           form=form
                           )
Пример #2
0
def edit(id):
    """
    Edit a thing
    """
    model = Collection.objects.get_or_404(id=id)
    if not can_edit_collection(model):
        abort(403)
    form = CollectionForm(formdata=request.form,
                          obj=model, exclude=['creator'])
    if form.validate_on_submit():
        model.title = form.title.data
        model.short_description = form.short_description.data
        model.description = form.description.data
        model.save()
        flash("Collection updated")
        return redirect(url_for("collection.detail", id=model.id))
    return render_template('collection/edit.html',
                           title='Edit',
                           form=form)
Пример #3
0
def add_subcollection(id):
    """
    Add a new subcollection
    """
    c = Collection.objects.get_or_404(id=id)
    form = CollectionForm(exclude=['creator'], accessibility=c.accessibility)
    if form.validate_on_submit():
        sc = SuperCollection()
        form.populate_obj(sc)
        sc.supercollection = c
        sc.save()
        c.add_subcollection(sc)
        flash("Subcollection created")
        return redirect(url_for("collection.detail", id=c.id))
    return render_template('collection/edit.html',
                           title='Start a Subcollection in %s' % c.title,
                           form=form,
                           collection=c
                           )
Пример #4
0
def add():
    """
    Add a new collection
    """
    form = CollectionForm(exclude=['creator'])
    if form.validate_on_submit():
        model = SuperCollection()
        form.populate_obj(model)
        model.save()
        flash("Collection created")
        if request.is_xhr:
            return jsonify({
                'message':'Success', 
                'data':str(model.id)
                })
        return redirect(url_for("collection.list"))
    return render_template('collection/edit.html',
                           title='Start a Collection',
                           form=form
                           )