-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
custom fields: edtf and iso date support #387
Conversation
ppanero
commented
Sep 9, 2022
- closes EDTF CF #385
Tested in an instance with the following config: # Custom fields
from invenio_records_resources.services.custom_fields import EDTFDateStringCF, ISODateStringCF
RDM_CUSTOM_FIELDS = [
EDTFDateStringCF(name="edtf"),
ISODateStringCF(name="iso"),
]
RDM_CUSTOM_FIELDS_UI = [
{
"section": _("CERN Experiment"),
"fields": [
dict(
field="edtf", # this should be validated against the defined fields in `RDM_CUSTOM_FIELDS`
ui_widget="Input", # user defined widget in my-site
props=dict(
label="EDTF Date",
placeholder="Type...",
icon="lab",
description="You should fill this...",
)
),
dict(
field="iso", # this should be validated against the defined fields in `RDM_CUSTOM_FIELDS`
ui_widget="Input", # user defined widget in my-site
props=dict(
label="EDTF Date",
placeholder="Type...",
icon="lab",
description="You should fill this...",
)
),
]
}
] Mapping result after services setup: "custom_fields": {
"properties": {
"edtf": {
"properties": {
"date": {
"type": "date"
},
"date_range": {
"type": "date_range"
}
}
},
"iso": {
"type": "date"
}
}
}, Demo records are indexed without them, same for a record without those values created from the deposit form. "custom_fields": {}, Deposit form looks like: The landing page: The REST API ( "custom_fields": {"edtf": "2020/2021", "iso": "2020-10-01"}, The ES record: "custom_fields": {
"iso": "2020-10-01",
"edtf": {
"date": "2020/2021",
"date_range": {
"gte": "2020-01-01",
"lte": "2021-12-31"
}
}
}, |
7f6328f
to
0b38880
Compare
This supports the case where a field is based on others, both | ||
custom and non-custom fields. | ||
""" | ||
date = record.get(cf_key, {}).pop(self.name, None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why (recid is the same, so is not the parent), but on search a record passes twice by the dumper, the second time without metadata
and custom_fields
. That's why the first is a .get()
instead of []
(Pdb) record.keys()
dict_keys(['parent', 'versions', 'has_draft', '$schema', 'pid', 'id', 'files', 'metadata', 'custom_fields', 'pids', 'access', 'uuid', 'version_id', 'created', 'updated'])
(Pdb) record.keys()
dict_keys(['id', 'pid', 'access', '$schema', 'communities', 'uuid', 'version_id', 'created', 'updated'])
6f67043
to
39f91ed
Compare