Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 40 additions & 21 deletions site/cds_rdm/custom_fields/meeting.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,53 @@ def wrapper(self, data, original=None, **kwargs):
)


class BackwardCompatibleMeetingList(fields.List):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this one! wouldn't it be easier to implement this only on the new jinja template (CDSMeeting)? Did you consider that?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did think about that. A Jinja only fix in CDSMeeting.html would cover the record page, but the edit form still loads custom_fields through the schema dump into ArrayField, so a legacy object would still break there. Doing the wrap in serialize felt cleaner so both paths get a list without touching the widget or allowing object writes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah also the API response serializes it incorrectly too if only the jinja template is changed

"""Serialize a legacy meeting object as a one-item list.

Older records store ``meeting:meeting`` as a single object. After the
multi-conference change it is an array. Only serialization is adapted so
reads present a list to the UI; writes must still submit an array.
"""

def _serialize(self, value, attr, obj, **kwargs):
"""Wrap a legacy dict in a list without mutating storage."""
if isinstance(value, dict):
value = [value]
return super()._serialize(value, attr, obj, **kwargs)


class CDSMeetingCF(MeetingCF):
"""Nested custom field."""

@property
def field(self):
"""Meeting fields definitions."""
return fields.List(fields.Nested(
{
"acronym": SanitizedUnicode(),
"dates": SanitizedUnicode(),
"place": SanitizedUnicode(),
"session_part": SanitizedUnicode(),
"session": SanitizedUnicode(),
"title": SanitizedUnicode(),
# URL left for backwards compat, unused
"url": SanitizedUnicode(
validate=_valid_url(error_msg=_("You must provide a valid URL.")),
),
"identifiers": IdentifierValueSet(
fields.Nested(
partial(
IdentifierSchema,
allowed_schemes=record_related_identifiers_schemes,
return BackwardCompatibleMeetingList(
fields.Nested(
{
"acronym": SanitizedUnicode(),
"dates": SanitizedUnicode(),
"place": SanitizedUnicode(),
"session_part": SanitizedUnicode(),
"session": SanitizedUnicode(),
"title": SanitizedUnicode(),
# URL left for backwards compat, unused
"url": SanitizedUnicode(
validate=_valid_url(
error_msg=_("You must provide a valid URL.")
),
),
"identifiers": IdentifierValueSet(
fields.Nested(
partial(
IdentifierSchema,
allowed_schemes=record_related_identifiers_schemes,
)
)
)
),
}
))
),
}
)
)

@property
def mapping(self):
Expand Down
Loading