Skip to content

Commit

Permalink
Do not break News serializer if tipologia_notizia attribute is miss…
Browse files Browse the repository at this point in the history
…ing (#257)

* Do not break News serialzier if  attribute is missing.
* fix in more places
  • Loading branch information
cekk authored Apr 22, 2024
1 parent e5a79ec commit d7450cc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/design/plone/contenttypes/patches/baseserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 5 additions & 4 deletions src/design/plone/contenttypes/restapi/serializers/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit d7450cc

Please sign in to comment.