diff --git a/CHANGES.rst b/CHANGES.rst index 7b270ba2..4fa5669c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,8 @@ Changelog 6.2.7 (unreleased) ------------------ -- Nothing changed yet. +- Do not break News serialzier if `tipologia_notizia` attribute is missing. + [cekk] 6.2.6 (2024-04-18) diff --git a/src/design/plone/contenttypes/patches/baseserializer.py b/src/design/plone/contenttypes/patches/baseserializer.py index 1ac8ca6d..12805939 100644 --- a/src/design/plone/contenttypes/patches/baseserializer.py +++ b/src/design/plone/contenttypes/patches/baseserializer.py @@ -37,7 +37,7 @@ def design_italia_serialize_to_json_call(self, version=None, include_items=True) ttool[self.context.portal_type].Title(), context=self.request ) if self.context.portal_type == "News Item": - if self.context.tipologia_notizia: + if getattr(self.context, "tipologia_notizia", ""): taxonomy = getUtility( ITaxonomy, name="collective.taxonomy.tipologia_notizia" ) diff --git a/src/design/plone/contenttypes/restapi/serializers/dxcontent.py b/src/design/plone/contenttypes/restapi/serializers/dxcontent.py index bae57370..568cc3a3 100644 --- a/src/design/plone/contenttypes/restapi/serializers/dxcontent.py +++ b/src/design/plone/contenttypes/restapi/serializers/dxcontent.py @@ -19,15 +19,16 @@ class MetaTypeSerializer(object): def get_design_meta_type(self): ttool = api.portal.get_tool("portal_types") - if self.context.portal_type == "News Item" and self.context.tipologia_notizia: + tipologia_notizia = getattr(self.context, "tipologia_notizia", "") + if self.context.portal_type == "News Item" and tipologia_notizia: taxonomy = getUtility( ITaxonomy, name="collective.taxonomy.tipologia_notizia" ) taxonomy_voc = taxonomy.makeVocabulary(self.request.get("LANGUAGE")) - if isinstance(self.context.tipologia_notizia, list): - token = self.context.tipologia_notizia[0] + if isinstance(tipologia_notizia, list): + token = tipologia_notizia[0] else: - token = self.context.tipologia_notizia + token = tipologia_notizia title = taxonomy_voc.inv_data.get(token, None) if title and title.startswith(PATH_SEPARATOR): diff --git a/src/design/plone/contenttypes/restapi/serializers/summary.py b/src/design/plone/contenttypes/restapi/serializers/summary.py index 055ba38e..92c31bb3 100644 --- a/src/design/plone/contenttypes/restapi/serializers/summary.py +++ b/src/design/plone/contenttypes/restapi/serializers/summary.py @@ -220,15 +220,16 @@ def is_get_call(self): def get_design_meta_type(self): ttool = api.portal.get_tool("portal_types") if self.context.portal_type == "News Item": - if self.context.tipologia_notizia: + tipologia_notizia = getattr(self.context, "tipologia_notizia", "") + if tipologia_notizia: taxonomy = getUtility( ITaxonomy, name="collective.taxonomy.tipologia_notizia" ) taxonomy_voc = taxonomy.makeVocabulary(self.request.get("LANGUAGE")) - if isinstance(self.context.tipologia_notizia, list): - token = self.context.tipologia_notizia[0] + if isinstance(tipologia_notizia, list): + token = tipologia_notizia[0] else: - token = self.context.tipologia_notizia + token = tipologia_notizia title = taxonomy_voc.inv_data.get(token, None) if title: if title.startswith(PATH_SEPARATOR):