Skip to content

Commit

Permalink
vocabulary types: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahW91 committed Jun 24, 2024
1 parent 2555b8e commit 842f5c3
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 50 deletions.
2 changes: 0 additions & 2 deletions invenio_vocabularies/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion invenio_vocabularies/resources/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 0 additions & 2 deletions invenio_vocabularies/resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@

from .serializer import VocabularyL10NItemSchema

# from invenio_vocabularies.proxies import current_service


#
# Resource
Expand Down
40 changes: 7 additions & 33 deletions invenio_vocabularies/services/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand Down Expand Up @@ -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"),
Expand All @@ -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"
Expand Down Expand Up @@ -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(
Expand All @@ -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*}")
6 changes: 2 additions & 4 deletions invenio_vocabularies/services/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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", {}
)
Expand Down
9 changes: 1 addition & 8 deletions invenio_vocabularies/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand Down

0 comments on commit 842f5c3

Please sign in to comment.