Skip to content

Commit

Permalink
Merge pull request #57 from Narodni-repozitar/miroslavsimek/be-179-fi…
Browse files Browse the repository at this point in the history
…x-sort-by-title-in-nr-docs

Extra field for czech-enabled sort
  • Loading branch information
mirekys authored Oct 24, 2023
2 parents 4066e14 + 14a6c20 commit d271bbd
Show file tree
Hide file tree
Showing 14 changed files with 452 additions and 349 deletions.
12 changes: 12 additions & 0 deletions local/nr-docs-extensions/nr_docs_extensions/services/sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from oarepo_runtime.records.icu import ICUSortField
from oarepo_runtime.relations.lookup import lookup_key


class TitleICUSortField(ICUSortField):

def get_values(self, data, language):
ret = []
for l in lookup_key(data, self.source_field):
if l.value:
ret.append(l.value)
return ret
24 changes: 21 additions & 3 deletions models/nr-documents/model.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,30 @@ record:
- import: flask_resources.MarshmallowSerializer
resource-config:
base-html-url: /docs/

# sort by czech title
search-options:
base-classes:
- InvenioSearchOptions
- I18nSearchOptions
imports:
- import: oarepo_runtime.services.icu.SearchOptions
alias: InvenioSearchOptions
- import: oarepo_runtime.services.icu.I18nSearchOptions
- import: oarepo_runtime.services.icu.ICUSortOptions
sort-options-field: extra_sort_options
extra-code: |-2
sort_options = ICUSortOptions("nr_documents")
record:
imports:
- import: oarepo_runtime.records.SystemFieldDumperExt
- import: nr_docs_extensions.services.sort.TitleICUSortField
- import: invenio_drafts_resources.records.api.Record
alias: InvenioRecord
extra-code: |-2
# extra custom fields for sorting by title
sort = TitleICUSortField(source_field="metadata.title")
record-dumper:
extensions:
- SystemFieldDumperExt()

draft: {}
use:
- invenio
Expand Down
1 change: 1 addition & 0 deletions models/nr-documents/nr_documents/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class Nr_documentsExt:
def __init__(self, app=None):

if app:
self.init_app(app)

Expand Down
119 changes: 64 additions & 55 deletions models/nr-documents/nr_documents/models/records.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,24 @@
"extra-code": "",
"generate": true
},
"record-dumper": {
"extensions": [
"SystemFieldDumperExt()",
"MultilingualSearchDumper()"
],
"generate": true,
"module": "nr_documents.records.dumper",
"class": "nr_documents.records.dumper.NrDocumentsDumper",
"base-classes": [
"SearchDumper"
],
"extra-code": "",
"imports": [
{
"import": "invenio_records.dumpers.SearchDumper"
}
]
},
"resource-config": {
"base-html-url": "/docs/",
"imports": [
Expand All @@ -227,21 +245,44 @@
"RecordResourceConfig"
]
},
"record": {
"extra-code": " # extra custom fields for sorting by title\n sort = LangValueICUSortField(source_field=\"metadata.title\")",
"imports": [
{
"import": "oarepo_runtime.records.SystemFieldDumperExt"
},
{
"import": "nr_docs_extensions.services.sort.LangValueICUSortField"
},
{
"import": "invenio_drafts_resources.records.api.Record",
"alias": "InvenioRecord"
}
],
"generate": true,
"module": "nr_documents.records.api",
"class": "nr_documents.records.api.NrDocumentsRecord",
"base-classes": [
"InvenioRecord"
]
},
"search-options": {
"extra-code": " sort_options = ICUSortOptions(\"nr_documents\")",
"base-classes": [
"InvenioSearchOptions"
"I18nSearchOptions"
],
"imports": [
{
"import": "oarepo_runtime.services.icu.SearchOptions",
"alias": "InvenioSearchOptions"
"import": "oarepo_runtime.services.icu.I18nSearchOptions"
},
{
"import": "oarepo_runtime.services.icu.ICUSortOptions"
}
],
"sort-options-field": "extra_sort_options",
"generate": true,
"module": "nr_documents.services.records.search",
"extra-code": "",
"class": "nr_documents.services.records.search.NrDocumentsSearchOptions",
"sort-options-field": "sort_options"
"class": "nr_documents.services.records.search.NrDocumentsSearchOptions"
},
"module": {
"qualified": "nr_documents",
Expand All @@ -258,11 +299,6 @@
"suffix-upper": "NR_DOCUMENTS",
"suffix-snake": "nr_documents"
},
"tests": {
"extra-fixtures": [],
"extra-code": "",
"module": "tests"
},
"draft": {
"type": "draft_record",
"properties": {},
Expand Down Expand Up @@ -293,6 +329,11 @@
"module": "tests"
}
},
"tests": {
"extra-fixtures": [],
"extra-code": "",
"module": "tests"
},
"sample": {
"file": "data/sample_data.yaml"
},
Expand Down Expand Up @@ -346,21 +387,6 @@
"module": "nr_documents.proxies",
"generate": true
},
"record": {
"imports": [
{
"import": "invenio_drafts_resources.records.api.Record",
"alias": "InvenioRecord"
}
],
"generate": true,
"module": "nr_documents.records.api",
"class": "nr_documents.records.api.NrDocumentsRecord",
"base-classes": [
"InvenioRecord"
],
"extra-code": ""
},
"resource": {
"imports": [
{
Expand All @@ -377,6 +403,18 @@
"RecordResource"
]
},
"json-schema-settings": {
"generate": true,
"alias": "nr_documents",
"version": "1.0.0",
"module": "nr_documents.records.jsonschemas",
"name": "nr_documents-1.0.0.json",
"file": "nr_documents/records/jsonschemas/nr_documents-1.0.0.json"
},
"translations": {
"module": "nr_documents.translations",
"alias": "nr_documents"
},
"files-field": {
"generate": true,
"field-class": "FilesField",
Expand All @@ -393,35 +431,6 @@
}
]
},
"json-schema-settings": {
"generate": true,
"alias": "nr_documents",
"version": "1.0.0",
"module": "nr_documents.records.jsonschemas",
"name": "nr_documents-1.0.0.json",
"file": "nr_documents/records/jsonschemas/nr_documents-1.0.0.json"
},
"record-dumper": {
"generate": true,
"module": "nr_documents.records.dumper",
"class": "nr_documents.records.dumper.NrDocumentsDumper",
"base-classes": [
"SearchDumper"
],
"extra-code": "",
"extensions": [
"MultilingualSearchDumper()"
],
"imports": [
{
"import": "invenio_records.dumpers.SearchDumper"
}
]
},
"translations": {
"module": "nr_documents.translations",
"alias": "nr_documents"
},
"record-metadata": {
"generate": true,
"module": "nr_documents.records.models",
Expand Down
11 changes: 6 additions & 5 deletions models/nr-documents/nr_documents/records/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from invenio_requests.records import Request
from invenio_requests.records.systemfields.relatedrecord import RelatedRecord
from invenio_vocabularies.records.api import Vocabulary
from nr_docs_extensions.services.sort import TitleICUSortField
from oarepo_runtime.drafts.systemfields.has_draftcheck import HasDraftCheckField
from oarepo_runtime.records import SystemFieldDumperExt
from oarepo_runtime.relations import PIDRelation, RelationsField

from nr_documents.records.dumper import NrDocumentsDraftDumper, NrDocumentsDumper
Expand All @@ -31,10 +33,6 @@ class NrDocumentsParentRecord(ParentRecord):
keys=["type", "receiver", "status"],
)

# schema = ConstantField(
# "$schema", "local://parent-v1.0.0.json"
# )


class NrDocumentsIdProvider(DraftRecordIdProviderV2):
pid_type = "dcmnts"
Expand All @@ -51,9 +49,12 @@ class NrDocumentsRecord(InvenioRecord):
provider=NrDocumentsIdProvider, context_cls=PIDFieldContext, create=True
)

dumper_extensions = [MultilingualSearchDumper()]
dumper_extensions = [SystemFieldDumperExt(), MultilingualSearchDumper()]
dumper = NrDocumentsDumper(extensions=dumper_extensions)

# extra custom fields for sorting by title
sort = TitleICUSortField(source_field="metadata.title")

relations = RelationsField(
accessRights=PIDRelation(
"metadata.accessRights",
Expand Down
8 changes: 5 additions & 3 deletions models/nr-documents/nr_documents/services/records/search.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from oarepo_runtime.services.icu import SearchOptions as InvenioSearchOptions
from oarepo_runtime.services.icu import I18nSearchOptions, ICUSortOptions

from . import facets


class NrDocumentsSearchOptions(InvenioSearchOptions):
class NrDocumentsSearchOptions(I18nSearchOptions):
"""NrDocumentsRecord search options."""

facet_groups = {}
Expand Down Expand Up @@ -175,5 +175,7 @@ class NrDocumentsSearchOptions(InvenioSearchOptions):
"syntheticFields_keywords_en": facets.syntheticFields_keywords_en,
"syntheticFields_person": facets.syntheticFields_person,
"updated": facets.updated,
**getattr(InvenioSearchOptions, "facets", {}),
**getattr(I18nSearchOptions, "facets", {}),
}

sort_options = ICUSortOptions("nr_documents")
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
msgid ""
msgstr ""
"Project-Id-Version: 1.0\n"
"POT-Creation-Date: 2023-10-23T14:38:05.056789\n"
"PO-Revision-Date: 2023-10-23T14:38:05.056798\n"
"POT-Creation-Date: 2023-10-24T13:32:14.016888\n"
"PO-Revision-Date: 2023-10-24T13:32:14.016898\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
msgid ""
msgstr ""
"Project-Id-Version: 1.0\n"
"POT-Creation-Date: 2023-10-23T14:38:05.056819\n"
"PO-Revision-Date: 2023-10-23T14:38:05.056820\n"
"POT-Creation-Date: 2023-10-24T13:32:14.016920\n"
"PO-Revision-Date: 2023-10-24T13:32:14.016922\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
4 changes: 2 additions & 2 deletions models/nr-documents/nr_documents/translations/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
msgid ""
msgstr ""
"Project-Id-Version: 1.0\n"
"POT-Creation-Date: 2023-10-23T14:38:05.056835\n"
"PO-Revision-Date: 2023-10-23T14:38:05.056836\n"
"POT-Creation-Date: 2023-10-24T13:32:14.016936\n"
"PO-Revision-Date: 2023-10-24T13:32:14.016937\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
Loading

0 comments on commit d271bbd

Please sign in to comment.