Skip to content

Commit

Permalink
fix deprecated before_app_first_request
Browse files Browse the repository at this point in the history
  • Loading branch information
martinobersteiner committed Jun 11, 2024
1 parent 99705d7 commit 20bdff0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
21 changes: 21 additions & 0 deletions invenio_config_tugraz/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# details.

"""invenio module that adds tugraz configs."""

from . import config


Expand All @@ -28,3 +29,23 @@ def init_config(self, app):
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)})
17 changes: 1 addition & 16 deletions invenio_config_tugraz/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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


Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 20bdff0

Please sign in to comment.