Skip to content

Commit

Permalink
add venue serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Oct 17, 2023
1 parent 61610a3 commit e47690c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/design/plone/ctgeneric/restapi/serializer/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<adapter factory=".summary.PersonaDefaultJSONSummarySerializer" />
<adapter factory=".unita_organizzativa.UOJSONSummarySerializer" />
<adapter factory=".persona.PersonaSerializer" />
<adapter factory=".venue.VenueSerializer" />



</configure>
34 changes: 34 additions & 0 deletions src/design/plone/ctgeneric/restapi/serializer/venue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from design.plone.contenttypes.restapi.serializers.venue import (
VenueSerializer as BaseSerializer,
)
from design.plone.contenttypes.interfaces.persona import IPersona
from plone.restapi.interfaces import ISerializeToJson
from zope.component import adapter
from zope.interface import implementer
from design.plone.ctgeneric.interfaces import IDesignPloneCtgenericLayer
from plone.restapi.serializer.converters import json_compatible


@implementer(ISerializeToJson)
@adapter(IPersona, IDesignPloneCtgenericLayer)
class VenusSerializer(BaseSerializer):
def __call__(self, version=None, include_items=True):
result = super().__call__(version=version, include_items=include_items)

result["contact_info"] = self.get_contacts_v2()
return result

def get_contacts_v2(self):
pdc = []
for field in ["telefono", "fax", "email"]:
value = getattr(self.context, field, "")
if value:
pdc.append({"pdc_type": field, "pdc_value": value})

return [
[
{
"value_punto_contatto": pdc,
}
]
]

0 comments on commit e47690c

Please sign in to comment.