From d77b52af9631ca9f5727097126940932420e8c16 Mon Sep 17 00:00:00 2001 From: Niktia Pchelin Date: Sun, 16 Feb 2020 22:24:00 -0500 Subject: [PATCH 1/3] #645 - displays '(public)' next to public shelves created by the user --- cps/templates/layout.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cps/templates/layout.html b/cps/templates/layout.html index 9ffb04f8..84785205 100644 --- a/cps/templates/layout.html +++ b/cps/templates/layout.html @@ -140,7 +140,7 @@ {% endfor %} {% for shelf in g.user.shelf %} -
  • {{shelf.name|shortentitle(40)}}
  • +
  • {{shelf.name|shortentitle(40)}}{% if shelf.is_public == 1 %} (public){% endif %}
  • {% endfor %} {% if not g.user.is_anonymous %} From 7c0d10da796737f9c1f829c89914ff93b1a92e94 Mon Sep 17 00:00:00 2001 From: Niktia Pchelin Date: Sun, 16 Feb 2020 22:47:32 -0500 Subject: [PATCH 2/3] #645 - displays '(public)' next to user's public shelves in OPDS feed --- cps/templates/feed.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cps/templates/feed.xml b/cps/templates/feed.xml index 37b7765e..089ca65b 100644 --- a/cps/templates/feed.xml +++ b/cps/templates/feed.xml @@ -75,7 +75,11 @@ {% endif %} {% for entry in listelements %} + {% if entry.__class__.__name__ == 'Shelf' and entry.is_public == 1 %} + {{entry.name}} (public) + {% else %} {{entry.name}} + {% endif %} {{ url_for(folder, book_id=entry.id) }} From dac48a26108bf38d823f364969902db53095e691 Mon Sep 17 00:00:00 2001 From: Niktia Pchelin Date: Sun, 16 Feb 2020 23:38:35 -0500 Subject: [PATCH 3/3] #645 - changes create_shelf and edit_shelf to allow user create public and private shelves with the same name --- cps/shelf.py | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/cps/shelf.py b/cps/shelf.py index 6e8c4b9f..2a8d7c43 100644 --- a/cps/shelf.py +++ b/cps/shelf.py @@ -204,12 +204,24 @@ 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( - 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") + + is_shelf_name_unique = False + if shelf.is_public == 1: + is_shelf_name_unique = ub.session.query(ub.Shelf) \ + .filter((ub.Shelf.name == to_save["title"]) & (ub.Shelf.is_public == 1)) \ + .first() is None + + if not is_shelf_name_unique: + flash(_(u"A public shelf with the name '%(title)s' already exists.", title=to_save["title"]), category="error") else: + is_shelf_name_unique = ub.session.query(ub.Shelf) \ + .filter((ub.Shelf.name == to_save["title"]) & (ub.Shelf.is_public == 0) & (ub.Shelf.user_id == int(current_user.id))) \ + .first() is None + + if not is_shelf_name_unique: + flash(_(u"A private shelf with the name '%(title)s' already exists.", title=to_save["title"]), category="error") + + if is_shelf_name_unique: try: ub.session.add(shelf) ub.session.commit() @@ -227,13 +239,26 @@ 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( - 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") + + is_shelf_name_unique = False + if shelf.is_public == 1: + is_shelf_name_unique = ub.session.query(ub.Shelf) \ + .filter((ub.Shelf.name == to_save["title"]) & (ub.Shelf.is_public == 1)) \ + .filter(ub.Shelf.id != shelf_id) \ + .first() is None + + if not is_shelf_name_unique: + flash(_(u"A public shelf with the name '%(title)s' already exists.", title=to_save["title"]), category="error") else: + is_shelf_name_unique = ub.session.query(ub.Shelf) \ + .filter((ub.Shelf.name == to_save["title"]) & (ub.Shelf.is_public == 0) & (ub.Shelf.user_id == int(current_user.id))) \ + .filter(ub.Shelf.id != shelf_id) \ + .first() is None + + if not is_shelf_name_unique: + flash(_(u"A private shelf with the name '%(title)s' already exists.", title=to_save["title"]), category="error") + + if is_shelf_name_unique: shelf.name = to_save["title"] if "is_public" in to_save: shelf.is_public = 1