Skip to content

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
folix-01 committed Oct 26, 2023
1 parent bc8371d commit fadc3a9
Show file tree
Hide file tree
Showing 54 changed files with 1,050 additions and 558 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changelog
2.1.4 (unreleased)
------------------

- Convert bookgig types to c.t.
[folix-01]

- Change bookings default limit to 0.
[folix-01]

Expand Down
13 changes: 11 additions & 2 deletions src/redturtle/prenotazioni/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,25 @@
from plone.api.exc import UserNotFoundError
from plone.app.event.base import default_timezone
from six.moves import map
from zope.globalrequest import getRequest
from zope.i18nmessageid import MessageFactory

from redturtle.prenotazioni.utils import is_migration

logger = getLogger("redturtle.prenotazioni")
_ = MessageFactory("redturtle.prenotazioni")

prenotazioniMessageFactory = MessageFactory("redturtle.prenotazioni")
prenotazioniFileLogger = getLogger("redturtle.prenotazioni.file")

try:
from collective.exportimport.interfaces import IMigrationMarker
except ImportError:
IMigrationMarker = None


def is_migration():
"""Returns True if the current reqeust provides the migration marker"""
return IMigrationMarker and IMigrationMarker.providedBy(getRequest())


def tznow():
"""Return a timezone aware now"""
Expand Down
11 changes: 3 additions & 8 deletions src/redturtle/prenotazioni/browser/prenotazioni_context_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,15 +824,10 @@ def booking_type_durations(self):
}
"""

def get_duration(duration):
if isinstance(duration, tuple):
return int(duration[0])
return int(duration)

return {
typ["name"]: get_duration(typ["duration"])
for typ in getattr(self.context, "booking_types", [])
if typ["duration"]
typ.title: typ.duration
for typ in self.context.get_booking_types()
if typ.duration
}

def get_booking_type_duration(self, booking_type):
Expand Down
41 changes: 41 additions & 0 deletions src/redturtle/prenotazioni/content/booking_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
from plone.app.textfield import RichText
from plone.dexterity.content import Item
from plone.supermodel import model
from zope import schema
from zope.interface import implementer

from redturtle.prenotazioni import _


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

duration = schema.Choice(
title=_("Duration value"),
required=True,
vocabulary="redturtle.prenotazioni.VocDurataIncontro",
)

requirements = RichText(
required=False,
title=_("Cosa serve", default="Cosa serve"),
description=_(
"Elencare le informazioni utili per il giorno della prenotazione, come ad esempio i documenti da presentare."
),
)

gates = schema.List(
title=_("gates_label", "Gates"),
description=_("gates_help", default="Put gates here (one per line)."),
required=True,
value_type=schema.Choice(
vocabulary="redturtle.prenotazioni.VocBookingTypeGates"
),
default=[],
)


@implementer(IBookingType)
class BookingType(Item):
""" """
3 changes: 1 addition & 2 deletions src/redturtle/prenotazioni/content/prenotazione.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
from zope.interface import implementer
from zope.schema import ValidationError

from redturtle.prenotazioni import _, datetime_with_tz, tznow
from redturtle.prenotazioni.utils import is_migration
from redturtle.prenotazioni import _, datetime_with_tz, is_migration, tznow

from .prenotazioni_folder import IPrenotazioniFolder

Expand Down
78 changes: 45 additions & 33 deletions src/redturtle/prenotazioni/content/prenotazioni_folder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
from typing import Generator

from collective.z3cform.datagridfield.datagridfield import DataGridFieldFactory
from collective.z3cform.datagridfield.row import DictRow
from plone import api
from plone.app.textfield import RichText
from plone.autoform import directives
from plone.autoform import directives as form
Expand All @@ -11,13 +14,14 @@
from zope import schema
from zope.component import provideAdapter
from zope.i18n import translate
from zope.interface import Interface, Invalid, implementer, invariant, provider
from zope.interface import Invalid, implementer, invariant, provider
from zope.schema.interfaces import IContextAwareDefaultFactory
from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary

from redturtle.prenotazioni import _
from redturtle.prenotazioni.browser.widget import WeekTableOverridesFieldWidget
from redturtle.prenotazioni.config import DEFAULT_VISIBLE_BOOKING_FIELDS
from redturtle.prenotazioni.content.booking_type import BookingType
from redturtle.prenotazioni.content.validators import PauseValidator, checkOverrides

try:
Expand Down Expand Up @@ -123,18 +127,18 @@ class IPauseTableRow(model.Schema):
)


class IBookingTypeRow(Interface):
name = schema.TextLine(title=_("Booking type name"), required=True)
duration = schema.Choice(
title=_("Duration value"),
required=True,
vocabulary="redturtle.prenotazioni.VocDurataIncontro",
)
hidden = schema.Bool(
title=_("Hidden type"),
required=False,
default=False,
)
# class IBookingTypeRow(Interface):
# name = schema.TextLine(title=_("Booking type name"), required=True)
# duration = schema.Choice(
# title=_("Duration value"),
# required=True,
# vocabulary="redturtle.prenotazioni.VocDurataIncontro",
# )
# hidden = schema.Bool(
# title=_("Hidden type"),
# required=False,
# default=False,
# )


@provider(IContextAwareDefaultFactory)
Expand Down Expand Up @@ -441,24 +445,24 @@ def get_options():
),
)

booking_types = schema.List(
title=_("booking_types_label", default="Booking types"),
description=_(
"booking_types_help",
default="Put booking types there (one per line).\n"
"If you do not provide this field, "
"not type selection will be available. "
"If the 'Hidden Type' flag is selected the type will only "
"be available to users with the 'Bookings Manager' permission",
),
value_type=DictRow(schema=IBookingTypeRow),
)
form.widget(
"booking_types",
DataGridFieldFactory,
auto_append=False,
frontendOptions={"widget": "data_grid"},
)
# booking_types = schema.List(
# title=_("booking_types_label", default="Booking types"),
# description=_(
# "booking_types_help",
# default="Put booking types there (one per line).\n"
# "If you do not provide this field, "
# "not type selection will be available. "
# "If the 'Hidden Type' flag is selected the type will only "
# "be available to users with the 'Bookings Manager' permission",
# ),
# value_type=DictRow(schema=IBookingTypeRow),
# )
# form.widget(
# "booking_types",
# DataGridFieldFactory,
# auto_append=False,
# frontendOptions={"widget": "data_grid"},
# )

gates = schema.List(
title=_("gates_label", "Gates"),
Expand Down Expand Up @@ -494,8 +498,6 @@ def data_validation(data):
"""
Needed because is the only way to validate a datagrid field
"""
if not data.booking_types:
raise Invalid(_("You should set at least one booking type."))
for interval in data.week_table:
if interval["morning_start"] and not interval["morning_end"]:
raise Invalid(_("You should set an end time for morning."))
Expand Down Expand Up @@ -765,3 +767,13 @@ def getNotBeforeDays(self):

def getCosaServe(self):
return self.cosa_serve

def get_booking_types(self) -> Generator[BookingType, None, None]:
for booking_type in api.content.find(
portal_type="BookingType",
path={
"query": "/".join(self.getPhysicalPath()),
"depth": 1,
},
):
yield booking_type.getObject()
3 changes: 1 addition & 2 deletions src/redturtle/prenotazioni/events/prenotazione.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
from zope.component import getAdapter, getMultiAdapter, getUtility
from zope.i18n import translate

from redturtle.prenotazioni import _
from redturtle.prenotazioni import _, is_migration
from redturtle.prenotazioni.adapters.booker import IBooker
from redturtle.prenotazioni.interfaces import IPrenotazioneEmailMessage
from redturtle.prenotazioni.utils import is_migration

logger = getLogger(__name__)

Expand Down
4 changes: 4 additions & 0 deletions src/redturtle/prenotazioni/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ class ISerializeToPrenotazioneSearchableItem(Interface):

class IPrenotazioneEmailMessage(Interface):
"""Prenotazione email message"""


class ISerializeToRetrocompattibleJson(Interface):
"""Interface used to cereate the TEMPORARY retrocomattible serializers"""
Loading

0 comments on commit fadc3a9

Please sign in to comment.