diff --git a/invenio_vocabularies/ext.py b/invenio_vocabularies/ext.py index 3792f1bc..e273d3cd 100644 --- a/invenio_vocabularies/ext.py +++ b/invenio_vocabularies/ext.py @@ -49,8 +49,6 @@ from .services.config import VocabularyTypesServiceConfig from .services.service import VocabulariesService, VocabularyTypeService -# from .contrib.information import InformationResource, InformationResourceConfig - class InvenioVocabularies(object): """Invenio-Vocabularies extension.""" diff --git a/invenio_vocabularies/resources/config.py b/invenio_vocabularies/resources/config.py index 2b1f3080..1a175135 100644 --- a/invenio_vocabularies/resources/config.py +++ b/invenio_vocabularies/resources/config.py @@ -75,7 +75,7 @@ class VocabularyTypeResourceConfig(ResourceConfig, ConfiguratorMixin): # /vocabulary/vocabulary_id # Blueprint configuration - blueprint_name = "vocabulary_list" + blueprint_name = "vocabulary_types" url_prefix = "/vocabularies" routes = { diff --git a/invenio_vocabularies/resources/resource.py b/invenio_vocabularies/resources/resource.py index 9520a42e..8d3cc09a 100644 --- a/invenio_vocabularies/resources/resource.py +++ b/invenio_vocabularies/resources/resource.py @@ -40,8 +40,6 @@ from .serializer import VocabularyL10NItemSchema -# from invenio_vocabularies.proxies import current_service - # # Resource diff --git a/invenio_vocabularies/services/config.py b/invenio_vocabularies/services/config.py index 4684b1cb..7ab12932 100644 --- a/invenio_vocabularies/services/config.py +++ b/invenio_vocabularies/services/config.py @@ -9,6 +9,7 @@ """Vocabulary services configs.""" +import sqlalchemy as sa from flask import current_app from invenio_i18n import lazy_gettext as _ from invenio_records_resources.services import ( @@ -29,9 +30,9 @@ FilterParam, SuggestQueryParser, ) -from sqlalchemy import asc, desc from ..records.api import Vocabulary +from ..records.models import VocabularyType from . import results from .components import PIDComponent, VocabularyTypeComponent from .permissions import PermissionPolicy @@ -90,20 +91,6 @@ class VocabularySearchOptions(SearchOptions): class VocabularyTypeSearchOptions(SearchOptions): """Search options for vocabulary types.""" - # TODO: Is this still necessary here? - params_interpreters_cls = [ - FilterParam.factory(param="tags", field="tags"), - ] + SearchOptions.params_interpreters_cls - - # TODO: Is this still necessary here? - suggest_parser_cls = SuggestQueryParser.factory( - fields=[ - "id.text^100", - "id.text._2gram", - "id.text._3gram", - ], - ) - sort_options = { "id": dict( title=_("ID"), @@ -116,8 +103,8 @@ class VocabularyTypeSearchOptions(SearchOptions): sort_default_no_query = "id" sort_direction_options = { - "asc": dict(title=_("Ascending"), fn=asc), - "desc": dict(title=_("Descending"), fn=desc), + "asc": dict(title=_("Ascending"), fn=sa.asc), + "desc": dict(title=_("Descending"), fn=sa.desc), } sort_direction_default = "asc" @@ -162,12 +149,11 @@ class VocabularyTypesServiceConfig(RecordServiceConfig): service_id = "vocabulary_types" permission_policy_cls = PermissionPolicy - record_cls = Vocabulary # TODO: Is this correct? + record_cls = VocabularyType schema = VocabularySchema - task_schema = TaskSchema - vocabularies_listing_resultlist_cls = results.VocabularyMetadataList + result_list_cls = results.VocabularyTypeList - vocabularies_listing_item = { + links_item = { "self": ConditionalLink( cond=is_custom_vocabulary_type, if_=Link( @@ -190,16 +176,4 @@ class VocabularyTypesServiceConfig(RecordServiceConfig): PIDComponent, ] - links_item = { - "self": Link( - "{+api}/vocabularies/{type}/{id}", - vars=lambda record, vars: vars.update( - { - "id": record.pid.pid_value, - "type": record.type.id, - } - ), - ), - } - links_search = pagination_links("{+api}/vocabularies/{type}{?args*}") diff --git a/invenio_vocabularies/services/results.py b/invenio_vocabularies/services/results.py index 790b8085..877270ea 100644 --- a/invenio_vocabularies/services/results.py +++ b/invenio_vocabularies/services/results.py @@ -18,8 +18,8 @@ from ..proxies import current_service -class VocabularyMetadataList(RecordList): - """Ensures that vocabulary metadata is returned in the proper format.""" +class VocabularyTypeList(RecordList): + """Ensures that vocabulary type metadata is returned in the proper format.""" @property def total(self): @@ -33,8 +33,6 @@ def custom_vocabulary_names(self): def to_dict(self): """Formats result to a dict of hits.""" - # hits = list(self._results) - config_vocab_types = current_app.config.get( "INVENIO_VOCABULARY_TYPE_METADATA", {} ) diff --git a/invenio_vocabularies/services/service.py b/invenio_vocabularies/services/service.py index b061bb3b..c8a16b21 100644 --- a/invenio_vocabularies/services/service.py +++ b/invenio_vocabularies/services/service.py @@ -37,13 +37,6 @@ def schema(self): """Returns the data schema instance.""" return ServiceSchemaWrapper(self, schema=self.config.schema) - @property - def links_item_tpl(self): - """Item links template.""" - return LinksTemplate( - self.config.vocabularies_listing_item, - ) - def search(self, identity, params=None): """Search for vocabulary types entries.""" self.require_permission(identity, "list_vocabularies") @@ -70,7 +63,7 @@ def search(self, identity, params=None): ) ) - return self.config.vocabularies_listing_resultlist_cls( + return self.config.result_list_cls( self, identity, vocabulary_types,