From 7a93a2d442d4f810e5d473bf70a388d80151f54a Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Tue, 6 Feb 2024 14:40:46 +0100 Subject: [PATCH] fix compatibility --- src/rer/solrpush/parser.py | 27 +++++++++++++++++++++++++- src/rer/solrpush/utils/solr_indexer.py | 10 +++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/rer/solrpush/parser.py b/src/rer/solrpush/parser.py index 7209303..9daba7e 100644 --- a/src/rer/solrpush/parser.py +++ b/src/rer/solrpush/parser.py @@ -170,7 +170,32 @@ def restrictedTraverse(self, name): @property def image_scales(self): - return json.loads(self.get("image_scales", "{}")) + scales = json.loads(self.get("image_scales", "{}")) + if scales: + return scales + + # backward compatibility with < Plone6 indexed contents + if not self.get("getIcon", False): + return {} + + return { + "image": [ + { + "download": "@@images/image", + "scales": { + "preview": { + "download": "@@images/image/preview", + }, + "thumb": { + "download": "@@images/image/thumb", + }, + "mini": { + "download": "@@images/image/mini", + }, + }, + } + ] + } class SolrResults(list): diff --git a/src/rer/solrpush/utils/solr_indexer.py b/src/rer/solrpush/utils/solr_indexer.py index bf3c3e3..cf02baf 100644 --- a/src/rer/solrpush/utils/solr_indexer.py +++ b/src/rer/solrpush/utils/solr_indexer.py @@ -171,9 +171,17 @@ def create_index_dict(item): else: index_me["url"] = item.absolute_url() - has_image = getattr(item.aq_base, "image", None) + # backward compatibility with Plone < 6 where there wasn't image_field and image_scales indexers + has_image = False + if index_me.get("image_field", None) and index_me.get( + "image_scales", None + ): + has_image = True + else: + has_image = getattr(item.aq_base, "image", None) if has_image: index_me["getIcon"] = True + return index_me