示例#1
0
def update_doc(doc_id):
    """Upload a new version of a document."""
    doc = Document.query.get(doc_id)
    form = UpdateDocumentForm()
    if form.validate_on_submit():

        file_obj = form.uploaded.data
        filename = insert_in_filename(werkzeug.secure_filename(file_obj.filename), "-{0}-rev.{1}".format(
            current_user.username, len(doc.versions)))
        upload_to_s3(file_obj, filename)
        s3path = make_s3_path(filename)

        version = Version(form.comment.data, s3path, croc.add_doc_to_croc(s3path), doc)

        add_model(version)
        flash("Added new version of {0}".format(doc.name), 'success')
        return redirect(url_for('docs.view_doc', doc_id=doc.uid))
    else:
        return redirect(url_for('docs.view_doc', doc_id=doc.uid))
示例#2
0
def upload():
    """Display upload template, and upload document if form submitted."""
    form = DocumentForm()
    if form.validate_on_submit():
        file_obj = form.uploaded.data
        filename = werkzeug.secure_filename(file_obj.filename)
        randstr = upload_to_s3(file_obj)
        if randstr:
            filename = insert_in_filename(filename, randstr)
        doc = Document(form.name.data, make_s3_path(filename),
                       request.form['format'], current_user)
        doc.uuid = croc.add_doc_to_croc(doc.s3path)

        db.session.add(doc)
        db.session.commit()

        flash("Successfully uploaded {0}".format(filename), 'success')
        return redirect(url_for('home'))
    return render_template('upload.html', form=form)