Checking and warrying on possible duplicity

This commit is contained in:
Jan Guzej 2019-10-26 11:54:27 +02:00
parent 5167ee520e
commit fadd085b57
3 changed files with 21 additions and 0 deletions

View File

@ -567,6 +567,12 @@ def upload():
filepath = os.path.join(config.config_calibre_dir, author_dir, title_dir)
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
if not os.path.exists(filepath):
try:

View File

@ -780,7 +780,17 @@ def get_download_link(book_id, book_format):
else:
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

View File

@ -99,6 +99,11 @@
<div id="flash_info" class="alert alert-info">{{ message[1] }}</div>
</div>
{%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" %}
<div class="row-fluid text-center" style="margin-top: -20px;">
<div id="flash_success" class="alert alert-success">{{ message[1] }}</div>