Exemple #1
0
def save_file(uploaded_file, release_id):
    if uploaded_file: # and allowed_file(uploaded_file.filename):
        filename = secure_filename(uploaded_file.filename)
        if os.path.isfile(os.path.join(app.config['UPLOAD_FOLDER'], filename)):
            fileName, fileExtension = os.path.splitext(filename)
            filename = fileName + '-' + time.strftime("%Y%m%d-%H%M%S") + fileExtension
        uploaded_file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        description = "";
        statinfo = os.stat(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        file = File(release_id=release_id, filename=filename, description=description, size=statinfo.st_size)
        file.approved = False;
        db.session.add(file)
        db.session.commit()
Exemple #2
0
def upload_file_old(game_slug):
    release_id = request.args.get('release', None)
    file_id = request.args.get('file', None)

    if file_id:
        file = db.session.query(File).filter(File.id==file_id).one()
        form = UploadForm()
        form.edit.data = "True"
    else:
        form = UploadForm()
        form.edit.data = ""

    if form.validate_on_submit():
        uploaded_file = form.uploaded_file.data
        if uploaded_file: # and allowed_file(uploaded_file.filename):
            filename = secure_filename(uploaded_file.filename)
            if os.path.isfile(os.path.join(app.config['UPLOAD_FOLDER'], filename)):
                fileName, fileExtension = os.path.splitext(filename)
                filename = fileName + '-' + time.strftime("%Y%m%d-%H%M%S") + fileExtension
            uploaded_file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        if form.edit.data:
            if uploaded_file:
                file.filename=filename

            file.description=form.description.data
        else:
            if uploaded_file:
#                release = Release.query.filter(Release.id==release_id).one()
                file = File(release_id=release_id, filename=filename, description=form.description.data)
                db.session.add(file)
        if uploaded_file or form.edit.data:
            file.approved = False;
            db.session.commit()
            if not form.edit.data:
                form.description.data=None
        if form.edit.data:
            flash('File changed!')
        else:
            if uploaded_file:
                flash('File uploaded!')
    else:
        if form.edit.data:
            form.description.data=file.description

    return render_template('add_file.html', form=form, site_data=site_data(), navigation=return_navigation())