Skip to content

Commit

Permalink
views: replace deprecated before_app_first_request
Browse files Browse the repository at this point in the history
* replaced by init_functions entry point
* closes inveniosoftware/invenio-base#171
  • Loading branch information
jrcastro2 committed Jan 13, 2023
1 parent 628595c commit 76b271d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 6 additions & 8 deletions invenio_pages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@
)


@blueprint.before_app_first_request
def register_pages():
def register_pages(app):
"""Register URL rule of all static pages to the application."""
# We need to set the function view, to be able to directly register the urls in the Flask.url_map
current_app.view_functions["invenio_pages.view"] = view

app.view_functions["invenio_pages.view"] = view
for page in Page.query.all():
_add_url_rule(page.url)
_add_url_rule(page.url, app=app)


@blueprint.app_template_filter("render_string")
Expand Down Expand Up @@ -103,13 +101,13 @@ def handle_not_found(exception, **extra):
return exception


def _add_url_rule(url):
def _add_url_rule(url, app=current_app):
"""Register URL rule to application URL map."""
rule = current_app.url_rule_class(
rule = app.url_rule_class(
url,
endpoint="invenio_pages.view",
methods=["GET", "HEAD", "OPTIONS"],
strict_slashes=True,
merge_slashes=True,
)
current_app.url_map.add(rule)
app.url_map.add(rule)
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ invenio_base.blueprints =
invenio_pages = invenio_pages.views:blueprint
invenio_base.api_blueprints =
invenio_pages_rest = invenio_pages.rest:blueprint
invenio_base.functions =
invenio_pages_rest = invenio_pages.views:register_pages
invenio_db.alembic =
invenio_pages = invenio_pages:alembic

Expand Down

0 comments on commit 76b271d

Please sign in to comment.