From 490f8ef5f274bccf0552f3e1ea00e00cb0d3eea6 Mon Sep 17 00:00:00 2001 From: OzzieIsaacs Date: Tue, 3 Jan 2017 19:29:33 +0100 Subject: [PATCH] Shelfs of diffrent users can have the same name now Removing ratings by giving a rating of zero is now possible (like in calibre) --- cps/templates/edit_book.html | 2 +- cps/web.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cps/templates/edit_book.html b/cps/templates/edit_book.html index 85e8de1a..e4bc7e0b 100644 --- a/cps/templates/edit_book.html +++ b/cps/templates/edit_book.html @@ -37,7 +37,7 @@
- +
diff --git a/cps/web.py b/cps/web.py index 07136f5f..fff84f37 100755 --- a/cps/web.py +++ b/cps/web.py @@ -1267,7 +1267,8 @@ def create_shelf(): shelf.is_public = 1 shelf.name = to_save["title"] shelf.user_id = int(current_user.id) - existing_shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.name == shelf.name).first() + existing_shelf = ub.session.query(ub.Shelf).filter(or_((ub.Shelf.name == to_save["title"])&( ub.Shelf.is_public == 1), + (ub.Shelf.name == to_save["title"])& (ub.Shelf.user_id == int(current_user.id)))).first() if existing_shelf: flash(_(u"A shelf with the name '%(title)s' already exists.", title=to_save["title"]), category="error") else: @@ -1287,8 +1288,9 @@ def edit_shelf(shelf_id): shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.id == shelf_id).first() if request.method == "POST": to_save = request.form.to_dict() - existing_shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.name == to_save["title"]).first() - if existing_shelf and existing_shelf.id != shelf_id: + existing_shelf = ub.session.query(ub.Shelf).filter(or_((ub.Shelf.name == to_save["title"])&( ub.Shelf.is_public == 1), + (ub.Shelf.name == to_save["title"])& (ub.Shelf.user_id == int(current_user.id)))).filter(ub.Shelf.id!=shelf_id).first() + if existing_shelf: flash(_(u"A shelf with the name '%(title)s' already exists.",title=to_save["title"]), category="error") else: shelf.name = to_save["title"]