diff --git a/invenio_vocabularies/ext.py b/invenio_vocabularies/ext.py index 4c34513c..52e9294b 100644 --- a/invenio_vocabularies/ext.py +++ b/invenio_vocabularies/ext.py @@ -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") diff --git a/invenio_vocabularies/views.py b/invenio_vocabularies/views.py index be150406..8a6d757e 100644 --- a/invenio_vocabularies/views.py +++ b/invenio_vocabularies/views.py @@ -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() diff --git a/setup.cfg b/setup.cfg index ce6dcd84..56d4bd5d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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/