1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-15 22:34:56 +00:00

Redirect shelf to category. - Sponsor: Fundación Karisma

This commit is contained in:
Byron H. 2024-02-05 22:11:52 -05:00
parent c2267b6902
commit 0be83a5517
5 changed files with 72 additions and 3 deletions

View File

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

View File

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

View File

@ -151,7 +151,17 @@
{% if current_user.is_authenticated or g.allow_anonymous %}
<li class="nav-head hidden-xs public-shelves">{{_('Shelves')}}</li>
{% for shelf in g.shelves_access %}
<li><a href="{{url_for('shelf.show_shelf', shelf_id=shelf.id)}}"><span class="glyphicon glyphicon-list shelf"></span> {{shelf.name|shortentitle(40)}}{% if shelf.is_public == 1 %} {{_('(Public)')}}{% endif %}</a></li>
{% if shelf.type == 0 %}
<li><a href="{{url_for('shelf.show_shelf', shelf_id=shelf.id)}}"><span class="glyphicon glyphicon-list shelf"></span> {{shelf.name|shortentitle(40)}}{% if shelf.is_public == 1 %} {{_('(Public)')}}{% endif %}</a></li>
{% else %}
<li><a href="{{url_for('web.books_list', data='category', sort_param='stored', book_id=shelf.category )}}"><span class="glyphicon glyphicon-list shelf"></span>
{{get_category(shelf.category).name|shortentitle(40)}}
{% if shelf.is_public == 1 %} {{_('(Public)')}}{% endif %}</a>
{% if not current_user.is_anonymous %}
<a href="{{url_for('shelf.show_shelf', shelf_id=shelf.id)}}"><span class="glyphicon glyphicon-edit shelf"></span> (Shelf)</a>
{% endif %}
</li>
{% endif %}
{% endfor %}
{% if not current_user.is_anonymous %}
<li id="nav_createshelf" class="create-shelf"><a href="{{url_for('shelf.create_shelf')}}">{{_('Create a Shelf')}}</a></li>

View File

@ -1,4 +1,8 @@
{% extends "layout.html" %}
{% block header %}
<link href="{{ url_for('static', filename='css/libs/bootstrap-select.min.css') }}" rel="stylesheet" >
{% endblock %}
{% block body %}
<div class="discover">
<h1>{{title}}</h1>
@ -14,6 +18,24 @@
<input type="checkbox" name="is_public" {% if shelf.is_public == 1 %}checked{% endif %}> {{_('Share with Everyone')}}
</label>
</div>
<div class="form-group">
<label for="type">Shelf type:</label>
<select id="type" name="type" class="selectpicker">
<option value="0"{% if shelf.type == 0 %} selected{% endif %}>Calibre web</option>
<option value="1"{% if shelf.type == 1 %} selected{% endif %}>Category shorcut</option>
</select>
</div>
<div class="form-group">
<label for="category">Category:</label>
<select id="category" name="category" class="selectpicker">
<option value="0">None</option>
{% if shelf.type == 1 %}
{% for category in categories %}
<option value="{{ category.id }}"{% if category.id == shelf.category %} selected{% endif %}>{{ category.name }}</option>
{% endfor %}
{% endif %}
</select>
</div>
{% endif %}
{% if kobo_sync_enabled and sync_only_selected_shelves %}
<div class="checkbox">
@ -29,3 +51,10 @@
</form>
</div>
{% endblock %}
{% block js %}
<script src="{{ url_for('static', filename='js/libs/bootstrap-select.min.js')}}"></script>
{% if not current_user.locale == 'en' %}
<script src="{{ url_for('static', filename='js/libs/bootstrap-select/defaults-' + current_user.locale + '.min.js') }}" charset="UTF-8"></script>
{% endif %}
{% endblock %}

View File

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