fix deprecated before_app_first_request

This commit is contained in:
Martin Obersteiner
2024-06-10 14:25:37 +02:00
committed by martinobersteiner
parent 99705d7a25
commit 20bdff0b79
3 changed files with 24 additions and 16 deletions

View File

@@ -7,6 +7,7 @@
# details.
"""invenio module that adds tugraz configs."""
from . import config
@@ -28,3 +29,23 @@ class InvenioConfigTugraz(object):
for k in dir(config):
if k.startswith("INVENIO_CONFIG_TUGRAZ_"):
app.config.setdefault(k, getattr(config, k))
def finalize_app(app):
"""Finalize app."""
rank_blueprint_higher(app)
def rank_blueprint_higher(app):
"""Rank this module's blueprint higher than blueprint of security module.
Needed in order to overwrite email templates.
Since the blueprints are in a dict and the order of insertion is
retained, popping and reinserting all items (except ours), ensures
our blueprint will be in front.
"""
bps = app.blueprints
for blueprint_name in list(bps.keys()):
if blueprint_name != "invenio_config_tugraz":
bps.update({blueprint_name: bps.pop(blueprint_name)})

View File

@@ -8,7 +8,7 @@
"""invenio module for TUGRAZ config."""
from flask import Blueprint, current_app, redirect, url_for
from flask import Blueprint, redirect, url_for
from invenio_i18n import get_locale
@@ -27,21 +27,6 @@ def ui_blueprint(app):
blueprint.add_url_rule(routes["terms"], view_func=terms)
blueprint.add_url_rule(routes["gdpr"], view_func=gdpr)
@blueprint.before_app_first_request
def rank_higher():
"""Rank this modules blueprint higher than blueprint of security module.
Needed in order to overwrite email templates.
Since the blueprints are in a dict and the order of insertion is
retained, popping and reinserting all items (except ours), ensures
our blueprint will be in front.
"""
bps = current_app.blueprints
for blueprint_name in list(bps.keys()):
if blueprint_name != "invenio_config_tugraz":
bps.update({blueprint_name: bps.pop(blueprint_name)})
return blueprint

View File

@@ -59,6 +59,8 @@ invenio_i18n.translations =
messages = invenio_config_tugraz
invenio_config.module =
invenio_config_tugraz = invenio_config_tugraz.config
invenio_base.finalize_app =
invenio_config_tugraz = invenio_config_tugraz.ext:finalize_app
[aliases]
test = pytest