Пример #1
0
def sort_actions(id):
    hide = request.args.get('hide', '')
    model = Thing.objects.get_or_404(id=id)
    if not hide == 'collections':
        form = AddThingToCollectionsForm()
        form.set_thing(model)
    else:
        form = None
    queues = Queue.objects.filter(creator=current_user.get_id())
    return render_template('thing/sort_actions.html',
                           form=form,
                           queues=queues,
                           thing=model)
Пример #2
0
def sort_actions(id):
    hide = request.args.get('hide', '')
    model = Thing.objects.get_or_404(id=id)
    if not hide == 'collections':
        form = AddThingToCollectionsForm()
        form.set_thing(model)
    else:
        form = None
    queues = Queue.objects.filter(creator=current_user.get_id())
    return render_template(
        'thing/sort_actions.html',
        form=form,
        queues=queues,
        thing=model
    )
Пример #3
0
def add_thing(thing_id):
    """
    Adds a thing to a collection. The collection and a note are submitted via form.
    """
    thing = Thing.objects.get_or_404(id=thing_id)
    cf = AddThingToCollectionsForm(formdata=request.form)
    cf.set_thing(thing)
    if cf.validate_on_submit():
        collection = cf.collection.data
        if not collection.has_thing(thing):
            collection.add_thing(thing=thing, note=cf.note.data)
        return jsonify({
            'result': 'success',
            'message': 'Added to <a href="%s">%s</a>!' % (url_for('collection.detail', id=collection.id), collection.title),
            'collection': unicode(get_template_attribute('collection/macros.html', 'show_collections_list_item')(collection, thing))})
    return jsonify({'result': 'error', 'message': 'Sorry, there was a problem'})
Пример #4
0
def list_for_thing(thing_id):
    """
    A list of collections and optional form
    """
    thing = Thing.objects.get_or_404(id=thing_id)
    collections = Collection.objects.filter(things__thing=thing)
    # Add this thing to one or more collections
    if can_add_thing_to_collections():
        cf = AddThingToCollectionsForm(formdata=request.form)
        cf.set_thing(thing)
        if cf.validate_on_submit():
            ct = CollectedThing()
            cf.populate_obj(ct)
            cf.collection.data.add_thing(ct)
        form_template = get_template_attribute(
            'collection/macros.html', 'add_to_collection_form')(cf)
        return get_template_attribute('collection/macros.html', 'show_collections_list')(collections, thing, form_template)
    else:
        return get_template_attribute('collection/macros.html', 'show_collections_list')(collections, thing)