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 %} -
  • {{shelf.name|shortentitle(40)}}{% if shelf.is_public == 1 %} {{_('(Public)')}}{% endif %}
  • + {% if shelf.type == 0 %} +
  • {{shelf.name|shortentitle(40)}}{% if shelf.is_public == 1 %} {{_('(Public)')}}{% endif %}
  • + {% else %} +
  • + {{get_category(shelf.category).name|shortentitle(40)}} + {% if shelf.is_public == 1 %} {{_('(Public)')}}{% endif %} + {% if not current_user.is_anonymous %} + (Shelf) + {% endif %} +
  • + {% endif %} {% endfor %} {% if not current_user.is_anonymous %} diff --git a/cps/templates/shelf_edit.html b/cps/templates/shelf_edit.html index 58521e3d..29fa79ee 100644 --- a/cps/templates/shelf_edit.html +++ b/cps/templates/shelf_edit.html @@ -1,4 +1,8 @@ {% extends "layout.html" %} +{% block header %} + +{% endblock %} + {% block body %}

    {{title}}

    @@ -14,6 +18,24 @@ {{_('Share with Everyone')}}
    +
    + + +
    +
    + + +
    {% endif %} {% if kobo_sync_enabled and sync_only_selected_shelves %}
    @@ -29,3 +51,10 @@
    {% endblock %} + +{% block js %} + +{% if not current_user.locale == 'en' %} + +{% endif %} +{% endblock %} diff --git a/cps/ub.py b/cps/ub.py index 3e478f99..32796dff 100644 --- a/cps/ub.py +++ b/cps/ub.py @@ -337,6 +337,8 @@ class Shelf(Base): uuid = Column(String, default=lambda: str(uuid.uuid4())) name = Column(String) is_public = Column(Integer, default=0) + type = Column(Integer, default=0) + category = Column(Integer, default=0) user_id = Column(Integer, ForeignKey('user.id')) kobo_sync = Column(Boolean, default=False) books = relationship("BookShelf", backref="ub_shelf", cascade="all, delete-orphan", lazy="dynamic") @@ -630,7 +632,20 @@ def migrate_shelfs(engine, _session): trans = conn.begin() conn.execute(text("ALTER TABLE book_shelf_link ADD column 'order' INTEGER DEFAULT 1")) trans.commit() - + try: + _session.query(exists().where(Shelf.type)).scalar() + except exc.OperationalError: # Database is not compatible, some columns are missing + with engine.connect() as conn: + trans = conn.begin() + conn.execute(text("ALTER TABLE shelf ADD column 'type' INTEGER DEFAULT 0")) + trans.commit() + try: + _session.query(exists().where(Shelf.category)).scalar() + except exc.OperationalError: # Database is not compatible, some columns are missing + with engine.connect() as conn: + trans = conn.begin() + conn.execute(text("ALTER TABLE shelf ADD column 'category' INTEGER DEFAULT 0")) + trans.commit() def migrate_readBook(engine, _session): try: