Skip to content
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

Merged
merged 2 commits into from
Sep 13, 2022

Conversation

ppanero
Copy link
Member

@ppanero ppanero commented Sep 9, 2022

@ppanero
Copy link
Member Author

ppanero commented Sep 12, 2022

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:

Screenshot 2022-09-12 at 10 38 37

The landing page:

Screenshot 2022-09-12 at 10 58 53

The REST API (/api/records/12345):

"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"
      }
  }
},

@ppanero ppanero force-pushed the edtf-cf branch 2 times, most recently from 7f6328f to 0b38880 Compare September 12, 2022 08:35
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)
Copy link
Member Author

@ppanero ppanero Sep 12, 2022

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'])

@ppanero ppanero force-pushed the edtf-cf branch 2 times, most recently from 6f67043 to 39f91ed Compare September 12, 2022 14:12
@ppanero ppanero merged commit 8ace818 into inveniosoftware:master Sep 13, 2022
@ppanero ppanero deleted the edtf-cf branch September 13, 2022 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EDTF CF
2 participants