示例#1
0
def add():
    """
    Add a new thing
    """
    m = request.args.get('maker', '')
    c = request.args.get('collection', None)
    form = ThingForm(formdata=request.form, makers_raw=m,
                     collection=c, exclude=['creator'])
    if form.validate_on_submit():
        thing = Thing()
        form.populate_obj(thing)
        thing.parse_makers_string(form.makers_raw.data)
        thing.save()
        if form.collection.data:
            collection = Collection.objects(id=form.collection.data).first()
            if collection:
                collection.add_thing(thing=thing)
        flash("'%s' created! Now, upload a file. When you are done <a href='%s'>click here</a>. If you skip this step, then this will be classified as a 'request' and hopefully someone else will upload a file." %
              (thing.title, url_for('thing.detail', id=thing.id)))
        # Upload form
        upload_form = UploadForm()
    else:
        thing = False
        upload_form = False
    return render_template('thing/add.html',
                           title='Add Thing',
                           form=form,
                           upload_form=upload_form,
                           thing=thing
                           )
示例#2
0
def edit(id):
    """
    Edit a thing
    """
    model = Thing.objects.get_or_404(id=id)
    if not can_edit_thing(model):
        abort(403)
    form = ThingForm(formdata=request.form, obj=model,
                     makers_raw=model.format_makers_string(), exclude=['creator'])
    if form.validate_on_submit():
        form.populate_obj(model)
        model.parse_makers_string(form.makers_raw.data)
        model.save()
        flash("Thing updated")
        return redirect(url_for("thing.detail", id=model.id))
    return render_template('thing/edit.html',
                           title='Edit',
                           form=form)
示例#3
0
def edit(id):
    """
    Edit a thing
    """
    model = Thing.objects.get_or_404(id=id)
    if not can_edit_thing(model):
        abort(403)
    form = ThingForm(formdata=request.form,
                     obj=model,
                     makers_raw=model.format_makers_string(),
                     exclude=['creator'])
    if form.validate_on_submit():
        form.populate_obj(model)
        model.parse_makers_string(form.makers_raw.data)
        model.save()
        flash("Thing updated")
        return redirect(url_for("thing.detail", id=model.id))
    return render_template('thing/edit.html', title='Edit', form=form)
示例#4
0
def add():
    """
    Add a new thing
    """
    if current_user.has_role('spammer'):
        abort(403)
    m = request.args.get('maker', '')
    c = request.args.get('collection', None)
    form = ThingForm(formdata=request.form,
                     makers_raw=m,
                     collection=c,
                     exclude=['creator'])
    if form.validate_on_submit():
        thing = Thing()
        form.populate_obj(thing)
        thing.parse_makers_string(form.makers_raw.data)
        thing.save()
        # If there are already files to upload do it here
        files = request.files
        for key, file in files.iteritems():
            um = UploadManager()
            u = um.set_uploaded_file(file)
            if thing:
                thing.add_file(u)
        #
        if form.collection.data:
            collection = Collection.objects(id=form.collection.data).first()
            if collection:
                collection.add_thing(thing=thing)
        flash(
            "'%s' created! Now, upload a file. When you are done <a href='%s'>click here</a>. If you skip this step, then this will be classified as a 'request' and hopefully someone else will upload a file."
            % (thing.title, url_for('thing.detail', id=thing.id)))
        # Upload form
        upload_form = UploadForm()
    else:
        thing = False
        upload_form = False
    return render_template('thing/add.html',
                           title='Add Thing',
                           form=form,
                           upload_form=upload_form,
                           thing=thing)
示例#5
0
def add():
    """
    Add a new thing
    """
    if current_user.has_role('spammer'):
        abort(403)
    m = request.args.get('maker', '')
    c = request.args.get('collection', None)
    form = ThingForm(formdata=request.form, makers_raw=m,
                     collection=c, exclude=['creator'])
    if form.validate_on_submit():
        thing = Thing()
        form.populate_obj(thing)
        thing.parse_makers_string(form.makers_raw.data)
        thing.save()
        # If there are already files to upload do it here
        files = request.files
        for key, file in files.iteritems():
            um = UploadManager()
            u = um.set_uploaded_file(file)
            if thing:
                thing.add_file(u)
        #
        if form.collection.data:
            collection = Collection.objects(id=form.collection.data).first()
            if collection:
                collection.add_thing(thing=thing)
        flash("'%s' created! Now, upload a file. When you are done <a href='%s'>click here</a>. If you skip this step, then this will be classified as a 'request' and hopefully someone else will upload a file." %
              (thing.title, url_for('thing.detail', id=thing.id)))
        # Upload form
        upload_form = UploadForm()
    else:
        thing = False
        upload_form = False
    return render_template('thing/add.html',
                           title='Add Thing',
                           form=form,
                           upload_form=upload_form,
                           thing=thing
                           )