-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added serializer for Modulo. Added field ricerca_in_testata to Moduli…
…stica ct
- Loading branch information
1 parent
4d5ca1f
commit 0fbfe61
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |