Skip to content

Commit

Permalink
added serializer for Modulo. Added field ricerca_in_testata to Moduli…
Browse files Browse the repository at this point in the history
…stica ct
  • Loading branch information
daniele-andreotti committed Sep 24, 2024
1 parent 4d5ca1f commit 0fbfe61
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/iosanita/contenttypes/interfaces/cartella_modulistica.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,13 @@ class ICartellaModulistica(model.Schema, IIosanitaContenttypes):
required=False,
default=False,
)

ricerca_in_testata = schema.Bool(
title=_("ricerca_in_testata_label", default="Ricerca in testata"),
default=False,
required=False,
description=_(
"ricerca_in_testata_help",
default="Seleziona se mostrare o meno il campo di ricerca in testata.",
),
)
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=".modulo.SerializeModuloToJsonSummary" />


<!-- Summary Serializer Metadata -->
Expand Down
37 changes: 37 additions & 0 deletions src/iosanita/contenttypes/restapi/serializers/modulo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
from iosanita.contenttypes.interfaces import IIosanitaContenttypesLayer
from iosanita.contenttypes.interfaces.modulo import IModulo
from iosanita.contenttypes.restapi.serializers.summary import (
DefaultJSONSummarySerializer,
)
from plone.dexterity.utils import iterSchemata
from plone.restapi.interfaces import IFieldSerializer
from plone.restapi.interfaces import ISerializeToJsonSummary
from zope.component import adapter
from zope.component import queryMultiAdapter
from zope.interface import implementer
from zope.schema import getFields


@implementer(ISerializeToJsonSummary)
@adapter(IModulo, IIosanitaContenttypesLayer)
class SerializeModuloToJsonSummary(DefaultJSONSummarySerializer):
def __call__(self, **kwargs):
summary = super().__call__(**kwargs)
fields = [
"file",
"formato_alternativo_1",
"formato_alternativo_2",
]
for schema in iterSchemata(self.context):
for name, field in getFields(schema).items():
if name not in fields:
continue

# serialize the field
serializer = queryMultiAdapter(
(field, self.context, self.request), IFieldSerializer
)
value = serializer()
summary[name] = value
return summary

0 comments on commit 0fbfe61

Please sign in to comment.