diff --git a/cps/render_template.py b/cps/render_template.py index 68b46459..5b5408b7 100644 --- a/cps/render_template.py +++ b/cps/render_template.py @@ -22,7 +22,7 @@ from werkzeug.local import LocalProxy from flask_login import current_user from sqlalchemy.sql.expression import or_ -from . import config, constants, logger, ub +from . import config, constants, logger, ub, db, calibre_db from .ub import User @@ -106,6 +106,13 @@ def get_sidebar_config(kwargs=None): return sidebar, simple +def get_category(categoryId=0): + categories = calibre_db.session.query(db.Tags)\ + .order_by(db.Tags.name) + for category in categories: + if category.id == categoryId: + return category + return { 'name': '' } # Returns the template for rendering and includes the instance name def render_title_template(*args, **kwargs): @@ -113,6 +120,7 @@ def render_title_template(*args, **kwargs): try: return render_template(instance=config.config_calibre_web_title, sidebar=sidebar, simple=simple, accept=constants.EXTENSIONS_UPLOAD, + get_category=get_category, *args, **kwargs) except PermissionError: log.error("No permission to access {} file.".format(args[0])) diff --git a/cps/shelf.py b/cps/shelf.py index 9d969322..f6277990 100644 --- a/cps/shelf.py +++ b/cps/shelf.py @@ -324,6 +324,8 @@ def create_edit_shelf(shelf, page_title, page, shelf_id=False): flash(_("Sorry you are not allowed to create a public shelf"), category="error") return redirect(url_for('web.index')) is_public = 1 if to_save.get("is_public") == "on" else 0 + type = to_save.get("type", "") + category = to_save.get("category", "") if config.config_kobo_sync: shelf.kobo_sync = True if to_save.get("kobo_sync") else False if shelf.kobo_sync: @@ -334,6 +336,8 @@ def create_edit_shelf(shelf, page_title, page, shelf_id=False): if check_shelf_is_unique(shelf_title, is_public, shelf_id): shelf.name = shelf_title shelf.is_public = is_public + shelf.type = type + shelf.category = category if not shelf_id: shelf.user_id = int(current_user.id) ub.session.add(shelf) @@ -356,8 +360,11 @@ def create_edit_shelf(shelf, page_title, page, shelf_id=False): ub.session.rollback() log.error_or_exception(ex) flash(_("There was an error"), category="error") + categories = calibre_db.session.query(db.Tags)\ + .order_by(db.Tags.name) return render_title_template('shelf_edit.html', shelf=shelf, + categories=categories, title=page_title, page=page, kobo_sync_enabled=config.config_kobo_sync, diff --git a/cps/templates/layout.html b/cps/templates/layout.html index 1bee1c1d..d7f790be 100644 --- a/cps/templates/layout.html +++ b/cps/templates/layout.html @@ -151,7 +151,17 @@ {% if current_user.is_authenticated or g.allow_anonymous %}
{% for shelf in g.shelves_access %} -