diff --git a/cps/web.py b/cps/web.py
old mode 100755
new mode 100644
index 28fc847c..721be5e0
--- a/cps/web.py
+++ b/cps/web.py
@@ -3055,48 +3055,50 @@ def edit_book(book_id):
# Check and handle Uploaded file
if 'btn-upload-format' in request.files:
requested_file = request.files['btn-upload-format']
- if '.' in requested_file.filename:
- file_ext = requested_file.filename.rsplit('.', 1)[-1].lower()
- if file_ext not in ALLOWED_EXTENSIONS:
- flash(_('File extension "%s" is not allowed to be uploaded to this server' % file_ext), category="error")
+ # check for empty request
+ if requested_file.filename != '':
+ if '.' in requested_file.filename:
+ file_ext = requested_file.filename.rsplit('.', 1)[-1].lower()
+ if file_ext not in ALLOWED_EXTENSIONS:
+ flash(_('File extension "%s" is not allowed to be uploaded to this server' % file_ext), category="error")
+ return redirect(url_for('show_book', book_id=book.id))
+ else:
+ flash(_('File to be uploaded must have an extension'), category="error")
return redirect(url_for('show_book', book_id=book.id))
- else:
- flash(_('File to be uploaded must have an extension'), category="error")
- return redirect(url_for('show_book', book_id=book.id))
- file_name = book.path.rsplit('/', 1)[-1]
- filepath = os.path.normpath(os.path.join(config.config_calibre_dir, book.path))
- saved_filename = os.path.join(filepath, file_name + '.' + file_ext)
+ file_name = book.path.rsplit('/', 1)[-1]
+ filepath = os.path.normpath(os.path.join(config.config_calibre_dir, book.path))
+ saved_filename = os.path.join(filepath, file_name + '.' + file_ext)
- # check if file path exists, otherwise create it, copy file to calibre path and delete temp file
- if not os.path.exists(filepath):
+ # check if file path exists, otherwise create it, copy file to calibre path and delete temp file
+ if not os.path.exists(filepath):
+ try:
+ os.makedirs(filepath)
+ except OSError:
+ flash(_(u"Failed to create path %s (Permission denied)." % filepath), category="error")
+ return redirect(url_for('show_book', book_id=book.id))
try:
- os.makedirs(filepath)
+ requested_file.save(saved_filename)
except OSError:
- flash(_(u"Failed to create path %s (Permission denied)." % filepath), category="error")
+ flash(_(u"Failed to store file %s." % saved_filename), category="error")
return redirect(url_for('show_book', book_id=book.id))
- try:
- requested_file.save(saved_filename)
- except OSError:
- flash(_(u"Failed to store file %s." % saved_filename), category="error")
- return redirect(url_for('show_book', book_id=book.id))
- file_size = os.path.getsize(saved_filename)
- is_format = db.session.query(db.Data).filter(db.Data.book == book_id).filter(db.Data.format == file_ext.upper()).first()
-
- # Format entry already exists, no need to update the database
- if is_format:
- app.logger.info('Book format already existing')
- else:
- db_format = db.Data(book_id, file_ext.upper(), file_size, file_name)
- db.session.add(db_format)
- db.session.commit()
- db.session.connection().connection.connection.create_function("title_sort", 1, db.title_sort)
+ file_size = os.path.getsize(saved_filename)
+ is_format = db.session.query(db.Data).filter(db.Data.book == book_id).filter(db.Data.format == file_ext.upper()).first()
- # Queue uploader info
- uploadText=_(u"File format %s added to %s" % (file_ext.upper(),book.title))
- helper.global_WorkerThread.add_upload(current_user.nickname,
- ""+ uploadText + "")
+ # Format entry already exists, no need to update the database
+ if is_format:
+ app.logger.info('Book format already existing')
+ else:
+ db_format = db.Data(book_id, file_ext.upper(), file_size, file_name)
+ db.session.add(db_format)
+ db.session.commit()
+ db.session.connection().connection.connection.create_function("title_sort", 1, db.title_sort)
+
+ # Queue uploader info
+ uploadText=_(u"File format %s added to %s" % (file_ext.upper(),book.title))
+ helper.global_WorkerThread.add_upload(current_user.nickname,
+ ""+ uploadText + "")
to_save = request.form.to_dict()