Skip to content

Commit

Permalink
Booking additional fields (#216)
Browse files Browse the repository at this point in the history
* Initial commit

* Intermediate commit

* Intermediate commit

* Tests + doc

* Fix readme

* translations

* Readme

* Remove unused code

* Update README.rst

* typo + traduzioni

* test for patch method

* label field for additional_fields + typos

* Customize Prenotazione update endpoint

* Update README.rst

conformity

* tests

* black

* additional_fields must return an object instead of a string

* additional_fields must return an object instead of a string

* tests

* Update README.rst

Co-authored-by: Andrea Cecchi <[email protected]>

* Update README.rst

Co-authored-by: Andrea Cecchi <[email protected]>

* Update README.rst

* Update README.rst

Co-authored-by: Andrea Cecchi <[email protected]>

* Update README.rst

Co-authored-by: Andrea Cecchi <[email protected]>

* CEKK requirements

* Required additional fields

* Readme

* Intermediate commit

* Fix logics

* fix update validation additional fields

---------

Co-authored-by: Mauro Amico <[email protected]>
Co-authored-by: Andrea Cecchi <[email protected]>
Co-authored-by: Roman Kysil <[email protected]>
  • Loading branch information
4 people authored Oct 9, 2024
1 parent c76a3bd commit a89b95c
Show file tree
Hide file tree
Showing 24 changed files with 826 additions and 79 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Changelog
2.7.7 (2024-08-22)
------------------

- Booking additional fields.
[folix-01]

- Bookings details help text in `Tipologia prenotazione`.
[folix-01]

Expand Down Expand Up @@ -49,7 +52,7 @@ Changelog
2.7.3 (2024-06-14)
------------------

- With an experimental envionment `SEE_OWN_ANONYMOUS_BOOKINGS` set to `True`, the endpoint will return
- With an experimental envionment `SEE_OWN_ANONYMOUS_BOOKINGS` set to `True`, the endpoint will return
also the bookings created by anonymous users with the same fiscalcode of the authenticated user.
[mamico]

Expand Down
61 changes: 61 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ Response::
{
"duration": "60",
"name": "Rilascio CIE"
"booking_additional_fields_schema": {"name": "field1", "description": "Field number 1", "type": "text", "required": true}
}
]
},
Expand Down Expand Up @@ -703,6 +704,66 @@ Response::
]
}

Booking Additional Fields
=========================

You can also create the addtional fields for your booking, you just need to compile
them in your PrenotazioneType.
And they will appear in the ["booking_types"]["booking_additional_fields_schema"]
in your booking schema so you can compile them for your booking in this way:

@booking
--------

Create booking with an additional field

POST
~~~~

This endpoint allows to create a new booking.

Example::

curl http://localhost:8080/Plone/++api++/<booking_folder_path>/@booking \
-X POST \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"booking_date": "2023-05-23T09:00:00+02:00",
"booking_type": "Type x",
"fields": [
{"name": "fullname", "value": "Mario Rossi"},
{"name": "email", "value": "mario.rossi@example"}
],
"additional_fields": [{"name": "field1", "value": "Addional field text"}]
}'

Response::

{
"booking_code": "17E3E6",
"booking_date": "2023-05-22T09:09:00",
"booking_expiration_date": "2023-05-22T09:10:00",
"booking_type": "Type x",
"company": null,
"cosa_serve": null,
"description": "",
"email": "mario.rossi@example",
"fiscalcode": "",
"gate": "gate 1",
"id": "mario-rossi-1",
"phone": "",
"staff_notes": null,
"title": "Mario Rossi",
"additional_fields": [{"name": "field1", "value": "Addional field text"}]
}

Available types are
-------------------

- **text**: Text which uses default zope.schema.TextLine validation


Special Views
==============

Expand Down
3 changes: 3 additions & 0 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ extends =
eggs +=
Products.PrintingMailHost
design.plone.ioprenoto

[versions]
docutils=0.21.2
2 changes: 2 additions & 0 deletions src/redturtle/prenotazioni/adapters/booker.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ def generate_params(self, data, force_gate, duration):
if fiscalcode:
params["fiscalcode"] = fiscalcode.upper()

params["additional_fields"] = data.get("additional_fields", [])

return params

def _create(self, data, duration=-1, force_gate=""):
Expand Down
10 changes: 10 additions & 0 deletions 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 @@ -186,6 +187,15 @@ class IPrenotazione(model.Schema):
required=False, title=_("label_booking_staff_notes", "Staff notes")
)

# Schema is defined in PrenotaizioneType as an datagridfield, and here we save the data as an json
# in base of selected type
additional_fields = schema.List(
title="Additional fields, not editable",
required=False,
value_type=plone_schema.JSONField(),
default=[],
)

directives.widget(
"booking_date",
DatetimeFieldWidget,
Expand Down
69 changes: 68 additions & 1 deletion src/redturtle/prenotazioni/content/prenotazione_type.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
from collective.z3cform.datagridfield.datagridfield import DataGridFieldFactory
from collective.z3cform.datagridfield.row import DictRow
from plone.app.textfield import RichText
from plone.autoform import directives as form
from plone.dexterity.content import Item
from plone.supermodel import model
from zope import schema
Expand All @@ -8,6 +11,40 @@
from redturtle.prenotazioni import _


class IBookingAdditionalFieldsSchema(model.Schema):
# TODO: definire un validatore per fare in modo che il nome sia unico e
# che non contenga caratteri strani non ammessi
name = schema.TextLine(
title=_("booking_additional_field_name", default="id"),
required=True,
default="",
description=_(
"booking_additional_field_name_help",
default="Additional field id must be unique",
),
)
label = schema.TextLine(
title=_("booking_additional_field_label", default="Label"),
required=True,
default="",
)
type = schema.Choice(
title=_("booking_additional_field_type", default="Tipo"),
required=True,
vocabulary="redturtle.prenotazioni.booking_additional_fields_types",
)
required = schema.Bool(
title=_("booking_additional_field_required", default="Required"),
required=False,
default=False,
)
description = schema.TextLine(
title=_("booking_additional_field_description", default="Descrizione"),
required=False,
default="",
)


class IPrenotazioneType(model.Schema):
"""Marker interface and Dexterity Python Schema for Prenotazione"""

Expand Down Expand Up @@ -38,13 +75,43 @@ class IPrenotazioneType(model.Schema):

booking_details_help_text = RichText(
required=False,
title=_("booking_details_help_text_label", default="Bookign detail help text"),
title=_("booking_details_help_text_label", default="Booking detail help text"),
description=_(
"booking_details_help_text_label_help",
default='This field will be visualized as "Details" helptext during the booking steps',
),
)

booking_additional_fields_schema = schema.List(
title=_(
"booking_additional_fields_schema_title",
default="Booking additional fields schema",
),
default=[],
value_type=DictRow(schema=IBookingAdditionalFieldsSchema),
description=_(
"booking_additional_fields_schema_description",
default="This schema is being used for the additional booking fields",
),
required=False,
)

form.widget(
"booking_additional_fields_schema",
DataGridFieldFactory,
frontendOptions={
"widget": "data_grid",
},
)

model.fieldset(
"additional_fields",
label=_("booking_additional_fields_schema_title"),
fields=[
"booking_additional_fields_schema",
],
)


@implementer(IPrenotazioneType)
class PrenotazioneType(Item):
Expand Down
2 changes: 1 addition & 1 deletion src/redturtle/prenotazioni/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class IBookingAPPIoMessage(Interface):


class IBookingNotificatorSupervisorUtility(Interface):
"""Bookign notificator supervisor
"""Booking notificator supervisor
basically contains the business logic to allow/disallow the
notification sending to gateways
"""
Loading

0 comments on commit a89b95c

Please sign in to comment.