Skip to content

Commit

Permalink
menu: use current_menu
Browse files Browse the repository at this point in the history
  • Loading branch information
utnapischtim committed Mar 20, 2024
1 parent 38bbd0a commit 834236d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
18 changes: 18 additions & 0 deletions invenio_userprofiles/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

"""User profiles module for Invenio."""

from flask_menu import current_menu
from invenio_i18n import LazyString
from invenio_i18n import lazy_gettext as _
from invenio_theme.proxies import current_theme_icons

from . import config
from .api import current_userprofile
from .forms import confirm_register_form_factory, register_form_factory
Expand Down Expand Up @@ -75,6 +80,7 @@ def finalize_app(app):
NOTE: replace former @record_once decorator
"""
init_common(app)
init_menu(app)


def api_finalize_app(app):
Expand All @@ -93,3 +99,15 @@ def init_common(app):
security_ext.confirm_register_form
)
security_ext.register_form = register_form_factory(security_ext.register_form)


def init_menu(app):
"""Init menu."""
current_menu.submenu("settings.profile").register(
endpoint="invenio_userprofiles.profile",
text=_(
"%(icon)s Profile",
icon=LazyString(lambda: f'<i class="{current_theme_icons.user}"></i>'),
),
order=0,
)
16 changes: 2 additions & 14 deletions invenio_userprofiles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This file is part of Invenio.
# Copyright (C) 2015-2018 CERN.
# Copyright (C) 2022 Northwestern University.
# Copyright (C) 2023 Graz University of Technology.
# Copyright (C) 2023-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.
Expand All @@ -24,9 +24,7 @@
from flask_login import current_user, login_required
from flask_security.confirmable import send_confirmation_instructions
from invenio_db import db
from invenio_i18n import LazyString
from invenio_i18n import lazy_gettext as _
from invenio_theme import menu

from .forms import EmailProfileForm, PreferencesForm, ProfileForm, VerificationForm
from .models import UserProfileProxy
Expand All @@ -38,6 +36,7 @@ def create_blueprint(app):
"invenio_userprofiles",
__name__,
template_folder="templates",
url_prefix="/account/settings",
)

@blueprint.app_template_filter()
Expand All @@ -48,17 +47,6 @@ def userprofile(value):

blueprint.add_url_rule("/", "profile", view_func=profile, methods=["GET", "POST"])

icons = app.extensions["invenio-theme"].icons

menu.submenu("settings.profile").register(
endpoint="invenio_userprofiles.profile",
text=_(
"%(icon)s Profile",
icon=LazyString(lambda: f'<i class="{icons.user}"></i>'),
),
order=0,
)

return blueprint


Expand Down

0 comments on commit 834236d

Please sign in to comment.