From a89692796b54b14c6b60fbd606a283be30ce9d13 Mon Sep 17 00:00:00 2001 From: Christoph Ladurner Date: Thu, 29 Jun 2023 23:34:29 +0200 Subject: [PATCH 1/9] global: remove breadcrumbs * breadcrumbs are not longer used in invenio --- docs/conf.py | 1 - invenio_theme/__init__.py | 38 ++++--------------------------------- invenio_theme/config.py | 3 --- invenio_theme/ext.py | 9 +-------- setup.cfg | 3 +-- tests/test_invenio_theme.py | 1 - 6 files changed, 6 insertions(+), 49 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index f76e5ffe..a179fe70 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -319,7 +319,6 @@ "https://docs.python.org/": None, "flask": ("http://flask.pocoo.org/docs/latest/", None), "flask_menu": ("https://flask-menu.readthedocs.io/en/latest/", None), - "flask_breadcrumbs": ("https://flask-breadcrumbs.readthedocs.io/en/latest/", None), "invenio_assets": ("https://invenio-assets.readthedocs.io/en/latest/", None), } diff --git a/invenio_theme/__init__.py b/invenio_theme/__init__.py index 14f140d3..ce101d62 100644 --- a/invenio_theme/__init__.py +++ b/invenio_theme/__init__.py @@ -15,9 +15,9 @@ `_ HTML, CSS and JS framework. - `Error handlers` - for showing user-friendly 401, 402, 404, and 500 error pages. -- `Menu and breadcrumbs` - for basic site navigation using `Flask-Menu - `_ and `Flask-Breadcrumbs - `_. +- `Menu` - for basic site navigation using `Flask-Menu + `_ + Initialization @@ -152,7 +152,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~ The header template (``invenio_theme/header.html``) is reponsible for rendering the navigation bar (including logo, search bar, menu and login/sign up -buttons), flash messages and the breadcrumbs. +buttons) and flash messages Change the template by updating :data:`invenio_theme.config.THEME_HEADER_TEMPLATE`. @@ -166,8 +166,6 @@ * ``flashmessages`` - Displays small notification messages such as "Successfully logged in." -* ``breadcrumbs`` - Displays the breadcrumbs. - Header login section template ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The header login template (``invenio_theme/header_login.html``) is responsible @@ -441,33 +439,6 @@ def init_config(app): To read more about the creation and usage of menus, see :mod:`~flask_menu`. -Breadcrumbs -~~~~~~~~~~~ -Breadcrumbs works similar to menus, just use the -:func:`~flask_breadcrumbs.register_breadcrumb` instead. - ->>> from flask_breadcrumbs import register_breadcrumb - -Using this decorator, you can specify the position of the view in a -hierarchical manner, as well as the title in the breadcrumb. By default, the -current breadcrumb is displayed inside the ``page_header`` block in the base -template. - ->>> @app.route('/part1') -... @register_breadcrumb(app, '.', 'Index') -... def part1(): -... return "" ->>> @app.route('/part2') -... @register_breadcrumb(app, '.p2', 'Part 2') -... def part2(): -... return "" ->>> @app.route('/part3') -... @register_breadcrumb(app, '.p2.p3', 'Part 3') -... def part3(): -... return "" - -To learn more about the usage of breadcrumbs, see :mod:`~flask_breadcrumbs`. - User settings ~~~~~~~~~~~~~ If your module allows your users to configure some settings, you can provide @@ -489,7 +460,6 @@ def init_config(app): .. code-block:: python @app.route('/settings/') - @register_breadcrumb(app, '.settings', 'Settings page') @register_menu(app, 'settings.item1', 'Item 1', order=2) def settings_item_1(): return render_template('invenio_foo/foo_settings.html') diff --git a/invenio_theme/config.py b/invenio_theme/config.py index 4e6a08e4..e32e40b5 100644 --- a/invenio_theme/config.py +++ b/invenio_theme/config.py @@ -112,9 +112,6 @@ THEME_SEARCH_ENDPOINT = "/search" """The endpoint for the search bar.""" -THEME_BREADCRUMB_ROOT_ENDPOINT = "" -"""The endpoint for the Home view in the breadcrumbs.""" - THEME_SITENAME = _("Invenio") """The name of the site to be used on the header and as a title.""" diff --git a/invenio_theme/ext.py b/invenio_theme/ext.py index 747ce670..3c5ff564 100644 --- a/invenio_theme/ext.py +++ b/invenio_theme/ext.py @@ -2,7 +2,7 @@ # # This file is part of Invenio. # Copyright (C) 2015-2018 CERN. -# Copyright (C) 2022 Graz University of Technology. +# Copyright (C) 2022-2023 Graz University of Technology. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -10,7 +10,6 @@ """Invenio standard theme.""" from flask import Blueprint -from flask_breadcrumbs import Breadcrumbs from flask_menu import Menu from invenio_i18n import lazy_gettext as _ @@ -36,7 +35,6 @@ def __init__(self, app=None, **kwargs): """ self.menu_ext = Menu() self.menu = None - self.breadcrumbs = Breadcrumbs() if app: self.init_app(app, **kwargs) @@ -51,7 +49,6 @@ def init_app(self, app, **kwargs): # Initialize extensions self.menu_ext.init_app(app) self.menu = app.extensions["menu"] - self.breadcrumbs.init_app(app) # Register blueprint in order to register template and static folder. app.register_blueprint( @@ -67,10 +64,6 @@ def init_app(self, app, **kwargs): if app.config["THEME_FRONTPAGE"]: app.register_blueprint(blueprint) - # Initialize breadcrumbs. - item = self.menu.submenu("breadcrumbs") - item.register(app.config["THEME_BREADCRUMB_ROOT_ENDPOINT"], _("Home")) - # Register errors handlers. app.register_error_handler(401, unauthorized) app.register_error_handler(403, insufficient_permissions) diff --git a/setup.cfg b/setup.cfg index 6bc0442f..b2e4bb72 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,7 +2,7 @@ # # This file is part of Invenio. # Copyright (C) 2015-2024 CERN. -# Copyright (C) 2022 Graz University of Technology. +# Copyright (C) 2022-2024 Graz University of Technology. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -27,7 +27,6 @@ packages = find: python_requires = >=3.7 zip_safe = False install_requires = - Flask-Breadcrumbs>=0.4.0 Flask-Menu>=0.5.0,<1.0.0 invenio-assets>=1.2.7 invenio-base>=1.2.5 diff --git a/tests/test_invenio_theme.py b/tests/test_invenio_theme.py index 80bbe973..fe6a1eeb 100644 --- a/tests/test_invenio_theme.py +++ b/tests/test_invenio_theme.py @@ -143,7 +143,6 @@ def test_header_template_blocks(app): "brand", "navbar_inner", "navbar_right", - "breadcrumbs", "flashmessages", "navbar_nav", "navbar_search", From b740de45a99a2cf15861554cf6d01ecb7ed7c20f Mon Sep 17 00:00:00 2001 From: Christoph Ladurner Date: Sun, 11 Jun 2023 23:09:24 +0200 Subject: [PATCH 2/9] global: introduce shared menu * the main point of using a shared menu is to have the menu outside of the application context --- invenio_theme/__init__.py | 3 ++- invenio_theme/ext.py | 14 ++++---------- invenio_theme/shared.py | 13 +++++++++++++ .../templates/invenio_theme/admin_header.html | 5 +++-- invenio_theme/templates/invenio_theme/header.html | 3 ++- .../templates/invenio_theme/header_login.html | 3 ++- .../templates/invenio_theme/page_settings.html | 3 ++- .../semantic-ui/invenio_theme/admin_header.html | 5 +++-- .../semantic-ui/invenio_theme/header.html | 3 ++- .../semantic-ui/invenio_theme/header_login.html | 3 ++- .../semantic-ui/invenio_theme/page_settings.html | 3 ++- tests/test_invenio_theme.py | 5 +---- 12 files changed, 38 insertions(+), 25 deletions(-) create mode 100644 invenio_theme/shared.py diff --git a/invenio_theme/__init__.py b/invenio_theme/__init__.py index ce101d62..bd6ecc52 100644 --- a/invenio_theme/__init__.py +++ b/invenio_theme/__init__.py @@ -490,7 +490,8 @@ def settings_item_1(): """ from .ext import InvenioTheme +from .shared import menu __version__ = "2.5.10" -__all__ = ("__version__", "InvenioTheme") +__all__ = ("__version__", "InvenioTheme", "menu") diff --git a/invenio_theme/ext.py b/invenio_theme/ext.py index 3c5ff564..4dfccc71 100644 --- a/invenio_theme/ext.py +++ b/invenio_theme/ext.py @@ -10,10 +10,9 @@ """Invenio standard theme.""" from flask import Blueprint -from flask_menu import Menu -from invenio_i18n import lazy_gettext as _ from . import config +from .shared import menu from .views import ( blueprint, insufficient_permissions, @@ -33,9 +32,6 @@ def __init__(self, app=None, **kwargs): :param app: An instance of :class:`~flask.Flask`. :param \**kwargs: Keyword arguments are passed to ``init_app`` method. """ - self.menu_ext = Menu() - self.menu = None - if app: self.init_app(app, **kwargs) @@ -46,10 +42,6 @@ def init_app(self, app, **kwargs): """ self.init_config(app) - # Initialize extensions - self.menu_ext.init_app(app) - self.menu = app.extensions["menu"] - # Register blueprint in order to register template and static folder. app.register_blueprint( Blueprint( @@ -78,6 +70,8 @@ def _theme_icon_ctx_processor(): return dict(current_theme_icons=current_theme_icons) + app.context_processor(lambda: {"menu": menu}) + # Save reference to self on object app.extensions["invenio-theme"] = self @@ -95,7 +89,7 @@ def init_config(self, app): # Set THEME__TEMPLATE from _TEMPLATE variables if not # already set. for varname in _vars: - theme_varname = "THEME_{}".format(varname) + theme_varname = "THEME{}".format(varname) if app.config[theme_varname] is None: app.config[theme_varname] = app.config[varname] diff --git a/invenio_theme/shared.py b/invenio_theme/shared.py new file mode 100644 index 00000000..2ee7ef67 --- /dev/null +++ b/invenio_theme/shared.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# +# This file is part of Invenio. +# Copyright (C) 2023 Graz University of Technology. +# +# Invenio is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Invenio standard theme.""" + +from flask_menu.menu import MenuRoot + +menu = MenuRoot("", None) diff --git a/invenio_theme/templates/invenio_theme/admin_header.html b/invenio_theme/templates/invenio_theme/admin_header.html index dcc1c5bc..1e9138da 100644 --- a/invenio_theme/templates/invenio_theme/admin_header.html +++ b/invenio_theme/templates/invenio_theme/admin_header.html @@ -2,6 +2,7 @@ This file is part of Invenio. Copyright (C) 2015-2018 CERN. + Copyright (C) 2023 Graz University of Technology. Invenio is free software; you can redistribute it and/or modify it under the terms of the MIT License; see LICENSE file for more details. @@ -20,7 +21,7 @@