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 @@