diff --git a/src/redturtle/prenotazioni/adapters/booker.py b/src/redturtle/prenotazioni/adapters/booker.py index 9794a78d..3f512408 100644 --- a/src/redturtle/prenotazioni/adapters/booker.py +++ b/src/redturtle/prenotazioni/adapters/booker.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -import json import math from datetime import timedelta from random import choice @@ -192,10 +191,7 @@ def generate_params(self, data, force_gate, duration): if fiscalcode: params["fiscalcode"] = fiscalcode.upper() - additional_fields = data.get("additional_fields", "") - - if additional_fields: - params["additional_fields"] = json.dumps(additional_fields) + params["additional_fields"] = data.get("additional_fields", []) return params diff --git a/src/redturtle/prenotazioni/content/prenotazione.py b/src/redturtle/prenotazioni/content/prenotazione.py index f21392c2..946e05ff 100644 --- a/src/redturtle/prenotazioni/content/prenotazione.py +++ b/src/redturtle/prenotazioni/content/prenotazione.py @@ -4,6 +4,7 @@ import six from DateTime import DateTime from plone import api +from plone import schema as plone_schema from plone.app.event.base import default_timezone from plone.app.z3cform.widget import DatetimeFieldWidget from plone.autoform import directives @@ -188,9 +189,11 @@ class IPrenotazione(model.Schema): # Schema is defined in PrenotaizioneType ad an datagridfield, and here we save the data as an json # in base of selected type - additional_fields = schema.TextLine( + additional_fields = schema.List( title="Additional fields, not editable", required=False, + value_type=plone_schema.JSONField(), + default=[], ) directives.widget( diff --git a/src/redturtle/prenotazioni/restapi/serializers/adapters/prenotazione.py b/src/redturtle/prenotazioni/restapi/serializers/adapters/prenotazione.py index 4c4bd2e3..227199b9 100644 --- a/src/redturtle/prenotazioni/restapi/serializers/adapters/prenotazione.py +++ b/src/redturtle/prenotazioni/restapi/serializers/adapters/prenotazione.py @@ -100,9 +100,7 @@ def __call__(self, *args, **kwargs): "requirements": requirements, "modification_date": json_compatible(self.prenotazione.modified()), "creation_date": json_compatible(self.prenotazione.created()), - "additional_fields": json.loads( - self.prenotazione.additional_fields or "[]" - ), + "additional_fields": self.prenotazione.additional_fields, } @@ -137,9 +135,7 @@ def __call__(self, *args, **kwargs): "email": self.prenotazione.email, "fiscalcode": self.prenotazione.fiscalcode, "phone": self.prenotazione.phone, - "additional_fields": json.loads( - self.prenotazione.additional_fields or "[]" - ), + "additional_fields": self.prenotazione.additional_fields, "staff_notes": self.prenotazione.staff_notes, "company": self.prenotazione.company, "vacation": self.prenotazione.isVacation(), diff --git a/src/redturtle/prenotazioni/restapi/services/booking/update.py b/src/redturtle/prenotazioni/restapi/services/booking/update.py index 3987ee99..7204df5a 100644 --- a/src/redturtle/prenotazioni/restapi/services/booking/update.py +++ b/src/redturtle/prenotazioni/restapi/services/booking/update.py @@ -2,6 +2,7 @@ import json from plone import api +from plone.restapi.deserializer import json_body from plone.restapi.services.content.update import ContentPatch from zExceptions import BadRequest from zope.component import getUtility @@ -19,7 +20,7 @@ def reply(self, *args, **kwargs): return super().reply(*args, **kwargs) def handle_additional_fields(self): - data = json.loads(self.request.get("BODY", b"").decode()) + data = json_body(self.request) booking_folder = self.context.getPrenotazioniFolder() if data: @@ -97,6 +98,4 @@ def handle_additional_fields(self): {"name": field.get("name"), "value": field.get("value")} ) - data["additional_fields"] = json.dumps(additional_fields_data) - self.request["BODY"] = json.dumps(data).encode()