|
|
@@ -73,24 +73,19 @@ def edit(file_id):
|
|
|
file = None
|
|
|
if 'file' in request.files:
|
|
|
file = request.files['file']
|
|
|
- if file.filename == '':
|
|
|
- flash('No file selected', 'warning')
|
|
|
- return redirect(request.url)
|
|
|
- if file and allowed_file(file.filename):
|
|
|
+ if file and file.filename != '' and allowed_file(file.filename):
|
|
|
filename = secure_filename(file.filename)
|
|
|
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
|
|
|
-
|
|
|
- filename = db_file.path
|
|
|
- if file is not None:
|
|
|
- db_file.path = file.filename
|
|
|
+ db_file.path = filename
|
|
|
if request.form['title']:
|
|
|
- title = request.form['title']
|
|
|
+ title = request.form['title']
|
|
|
url = quote(title.strip().lower().replace(" ", "_"))
|
|
|
+ old_path = db_file.path
|
|
|
db_file.path = secure_filename('%s.%s' % (url, db_file.path.rsplit('.', 1)[1]))
|
|
|
- os.rename(os.path.join(app.config['UPLOAD_FOLDER'], filename), os.path.join(app.config['UPLOAD_FOLDER'], db_file.path))
|
|
|
+ os.replace(os.path.join(app.config['UPLOAD_FOLDER'], old_path), os.path.join(app.config['UPLOAD_FOLDER'], db_file.path))
|
|
|
|
|
|
- db_file.title = title
|
|
|
- db_file.user_id = current_user.id
|
|
|
+ db_file.title = title
|
|
|
+ db_file.user_id = current_user.id
|
|
|
|
|
|
db.session.add(db_file)
|
|
|
db.session.commit()
|