Skip to content

Commit

Permalink
init: move record_once to finalize_app
Browse files Browse the repository at this point in the history
  • Loading branch information
utnapischtim committed Jul 24, 2023
1 parent 7921de5 commit 2e1e159
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 25 deletions.
39 changes: 39 additions & 0 deletions invenio_vocabularies/ext.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2020-2022 CERN.
# Copyright (C) 2023 Graz University of Technology.
#
# Invenio-Vocabularies is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
Expand Down Expand Up @@ -123,3 +124,41 @@ def init_resource(self, app):
service=self.service,
config=app.config["VOCABULARIES_RESOURCE_CONFIG"],
)


def finalize_app(app):
"""Finalize app.
NOTE: replace former @record_once decorator
"""
init(app)


def api_finalize_app(app):
"""Api Finalize app.
NOTE: replace former @record_once decorator
"""
init(app)


def init(app):
"""Init app."""
# Register services - cannot be done in extension because
# Invenio-Records-Resources might not have been initialized.
sregistry = app.extensions["invenio-records-resources"].registry
ext = app.extensions["invenio-vocabularies"]
sregistry.register(ext.affiliations_service, service_id="affiliations")
sregistry.register(ext.awards_service, service_id="awards")
sregistry.register(ext.funders_service, service_id="funders")
sregistry.register(ext.names_service, service_id="names")
sregistry.register(ext.subjects_service, service_id="subjects")
sregistry.register(ext.service, service_id="vocabularies")
# Register indexers
iregistry = app.extensions["invenio-indexer"].registry
iregistry.register(ext.affiliations_service.indexer, indexer_id="affiliations")
iregistry.register(ext.awards_service.indexer, indexer_id="awards")
iregistry.register(ext.funders_service.indexer, indexer_id="funders")
iregistry.register(ext.names_service.indexer, indexer_id="names")
iregistry.register(ext.subjects_service.indexer, indexer_id="subjects")
iregistry.register(ext.service.indexer, indexer_id="vocabularies")
25 changes: 1 addition & 24 deletions invenio_vocabularies/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2020-2022 CERN.
# Copyright (C) 2023 Graz University of Technology.
#
# Invenio-Vocabularies is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
Expand All @@ -13,30 +14,6 @@
blueprint = Blueprint("invenio_vocabularies_ext", __name__)


@blueprint.record_once
def init(state):
"""Init app."""
app = state.app
# Register services - cannot be done in extension because
# Invenio-Records-Resources might not have been initialized.
sregistry = app.extensions["invenio-records-resources"].registry
ext = app.extensions["invenio-vocabularies"]
sregistry.register(ext.affiliations_service, service_id="affiliations")
sregistry.register(ext.awards_service, service_id="awards")
sregistry.register(ext.funders_service, service_id="funders")
sregistry.register(ext.names_service, service_id="names")
sregistry.register(ext.subjects_service, service_id="subjects")
sregistry.register(ext.service, service_id="vocabularies")
# Register indexers
iregistry = app.extensions["invenio-indexer"].registry
iregistry.register(ext.affiliations_service.indexer, indexer_id="affiliations")
iregistry.register(ext.awards_service.indexer, indexer_id="awards")
iregistry.register(ext.funders_service.indexer, indexer_id="funders")
iregistry.register(ext.names_service.indexer, indexer_id="names")
iregistry.register(ext.subjects_service.indexer, indexer_id="subjects")
iregistry.register(ext.service.indexer, indexer_id="vocabularies")


def create_blueprint_from_app(app):
"""Create app blueprint."""
return app.extensions["invenio-vocabularies"].resource.as_blueprint()
Expand Down
7 changes: 6 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2020-2022 CERN.
# Copyright (C) 2022 Graz University of Technology.
# Copyright (C) 2022-2023 Graz University of Technology.
#
# Invenio-Vocabularies is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
Expand Down Expand Up @@ -67,6 +67,10 @@ invenio_base.api_blueprints =
invenio_vocabularies_names = invenio_vocabularies.views:create_names_blueprint_from_app
invenio_vocabularies_subjects = invenio_vocabularies.views:create_subjects_blueprint_from_app
invenio_vocabularies_ext = invenio_vocabularies.views:blueprint
invenio_base.api_finalize_app =
invenio_vocabularies = invenio_vocabularies.ext:api_finalize_app
invenio_base.finalize_app =
invenio_vocabularies = invenio_vocabularies.ext:finalize_app
invenio_db.alembic =
invenio_vocabularies = invenio_vocabularies:alembic
invenio_db.models =
Expand Down Expand Up @@ -95,6 +99,7 @@ invenio_assets.webpack =
invenio_i18n.translations =
invenio_vocabularies = invenio_vocabularies


[build_sphinx]
source-dir = docs/
build-dir = docs/_build
Expand Down

0 comments on commit 2e1e159

Please sign in to comment.