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 Jun 7, 2023
1 parent 7921de5 commit dc22556
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
32 changes: 32 additions & 0 deletions invenio_vocabularies/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,35 @@ def init_resource(self, app):
service=self.service,
config=app.config["VOCABULARIES_RESOURCE_CONFIG"],
)


def finalize_app(app):
"""Finalize app."""
init(app)


def api_finalize_app(app):
"""Api Finalize app."""
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")
24 changes: 0 additions & 24 deletions invenio_vocabularies/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,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
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ invenio_assets.webpack =
invenio_vocabularies = invenio_vocabularies.webpack:theme
invenio_i18n.translations =
invenio_vocabularies = invenio_vocabularies
invenio_base.finalize_app =
invenio_vocabularies = invenio_vocabularies.ext:finalize_app
invenio_base.api_finalize_app =
invenio_vocabularies = invenio_vocabularies.ext:api_finalize_app


[build_sphinx]
source-dir = docs/
Expand Down

0 comments on commit dc22556

Please sign in to comment.