Skip to content

Commit

Permalink
Merge branch 'main' into manager_dates_restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
mamico authored Oct 18, 2024
2 parents c6ab84e + 8bc006f commit 4454631
Show file tree
Hide file tree
Showing 26 changed files with 880 additions and 97 deletions.
18 changes: 16 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Changelog
=========


2.7.8 (unreleased)
------------------
2.7.10 (unreleased)
-------------------

- Apply validity dates restrictions for the Bookings Manger if selected flag 'apply_date_restrictions_to_manager'.
[folix-01]
Expand All @@ -12,6 +12,20 @@ Changelog
[folix-01]


2.7.9 (2024-10-09)
------------------

- Booking additional fields.
[folix-01]


2.7.8 (2024-09-13)
------------------

- Remove csrf protection from send reminder endpoint.
[folix-01]


2.7.7 (2024-08-22)
------------------

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
2 changes: 2 additions & 0 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ eggs +=
Products.PrintingMailHost
design.plone.ioprenoto

[versions]
docutils=0.21.2
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setup(
name="redturtle.prenotazioni",
version="2.7.8.dev0",
version="2.7.10.dev0",
description="An add-on for Plone",
long_description=long_description,
# Get more from https://pypi.python.org/pypi?%3Aaction=list_classifiers
Expand Down
2 changes: 2 additions & 0 deletions src/redturtle/prenotazioni/adapters/booker.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def booking_folder_provides_current_behavior(booking):
def send_email_notification_on_transition(context, event) -> None:
if not booking_folder_provides_current_behavior(context):
return

booking_folder = context.getPrenotazioniFolder()
flags = booking_folder.get_notification_flags()

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 4454631

Please sign in to comment.