Skip to content

Commit

Permalink
CEKK requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
folix-01 committed Aug 29, 2024
1 parent 582e4b6 commit 321ec12
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
6 changes: 1 addition & 5 deletions src/redturtle/prenotazioni/adapters/booker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
import json
import math
from datetime import timedelta
from random import choice
Expand Down Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion src/redturtle/prenotazioni/content/prenotazione.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}


Expand Down Expand Up @@ -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(),
Expand Down
5 changes: 2 additions & 3 deletions src/redturtle/prenotazioni/restapi/services/booking/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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()

0 comments on commit 321ec12

Please sign in to comment.