From fadd085b57100e53ed3eba13c998912b1b260037 Mon Sep 17 00:00:00 2001 From: Jan Guzej Date: Sat, 26 Oct 2019 11:54:27 +0200 Subject: [PATCH 1/2] Checking and warrying on possible duplicity --- cps/editbooks.py | 6 ++++++ cps/helper.py | 10 ++++++++++ cps/templates/layout.html | 5 +++++ 3 files changed, 21 insertions(+) diff --git a/cps/editbooks.py b/cps/editbooks.py index 2da9991f..f8431725 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -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: diff --git a/cps/helper.py b/cps/helper.py index b45300c0..81addeb8 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -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 diff --git a/cps/templates/layout.html b/cps/templates/layout.html index 72eba890..9ffb04f8 100644 --- a/cps/templates/layout.html +++ b/cps/templates/layout.html @@ -99,6 +99,11 @@
{{ message[1] }}
{%endif%} + {%if message[0] == "warning" %} +
+
{{ message[1] }}
+
+ {%endif%} {%if message[0] == "success" %}
{{ message[1] }}
From 94ae9937f0fdef4b6c253af177d30c8442c4e6f6 Mon Sep 17 00:00:00 2001 From: Jan Guzej Date: Sat, 26 Oct 2019 13:45:06 +0200 Subject: [PATCH 2/2] Add flash show book template --- cps/templates/book_exists_flash.html | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 cps/templates/book_exists_flash.html diff --git a/cps/templates/book_exists_flash.html b/cps/templates/book_exists_flash.html new file mode 100644 index 00000000..b0855120 --- /dev/null +++ b/cps/templates/book_exists_flash.html @@ -0,0 +1,3 @@ + + {{entry.title|shortentitle}} + \ No newline at end of file