mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-19 08:14:53 +00:00
Checking and warrying on possible duplicity
This commit is contained in:
parent
5167ee520e
commit
fadd085b57
@ -567,6 +567,12 @@ def upload():
|
|||||||
filepath = os.path.join(config.config_calibre_dir, author_dir, title_dir)
|
filepath = os.path.join(config.config_calibre_dir, author_dir, title_dir)
|
||||||
saved_filename = os.path.join(filepath, title_dir + meta.extension.lower())
|
saved_filename = os.path.join(filepath, title_dir + meta.extension.lower())
|
||||||
|
|
||||||
|
if unicode(title) != u'Unknown' and unicode(authr) != u'Unknown':
|
||||||
|
entry = helper.check_exists_book(authr, title)
|
||||||
|
if entry:
|
||||||
|
book_html = flash(_(u"Uploaded book probably exists in the library, consider to change before upload new: ")
|
||||||
|
+ Markup(render_title_template('book_exists_flash.html', entry=entry)), category="warning")
|
||||||
|
|
||||||
# check if file path exists, otherwise create it, copy file to calibre path and delete temp file
|
# check if file path exists, otherwise create it, copy file to calibre path and delete temp file
|
||||||
if not os.path.exists(filepath):
|
if not os.path.exists(filepath):
|
||||||
try:
|
try:
|
||||||
|
@ -780,7 +780,17 @@ def get_download_link(book_id, book_format):
|
|||||||
else:
|
else:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
|
def check_exists_book(authr,title):
|
||||||
|
db.session.connection().connection.connection.create_function("lower", 1, lcase)
|
||||||
|
q = list()
|
||||||
|
authorterms = re.split(r'\s*&\s*', authr)
|
||||||
|
for authorterm in authorterms:
|
||||||
|
q.append(db.Books.authors.any(func.lower(db.Authors.name).ilike("%" + authorterm + "%")))
|
||||||
|
|
||||||
|
return db.session.query(db.Books).filter(
|
||||||
|
and_(db.Books.authors.any(and_(*q)),
|
||||||
|
func.lower(db.Books.title).ilike("%" + title + "%")
|
||||||
|
)).first()
|
||||||
|
|
||||||
############### Database Helper functions
|
############### Database Helper functions
|
||||||
|
|
||||||
|
@ -99,6 +99,11 @@
|
|||||||
<div id="flash_info" class="alert alert-info">{{ message[1] }}</div>
|
<div id="flash_info" class="alert alert-info">{{ message[1] }}</div>
|
||||||
</div>
|
</div>
|
||||||
{%endif%}
|
{%endif%}
|
||||||
|
{%if message[0] == "warning" %}
|
||||||
|
<div class="row-fluid text-center" style="margin-top: -20px;">
|
||||||
|
<div id="flash_warning" class="alert alert-warning">{{ message[1] }}</div>
|
||||||
|
</div>
|
||||||
|
{%endif%}
|
||||||
{%if message[0] == "success" %}
|
{%if message[0] == "success" %}
|
||||||
<div class="row-fluid text-center" style="margin-top: -20px;">
|
<div class="row-fluid text-center" style="margin-top: -20px;">
|
||||||
<div id="flash_success" class="alert alert-success">{{ message[1] }}</div>
|
<div id="flash_success" class="alert alert-success">{{ message[1] }}</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user