mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-25 02:57:22 +00:00
Added option to upload a new format to a given book
This commit is contained in:
parent
b6b5313f2d
commit
9086f4e0e7
@ -90,3 +90,6 @@ input.pill:not(:checked) + label .glyphicon {
|
|||||||
#meta-info img { max-height: 150px; max-width: 100px; cursor: pointer; }
|
#meta-info img { max-height: 150px; max-width: 100px; cursor: pointer; }
|
||||||
|
|
||||||
.padded-bottom { margin-bottom: 15px; }
|
.padded-bottom { margin-bottom: 15px; }
|
||||||
|
|
||||||
|
.upload-format-input-text {display: initial;}
|
||||||
|
#btn-upload-format {display: none;}
|
||||||
|
@ -205,3 +205,11 @@ $("#search").on("change input.typeahead:selected", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#btn-upload-format").on('change', function () {
|
||||||
|
var filename = $(this).val();
|
||||||
|
if (filename.substring(3,11) == 'fakepath') {
|
||||||
|
filename = filename.substring(12);
|
||||||
|
} // Remove c:\fake at beginning from localhost chrome
|
||||||
|
$('#upload-format').html(filename);
|
||||||
|
});
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{% extends "layout.html" %}
|
{% extends "layout.html" %}
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{% if book %}
|
{% if book %}
|
||||||
<form role="form" action="{{ url_for('edit_book', book_id=book.id) }}" method="post">
|
<form role="form" action="{{ url_for('edit_book', book_id=book.id) }}" method="post" enctype="multipart/form-data">
|
||||||
|
|
||||||
<div class="col-sm-3 col-lg-3 col-xs-12">
|
<div class="col-sm-3 col-lg-3 col-xs-12">
|
||||||
<div class="cover">
|
<div class="cover">
|
||||||
@ -115,7 +115,15 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if g.user.role_upload() or g.user.role_admin()%}
|
||||||
|
{% if g.allow_upload %}
|
||||||
|
<div role="group" aria-label="Upload new book format">
|
||||||
|
<label class="btn btn-default btn-file" for="btn-upload-format">{{ _('Upload format') }}</label>
|
||||||
|
<div class="upload-format-input-text" id="upload-format"></div>
|
||||||
|
<input id="btn-upload-format" name="btn-upload-format" type="file">
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
<label>
|
<label>
|
||||||
|
@ -475,6 +475,10 @@ msgstr "Descarga"
|
|||||||
msgid "Upload"
|
msgid "Upload"
|
||||||
msgstr "Subir archivo"
|
msgstr "Subir archivo"
|
||||||
|
|
||||||
|
#: cps/templates/detail.html:14
|
||||||
|
msgid "Upload format"
|
||||||
|
msgstr "Subir formato"
|
||||||
|
|
||||||
#: cps/templates/admin.html:15
|
#: cps/templates/admin.html:15
|
||||||
msgid "Edit"
|
msgid "Edit"
|
||||||
msgstr "Editar"
|
msgstr "Editar"
|
||||||
|
29
cps/web.py
29
cps/web.py
@ -2724,6 +2724,35 @@ def edit_book(book_id):
|
|||||||
|
|
||||||
# Update book
|
# Update book
|
||||||
edited_books_id = set()
|
edited_books_id = set()
|
||||||
|
|
||||||
|
# Check and handle Uploaded file
|
||||||
|
if 'btn-upload-format' in request.files and '.' in request.files['btn-upload-format'].filename:
|
||||||
|
requested_file = request.files['btn-upload-format']
|
||||||
|
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('index'))
|
||||||
|
|
||||||
|
file_name = book.path.rsplit('/', 1)[-1]
|
||||||
|
filepath = config.config_calibre_dir + os.sep + book.path
|
||||||
|
filepath = os.path.normpath(filepath)
|
||||||
|
saved_filename = filepath + os.sep + file_name + '.' + file_ext
|
||||||
|
file_size = os.path.getsize(requested_file.stream.name)
|
||||||
|
|
||||||
|
try:
|
||||||
|
requested_file.save(saved_filename)
|
||||||
|
except OSError:
|
||||||
|
flash(_(u"Failed to store file %s." % saved_filename), category="error")
|
||||||
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
is_format = db.session.query(db.Data).filter(db.Data.book == book_id).filter(db.Data.format == file_ext.upper()).first()
|
||||||
|
if is_format:
|
||||||
|
# Format entry already exists, no need to update the database
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
db_format = db.Data(book_id, file_ext.upper(), file_size, file_name)
|
||||||
|
db.session.add(db_format)
|
||||||
|
|
||||||
to_save = request.form.to_dict()
|
to_save = request.form.to_dict()
|
||||||
if book.title != to_save["book_title"]:
|
if book.title != to_save["book_title"]:
|
||||||
book.title = to_save["book_title"]
|
book.title = to_save["book_title"]
|
||||||
|
Loading…
Reference in New Issue
Block a user