Skip to content

Commit

Permalink
Add hidden bookign types
Browse files Browse the repository at this point in the history
  • Loading branch information
folix-01 committed Oct 10, 2023
1 parent 49c2dc5 commit 51c1939
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 8 deletions.
38 changes: 30 additions & 8 deletions src/redturtle/prenotazioni/content/prenotazioni_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
from redturtle.prenotazioni import _
from redturtle.prenotazioni.browser.widget import WeekTableOverridesFieldWidget
from redturtle.prenotazioni.config import DEFAULT_VISIBLE_BOOKING_FIELDS
from redturtle.prenotazioni.content.validators import PauseValidator, checkOverrides
from redturtle.prenotazioni.content.validators import (
PauseValidator,
checkOverrides,
)

try:
from plone.app.dexterity import textindexer
Expand All @@ -42,7 +45,9 @@ def get_from_form(form, fieldname):
return value
return None

number_of_entry = request.form.get("form.widgets.{}.count".format(fieldname))
number_of_entry = request.form.get(
"form.widgets.{}.count".format(fieldname)
)
data = []
prefix = "form.widgets.{}".format(fieldname)
for counter in range(int(number_of_entry)):
Expand Down Expand Up @@ -82,7 +87,9 @@ class IWeekTableRow(model.Schema):
)

afternoon_start = schema.Choice(
title=_("afternoon_start_label", default="Start time in the afternoon"),
title=_(
"afternoon_start_label", default="Start time in the afternoon"
),
vocabulary="redturtle.prenotazioni.VocOreInizio",
required=False,
)
Expand Down Expand Up @@ -130,6 +137,11 @@ class IBookingTypeRow(Interface):
required=True,
vocabulary="redturtle.prenotazioni.VocDurataIncontro",
)
hidden = schema.Bool(
title=_("Hidden type"),
required=False,
default=False,
)


@provider(IContextAwareDefaultFactory)
Expand Down Expand Up @@ -217,7 +229,9 @@ class IPrenotazioniFolder(model.Schema):
descriptionAgenda = RichText(
required=False,
title=_("Descrizione Agenda", default="Descrizione Agenda"),
description=_("Inserire il testo di presentazione dell'agenda corrente"),
description=_(
"Inserire il testo di presentazione dell'agenda corrente"
),
)

form.mode(descriptionAgenda="display")
Expand All @@ -232,7 +246,9 @@ class IPrenotazioniFolder(model.Schema):

directives.widget(visible_booking_fields=CheckBoxFieldWidget)
visible_booking_fields = schema.List(
title=_("label_visible_booking_fields", default="Visible booking fields"),
title=_(
"label_visible_booking_fields", default="Visible booking fields"
),
description=_(
"help_visible_booking_fields",
"User will not be able to add a booking unless those "
Expand All @@ -250,7 +266,9 @@ class IPrenotazioniFolder(model.Schema):

directives.widget(required_booking_fields=CheckBoxFieldWidget)
required_booking_fields = schema.List(
title=_("label_required_booking_fields", default="Required booking fields"),
title=_(
"label_required_booking_fields", default="Required booking fields"
),
description=_(
"help_required_booking_fields",
"User will not be able to add a booking unless those "
Expand Down Expand Up @@ -500,10 +518,14 @@ def data_validation(data):
raise Invalid(_("You should set a start time for afternoon."))
if interval["morning_start"] and interval["morning_end"]:
if interval["morning_start"] > interval["morning_end"]:
raise Invalid(_("Morning start should not be greater than end."))
raise Invalid(
_("Morning start should not be greater than end.")
)
if interval["afternoon_start"] and interval["afternoon_end"]:
if interval["afternoon_start"] > interval["afternoon_end"]:
raise Invalid(_("Afternoon start should not be greater than end."))
raise Invalid(
_("Afternoon start should not be greater than end.")
)

# TODO: definire o descrivere quando avviee la notifica
# TODO: inserire qui la chiave IO ? o su un config in zope.conf/environment ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<adapter factory=".slot.SlotSerializer" />
<adapter factory=".prenotazione.PrenotazioneSerializer" />
<adapter factory=".prenotazione.PrenotazioneSearchableItemSerializer" />
<adapter factory=".prenotazioni_folder.PrenotazioniFolderSerializer" />

</configure>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
from plone import api
from plone.restapi.interfaces import IFieldSerializer, ISerializeToJson
from plone.restapi.serializer.converters import json_compatible
from zope.component import adapter, getMultiAdapter
from zope.i18n import translate
from zope.interface import implementer
from zope.publisher.interfaces import IRequest
from zope.schema import getFields
from plone.restapi.serializer.dxcontent import SerializeFolderToJson

from redturtle.prenotazioni import logger
from redturtle.prenotazioni.content.prenotazioni_folder import (
IPrenotazioniFolder,
)
from redturtle.prenotazioni.interfaces import (
ISerializeToPrenotazioneSearchableItem,
)
from redturtle.prenotazioni.interfaces import IRedturtlePrenotazioniLayer

from copy import deepcopy


@implementer(ISerializeToJson)
@adapter(IPrenotazioniFolder, IRedturtlePrenotazioniLayer)
class PrenotazioniFolderSerializer(SerializeFolderToJson):
def __call__(self, *args, **kwargs):
res = super().__call__()

for index, type in enumerate(deepcopy(res.get("booking_types", {}))):
if type.get("hidden"):
del res["booking_types"][index]

return res
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# -*- coding: UTF-8 -*-
import email
import unittest
from datetime import date, datetime, timedelta

import pytz
from collective.contentrules.mailfromfield.actions.mail import (
MailFromFieldAction,
)
from plone import api
from plone.app.testing import TEST_USER_ID, setRoles
from plone.contentrules.rule.interfaces import IExecutable
from Products.CMFCore.WorkflowCore import ActionSucceededEvent
from zope.component import getMultiAdapter
from zope.interface import implementer
from zope.interface.interfaces import IObjectEvent
from zope.globalrequest import getRequest
from plone.restapi.interfaces import ISerializeToJson

from redturtle.prenotazioni.adapters.booker import IBooker
from redturtle.prenotazioni.testing import (
REDTURTLE_PRENOTAZIONI_FUNCTIONAL_TESTING,
)


@implementer(IObjectEvent)
class DummyEvent(object):
def __init__(self, object):
self.object = object


class TestEmailToManagers(unittest.TestCase):
layer = REDTURTLE_PRENOTAZIONI_FUNCTIONAL_TESTING

def setUp(self):
self.app = self.layer["app"]
self.portal = self.layer["portal"]
self.mailhost = self.portal.MailHost
self.hidden_type_name = "Type Hidden"
self.not_hidden_type_name = "Type visible"

setRoles(self.portal, TEST_USER_ID, ["Manager"])

self.folder_prenotazioni = api.content.create(
container=self.portal,
type="PrenotazioniFolder",
title="Prenota foo",
description="",
daData=date.today(),
booking_types=[
{
"name": self.hidden_type_name,
"duration": "30",
"hidden": True,
},
{
"name": self.not_hidden_type_name,
"duration": "30",
"hidden": False,
},
],
gates=["Gate A"],
)
week_table = self.folder_prenotazioni.week_table
for data in week_table:
data["morning_start"] = "0700"
data["morning_end"] = "1000"
self.folder_prenotazioni.week_table = week_table

def test_hidden_type_is_not_shown(self):
self.assertNotIn(
self.hidden_type_name,
[
i["name"]
for i in getMultiAdapter(
(self.folder_prenotazioni, getRequest()), ISerializeToJson
)()["booking_types"]
],
)

def test_not_hidden_type_is_being_shown(self):
self.assertIn(
self.not_hidden_type_name,
[
i["name"]
for i in getMultiAdapter(
(self.folder_prenotazioni, getRequest()), ISerializeToJson
)()["booking_types"]
],
)

0 comments on commit 51c1939

Please sign in to comment.