From 923d4e8120ec576ec405a0fa7f0316eaa110d429 Mon Sep 17 00:00:00 2001 From: Martin Obersteiner Date: Mon, 10 Jun 2024 14:23:06 +0200 Subject: [PATCH] fix deprecated `before_app_first_request` --- invenio_theme_tugraz/ext.py | 24 ++++++++++++++++++++++++ invenio_theme_tugraz/views.py | 22 ---------------------- setup.cfg | 2 ++ 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/invenio_theme_tugraz/ext.py b/invenio_theme_tugraz/ext.py index 3485ca1..4746bac 100644 --- a/invenio_theme_tugraz/ext.py +++ b/invenio_theme_tugraz/ext.py @@ -8,6 +8,7 @@ """invenio module for TUGRAZ theme.""" +from invenio_i18n import lazy_gettext as _ from invenio_records_marc21.ui.theme import current_identity_can_view from . import config @@ -42,3 +43,26 @@ def init_config(self, app): for k in dir(config): if k.startswith("INVENIO_THEME_TUGRAZ_") or k.startswith("THEME_TUGRAZ_"): app.config.setdefault(k, getattr(config, k)) + + +def finalize_app(app): + """Finalize app.""" + modify_user_dashboard(app) + + +def modify_user_dashboard(app): + """Modify user dashboard.""" + root_menu = app.extensions["menu"].root_node + + user_dashboard_menu = root_menu.submenu("dashboard") + user_dashboard_menu.submenu("overview").register( + "invenio_theme_tugraz.overview", + text=_("Overview"), + order=0, + ) + + root_menu.submenu("actions.deposit").register( + "invenio_theme_tugraz.overview", + _("My dashboard"), + order=1, + ) diff --git a/invenio_theme_tugraz/views.py b/invenio_theme_tugraz/views.py index 1564185..1f37496 100644 --- a/invenio_theme_tugraz/views.py +++ b/invenio_theme_tugraz/views.py @@ -12,10 +12,6 @@ from flask import Blueprint, g, render_template from flask_login import current_user, login_required -from flask_menu import current_menu -from invenio_i18n import lazy_gettext as _ - -# from invenio_rdm_records.resources.serializers import UIJSONSerializer from invenio_records_global_search.resources.serializers import ( GlobalSearchJSONSerializer, ) @@ -60,24 +56,6 @@ def cast_to_dict(attr_dict): return AttrDict.to_dict(attr_dict) -@blueprint.before_app_first_request -def modify_user_dashboard(): - """Modify user dashboard.""" - user_dashboard_menu = current_menu.submenu("dashboard") - - user_dashboard_menu.submenu("overview").register( - "invenio_theme_tugraz.overview", - text=_("Overview"), - order=0, - ) - - current_menu.submenu("actions.deposit").register( - "invenio_theme_tugraz.overview", - _("My dashboard"), - order=1, - ) - - def ui_blueprint(app): """Blueprint for the routes and resources provided by Invenio-theme-tugraz.""" routes = app.config.get("TUG_ROUTES") diff --git a/setup.cfg b/setup.cfg index 2ed96d2..6173435 100644 --- a/setup.cfg +++ b/setup.cfg @@ -62,6 +62,8 @@ invenio_assets.webpack = invenio_theme_tugraz_theme = invenio_theme_tugraz.webpack:theme invenio_config.module = invenio_theme_tugraz = invenio_theme_tugraz.config +invenio_base.finalize_app = + invenio_theme_tugraz = invenio_theme_tugraz.ext:finalize_app [aliases] test = pytest