Skip to content

Commit

Permalink
Add NewsItem summary serializer, to return always metadata infos abou…
Browse files Browse the repository at this point in the history
…t tipologia_notizia and tipologia_notizia_metadata.
  • Loading branch information
cekk committed Nov 20, 2024
1 parent 7b63092 commit bee8611
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Changelog
1.0.2 (unreleased)
------------------

- Nothing changed yet.
- Add NewsItem summary serializer, to return always metadata infos about tipologia_notizia and tipologia_notizia_metadata.
[cekk]


1.0.1 (2024-11-19)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<adapter factory=".news.NewsItemSerializeToJson" />
<adapter factory=".summary.IOSanitaJSONSummarySerializer" />
<adapter factory=".summary.PuntoDiContattoJSONSummarySerializer" />
<adapter factory=".summary.NewsItemJSONSummarySerializer" />
<adapter factory=".modulo.SerializeModuloToJsonSummary" />
<adapter factory=".dxfields.FileFieldViewModeSerializer" />

Expand Down
18 changes: 18 additions & 0 deletions src/iosanita/contenttypes/restapi/serializers/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from zope.component import adapter
from zope.interface import implementer
from zope.interface import Interface
from plone.app.contenttypes.interfaces import INewsItem
from zope.component import queryMultiAdapter
from plone.indexer.interfaces import IIndexableObject

import logging

Expand All @@ -27,6 +30,7 @@ def default_metadata_fields(self):
"a_chi_si_rivolge_tassonomia_metadata",
"id",
"tipologia_notizia",
"tipologia_notizia_metadata",
"start",
"end",
"recurrence",
Expand Down Expand Up @@ -116,3 +120,17 @@ def __call__(self):
data["contatti"] = getattr(self.context, "contatti", [])

return data


@implementer(ISerializeToJsonSummary)
@adapter(INewsItem, IIosanitaContenttypesLayer)
class NewsItemJSONSummarySerializer(IOSanitaJSONSummarySerializer):
def __call__(self):
data = super().__call__()

catalog = api.portal.get_tool(name="portal_catalog")
adapter = queryMultiAdapter((self.context, catalog), IIndexableObject)

for metadata in ["tipologia_notizia", "tipologia_notizia_metadata"]:
data[metadata] = getattr(adapter, metadata, data.get(metadata, ""))
return data

0 comments on commit bee8611

Please sign in to comment.