From d768f717670fa5ada2be4744afa6e56a1ab3d02b Mon Sep 17 00:00:00 2001 From: Adrian Moennich Date: Wed, 12 May 2021 18:42:06 +0200 Subject: [PATCH] Citadel: Update schemas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Pedro Lourenço --- citadel/indico_citadel/result_schemas.py | 13 ++++++++++++- citadel/indico_citadel/schemas.py | 4 ++++ citadel/indico_citadel/schemas_test.py | 4 ++-- citadel/indico_citadel/search.py | 6 +++--- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/citadel/indico_citadel/result_schemas.py b/citadel/indico_citadel/result_schemas.py index dc4e013..5004008 100644 --- a/citadel/indico_citadel/result_schemas.py +++ b/citadel/indico_citadel/result_schemas.py @@ -11,7 +11,8 @@ from marshmallow import fields, pre_load from indico.modules.search.base import SearchTarget from indico.modules.search.result_schemas import (AggregationSchema, AttachmentResultSchema, BucketSchema, - EventResultSchema, ResultItemSchema, ResultSchema) + EventNoteResultSchema, EventResultSchema, ResultItemSchema, + ResultSchema) class CitadelEventResultSchema(EventResultSchema): @@ -26,10 +27,19 @@ class CitadelAttachmentResultSchema(AttachmentResultSchema): @pre_load def _translate_keys(self, data, **kwargs): data = data.copy() + data['user'] = data.pop('persons', None) data['attachment_type'] = data.pop('type_format') return data +class CitadelEventNoteResultSchema(EventNoteResultSchema): + @pre_load + def _translate_keys(self, data, **kwargs): + data = data.copy() + data['user'] = data.pop('persons', None) + return data + + class _CitadelBucketSchema(BucketSchema): @pre_load def _make_filter(self, data, **kwargs): @@ -52,6 +62,7 @@ class CitadelResultItemSchema(ResultItemSchema): **ResultItemSchema.type_schemas, SearchTarget.event.name: CitadelEventResultSchema, SearchTarget.attachment.name: CitadelAttachmentResultSchema, + SearchTarget.event_note.name: CitadelEventNoteResultSchema, } diff --git a/citadel/indico_citadel/schemas.py b/citadel/indico_citadel/schemas.py index 80ea46a..1d784a5 100644 --- a/citadel/indico_citadel/schemas.py +++ b/citadel/indico_citadel/schemas.py @@ -151,6 +151,8 @@ class AttachmentRecordSchema(RecordSchema, AttachmentSchema): @post_dump def _translate_keys(self, data, **kwargs): data['type_format'] = data.pop('attachment_type') + if user := data['_data'].pop('user', None): + data['_data']['persons'] = user return data @@ -208,6 +210,8 @@ class _EventNoteDataSchema(EventNoteSchema): def _transform(self, data, **kwargs): if desc := data.get('content'): data['content'] = strip_tags(desc).strip() + if user := data.pop('user', None): + data['persons'] = user return data diff --git a/citadel/indico_citadel/schemas_test.py b/citadel/indico_citadel/schemas_test.py index 3188c1f..08c17ab 100644 --- a/citadel/indico_citadel/schemas_test.py +++ b/citadel/indico_citadel/schemas_test.py @@ -188,7 +188,7 @@ def test_dump_attachment(db, dummy_user, dummy_contribution): 'filename': 'dummy_file.txt', 'site': 'http://localhost', 'title': 'Dummy Attachment', - 'user': {'name': 'Guinea Pig'}, + 'persons': {'name': 'Guinea Pig'}, }, 'attachment_id': attachment.id, 'category_id': category_id, @@ -247,7 +247,7 @@ def test_dump_event_note(db, dummy_user, dummy_event, dummy_contribution, link_t 'content': 'this is a dummy note', 'site': 'http://localhost', 'title': f'{note.object.title} - Notes/Minutes', - 'user': {'name': 'Guinea Pig'} + 'persons': {'name': 'Guinea Pig'} }, 'category_id': category_id, 'category_path': [ diff --git a/citadel/indico_citadel/search.py b/citadel/indico_citadel/search.py index fc7c8c0..e62cd77 100644 --- a/citadel/indico_citadel/search.py +++ b/citadel/indico_citadel/search.py @@ -77,9 +77,9 @@ class CitadelProvider(IndicoSearchProvider): placeholders = { 'title': ('_data.title', _('The title an event, contribution, etc.)')), - 'person': ('_data.persons.name', _("A speaker, author or event chair's name")), - 'affiliation': ('_data.persons.affiliation', _("A speaker, author or event chair's affiliation")), - 'type': ('type', _('An entry type (such as conference, meeting, file, etc.)')), + 'person': ('_data.persons_index.name', _("A speaker, author or event chair's name")), + 'affiliation': ('_data.persons_index.affiliation', _("A speaker, author or event chair's affiliation")), + 'type': ('type_any', _('An entry type (such as conference, meeting, file, etc.)')), 'venue': ('_data.location.venue_name', _("Name of the venue")), 'room': ('_data.location.room_name', _("Name of the room")), 'address': ('_data.location.address', _("Address of the venue")),