From 1827b674aafc69173cd0bf8816ba4ef21512aa65 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Tue, 7 Nov 2023 13:48:36 +0100 Subject: [PATCH] Add tipologia_bando to summary serializer --- CHANGES.rst | 3 +++ .../contenttypes/restapi/serializers/summary.py | 2 ++ .../tests/test_summary_serializer.py | 17 +++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index c4f963fd..9253d4ca 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -16,6 +16,9 @@ Changelog - Add @@export-incarichi view that allows to download a csv file with all Persona and their roles. [cekk] +- Add tipologia_bando to summary serializer. + [cekk] + 6.0.21 (2023-10-30) ------------------- diff --git a/src/design/plone/contenttypes/restapi/serializers/summary.py b/src/design/plone/contenttypes/restapi/serializers/summary.py index f0f46248..9b3dfb90 100644 --- a/src/design/plone/contenttypes/restapi/serializers/summary.py +++ b/src/design/plone/contenttypes/restapi/serializers/summary.py @@ -124,6 +124,8 @@ def __call__(self, force_all_metadata=False, force_images=False): if self.context.portal_type == "Persona": res["incarichi"] = self.get_incarichi() if self.context.portal_type == "Bando": + if "tipologia_bando" not in res: + res["tipologia_bando"] = getattr(self.context, "tipologia_bando", "") if "bando_state" in metadata_fields or self.show_all_metadata_fields: res["bando_state"] = self.get_bando_state() diff --git a/src/design/plone/contenttypes/tests/test_summary_serializer.py b/src/design/plone/contenttypes/tests/test_summary_serializer.py index 9bb43496..00836c73 100644 --- a/src/design/plone/contenttypes/tests/test_summary_serializer.py +++ b/src/design/plone/contenttypes/tests/test_summary_serializer.py @@ -312,3 +312,20 @@ def test_summary_do_not_return_tassonomia_argomenti_if_not_in_metadata_fields(se self.request.form["metadata_fields"] = "_all" serializer = getMultiAdapter((news, self.request), ISerializeToJsonSummary)() self.assertIn("tassonomia_argomenti", serializer) + + def test_bando_summary_return_tipologia_bando(self): + bando = api.content.create( + container=self.portal, + type="Bando", + title="Bando", + tipologia_bando="foo", + ) + + commit() + + response = self.api_session.get("@search?portal_type=Bando") + result = response.json() + items = result.get("items", []) + + self.assertEqual(len(items), 1) + self.assertNotIn("tipologia_bando", bando.tipologia_bando)