diff --git a/invenio_userprofiles/ext.py b/invenio_userprofiles/ext.py
index bcad821..0eb379b 100644
--- a/invenio_userprofiles/ext.py
+++ b/invenio_userprofiles/ext.py
@@ -8,8 +8,15 @@
"""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
+from .views import blueprint
class InvenioUserProfiles(object):
@@ -64,3 +71,50 @@ def init_config(self, app):
app.config[
"SECURITY_REGISTER_USER_TEMPLATE"
] = "invenio_userprofiles/register_user.html"
+
+
+def finalize_app(app):
+ """Finalize app."""
+ init_menu(app)
+ init_ui(app)
+ init_api(app)
+
+
+def init_menu(app):
+ """Init menu."""
+ menu = app.extensions["menu"]
+ menu.submenu("settings.profile").register(
+ endpoint="invenio_userprofiles.profile",
+ text=_(
+ "%(icon)s Profile",
+ icon=LazyString(lambda: f''),
+ ),
+ )
+
+ menu.submenu("breadcrumbs.settings.profile").register(
+ endpoint="invenio_userprofiles.profile",
+ text=_("Profile"),
+ )
+
+
+def init_common(app):
+ """Post initialization."""
+ if app.config["USERPROFILES_EXTEND_SECURITY_FORMS"]:
+ security_ext = app.extensions["security"]
+ security_ext.confirm_register_form = confirm_register_form_factory(
+ security_ext.confirm_register_form
+ )
+ security_ext.register_form = register_form_factory(security_ext.register_form)
+
+
+def init_ui(app):
+ """Post initialization for UI application."""
+ init_common(app)
+
+ # Register blueprint for templates
+ app.register_blueprint(blueprint, url_prefix=app.config["USERPROFILES_PROFILE_URL"])
+
+
+def init_api(app):
+ """Post initialization for API application."""
+ init_common(app)
diff --git a/invenio_userprofiles/finalize_app.py b/invenio_userprofiles/finalize_app.py
deleted file mode 100644
index 7ae997e..0000000
--- a/invenio_userprofiles/finalize_app.py
+++ /dev/null
@@ -1,42 +0,0 @@
-# -*- 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.
-
-"""Finalize app."""
-
-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
-
-
-def finalize_app(app):
- """Finalize app."""
- init_menu()
- init_breadcrumb()
-
-
-def init_menu():
- """Init menu."""
- item = current_menu.submenu("settings.profile")
- item.register(
- "invenio_userprofiles.profile",
- _(
- "%(icon)s Profile",
- icon=LazyString(lambda: f''),
- ),
- order=0,
- )
-
-
-def init_breadcrumb():
- """Init breadcrumb."""
- item = current_menu.submenu("breadcrumbs.settings.profile")
- item.register(
- "invenio_userprofiles.profile",
- _("Profile"),
- )
diff --git a/invenio_userprofiles/views.py b/invenio_userprofiles/views.py
index 773fe1d..010933e 100644
--- a/invenio_userprofiles/views.py
+++ b/invenio_userprofiles/views.py
@@ -25,14 +25,7 @@
from invenio_db import db
from invenio_i18n import lazy_gettext as _
-from .forms import (
- EmailProfileForm,
- PreferencesForm,
- ProfileForm,
- VerificationForm,
- confirm_register_form_factory,
- register_form_factory,
-)
+from .forms import EmailProfileForm, PreferencesForm, ProfileForm, VerificationForm
from .models import UserProfileProxy
blueprint = Blueprint(
@@ -53,32 +46,6 @@
)
-def init_common(app):
- """Post initialization."""
- if app.config["USERPROFILES_EXTEND_SECURITY_FORMS"]:
- security_ext = app.extensions["security"]
- security_ext.confirm_register_form = confirm_register_form_factory(
- security_ext.confirm_register_form
- )
- security_ext.register_form = register_form_factory(security_ext.register_form)
-
-
-@blueprint_ui_init.record_once
-def init_ui(state):
- """Post initialization for UI application."""
- app = state.app
- init_common(app)
-
- # Register blueprint for templates
- app.register_blueprint(blueprint, url_prefix=app.config["USERPROFILES_PROFILE_URL"])
-
-
-@blueprint_api_init.record_once
-def init_api(state):
- """Post initialization for API application."""
- init_common(state.app)
-
-
@blueprint.app_template_filter()
def userprofile(value):
"""Retrieve user profile for a given user id."""
diff --git a/setup.cfg b/setup.cfg
index 154314a..6c51ed7 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -60,7 +60,7 @@ invenio_db.alembic =
invenio_i18n.translations =
messages = invenio_userprofiles
invenio_base.finalize_app =
- invenio_userprofiles = invenio_userprofiles.finalize_app:finalize_app
+ invenio_userprofiles = invenio_userprofiles.ext:finalize_app
[build_sphinx]
source-dir = docs/
diff --git a/tests/conftest.py b/tests/conftest.py
index 65aa48b..3871341 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -24,6 +24,7 @@
from sqlalchemy_utils.functions import create_database, database_exists, drop_database
from invenio_userprofiles import InvenioUserProfiles
+from invenio_userprofiles.ext import finalize_app
from invenio_userprofiles.views import blueprint_ui_init
@@ -106,7 +107,9 @@ def _init_userprofiles_app(app_):
@pytest.fixture
def app(base_app):
"""Flask application."""
- return _init_userprofiles_app(base_app)
+ app_ = _init_userprofiles_app(base_app)
+ finalize_app(app_)
+ return app
@pytest.fixture