Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit f748cd7
Author: Roman <[email protected]>
Date:   Fri Oct 27 17:49:34 2023 +0200

    Refactor the @@prenotazioni_context_state.get_booking_type_duration method

commit d1209e7
Author: Roman <[email protected]>
Date:   Thu Oct 26 15:10:41 2023 +0200

    Refactor

commit 8da8dea
Author: Roman <[email protected]>
Date:   Thu Oct 26 15:05:56 2023 +0200

    Refactor

commit 5aac9ce
Author: Roman <[email protected]>
Date:   Thu Oct 26 14:37:37 2023 +0200

    Fix typos

commit 190b0ca
Author: Roman <[email protected]>
Date:   Thu Oct 19 16:54:46 2023 +0200

    Initial implementation
  • Loading branch information
folix-01 committed Oct 30, 2023
1 parent 04145f0 commit 323f603
Show file tree
Hide file tree
Showing 54 changed files with 1,456 additions and 1,066 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ Changelog
------------------

- Allow Bookings Manager to create, move the bookings and create the vacations.
- Convert bookgig types to c.t.
- Convert booking types to c.t.
[folix-01]

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

- Fix Bookings Manager permission in according to expected behavior
[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 request provides the migration marker"""
return IMigrationMarker and IMigrationMarker.providedBy(getRequest())


def tznow():
"""Return a timezone aware now"""
Expand Down
26 changes: 11 additions & 15 deletions src/redturtle/prenotazioni/browser/prenotazioni_context_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from redturtle.prenotazioni.adapters.conflict import IConflictManager
from redturtle.prenotazioni.adapters.slot import BaseSlot, ISlot
from redturtle.prenotazioni.config import PAUSE_PORTAL_TYPE, PAUSE_SLOT
from redturtle.prenotazioni.content.booking_type import BookingType
from redturtle.prenotazioni.content.pause import Pause
from redturtle.prenotazioni.utilities.dateutils import hm2DT, hm2seconds
from redturtle.prenotazioni.utilities.urls import urlify
Expand Down Expand Up @@ -824,27 +825,22 @@ 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):
"""Return the seconds for this booking_type"""
if isinstance(booking_type, dict):
return int(booking_type["duration"]) * 60
if isinstance(booking_type, six.string_types) and not isinstance(
booking_type, six.text_type
):
booking_type = booking_type
if type(booking_type) is BookingType:
return booking_type.duration * 60

if type(booking_type) is str:
return self.booking_type_durations.get(booking_type, 1)

# XXX: se il booking_type non esiste, ritorna 1 minuto, è corretto ????
return self.booking_type_durations.get(booking_type, 1)
return 1

@memoize
def booking_types_bookability(self, booking_date):
Expand Down
42 changes: 42 additions & 0 deletions src/redturtle/prenotazioni/content/booking_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- 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=_("booking_type_duration_label", default="Duration value"),
required=True,
vocabulary="redturtle.prenotazioni.VocDurataIncontro",
)

requirements = RichText(
required=False,
title=_("booking_type_requirements_labled", default="Requirements"),
description=_(
"booking_type_requirements_help",
default="List of requirements to recieve the service",
),
)

gates = schema.List(
title=_("gates_label", default="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
43 changes: 7 additions & 36 deletions src/redturtle/prenotazioni/content/prenotazioni_folder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
from typing import Generator

from collective.z3cform.datagridfield.datagridfield import DataGridFieldFactory
from collective.z3cform.datagridfield.row import DictRow
from plone.app.textfield import RichText
Expand All @@ -11,13 +13,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,20 +126,6 @@ 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,
)


@provider(IContextAwareDefaultFactory)
def notify_on_submit_subject_default_factory(context):
return getattr(context, "translate", translate)(
Expand Down Expand Up @@ -441,25 +430,6 @@ 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"},
)

gates = schema.List(
title=_("gates_label", "Gates"),
description=_("gates_help", default="Put gates here (one per line)."),
Expand Down Expand Up @@ -494,8 +464,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 +733,6 @@ def getNotBeforeDays(self):

def getCosaServe(self):
return self.cosa_serve

def get_booking_types(self) -> Generator[BookingType, None, None]:
return self.listFolderContents(contentFilter={"portal_type": "BookingType"})
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 ISerializeToRetroCompatibleJson(Interface):
"""Interface used to cereate the TEMPORARY retrocomattible serializers"""
Loading

0 comments on commit 323f603

Please sign in to comment.