Skip to content

Commit d153563

Browse files
Merge branch 'main' into fk-delete-cascade
2 parents d43e63c + 3f55f12 commit d153563

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

cps/render_template.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# SPDX-License-Identifier: GPL-3.0-or-later
66
# See CONTRIBUTORS for full list of authors.
77

8-
from flask import render_template, g, abort, request, flash
8+
from flask import render_template, g, abort, request, flash, current_app
99
from flask_babel import gettext as _
1010
from flask_babel import get_locale
1111
import polib
@@ -224,6 +224,13 @@ def translations_missing_notification() -> None:
224224
# Returns the template for rendering and includes the instance name
225225
def render_title_template(*args, **kwargs):
226226
sidebar, simple = get_sidebar_config(kwargs)
227+
try:
228+
magic_shelf_routes = {
229+
"render": 'web.render_magic_shelf' in current_app.view_functions,
230+
"create": 'web.create_magic_shelf' in current_app.view_functions,
231+
}
232+
except Exception:
233+
magic_shelf_routes = {"render": False, "create": False}
227234
if current_user.role_admin():
228235
try:
229236
cwa_update_notification()
@@ -241,8 +248,9 @@ def render_title_template(*args, **kwargs):
241248
print(f"[translation-notification-service] The following error occurred when checking for missing translations:\n{e}", flush=True)
242249
try:
243250
return render_template(instance=config.config_calibre_web_title, sidebar=sidebar, simple=simple,
244-
accept=config.config_upload_formats.split(','),
245-
*args, **kwargs)
251+
accept=config.config_upload_formats.split(','),
252+
magic_shelf_routes=magic_shelf_routes,
253+
*args, **kwargs)
246254
except PermissionError:
247255
log.error("No permission to access {} file.".format(args[0]))
248256
abort(403)

cps/templates/layout.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,14 @@ <h3>{{_('Uploading...')}}</h3>
301301
<li id="nav_createshelf" class="create-shelf"><a href="{{url_for('shelf.create_shelf')}}">{{_('Create Shelf')}}</a></li>
302302
{% endif %}
303303
{% endif %}
304-
{% if current_user.is_authenticated %}
304+
{% if current_user.is_authenticated and magic_shelf_routes.render %}
305305
<li class="nav-head hidden-xs" style="margin-top: 1rem;">{{_('Magic Shelves ✨')}}</li>
306306
{% for shelf in g.magic_shelves_access %}
307307
<li><a href="{{url_for('web.render_magic_shelf', shelf_id=shelf.id)}}" title="{{shelf.name}} ({{shelf.book_count}})"><span style="font-size: 14px;">{{shelf.icon}}</span> {{shelf.name|shortentitle(40)}}{% if shelf.is_public == 1 %} {{_('(Public)')}}{% endif %} <span style="font-size: 80%; color: #888;">({{shelf.book_count}})</span></a></li>
308308
{% endfor %}
309-
<li id="nav_createmagicshelf" class="create-shelf"><a href="{{url_for('web.create_magic_shelf')}}" style="display: flex; align-items: center;">{{_('Create Magic Shelf')}}</a></li>
309+
{% if magic_shelf_routes.create %}
310+
<li id="nav_createmagicshelf" class="create-shelf"><a href="{{url_for('web.create_magic_shelf')}}" style="display: flex; align-items: center;">{{_('Create Magic Shelf')}}</a></li>
311+
{% endif %}
310312
{% endif %}
311313
{% if not current_user.is_anonymous %}
312314
<li id="nav_about" {% if page == 'stat' %}class="active"{% endif %}><a href="{{url_for('about.stats')}}"><span class="glyphicon glyphicon-info-sign"></span> {{_('About')}}</a></li>

0 commit comments

Comments
 (0)