Skip to content

Commit

Permalink
Fix booking duration converison
Browse files Browse the repository at this point in the history
  • Loading branch information
folix-01 committed Oct 31, 2023
1 parent 8ce51e6 commit d3d4b34
Showing 1 changed file with 35 additions and 13 deletions.
48 changes: 35 additions & 13 deletions src/redturtle/prenotazioni/browser/prenotazioni_context_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def user_can_manage(self):
"""States if the authenticated user can manage this context"""
if self.is_anonymous:
return False
return api.user.has_permission("Modify portal content", obj=self.context)
return api.user.has_permission(
"Modify portal content", obj=self.context
)

@property
@memoize
Expand Down Expand Up @@ -252,7 +254,8 @@ def remembered_params(self):
and key.startswith("form.")
and not key.startswith("form.action")
and key not in ("form.booking_date",)
or key in ("disable_plone.leftcolumn", "disable_plone.rightcolumn")
or key
in ("disable_plone.leftcolumn", "disable_plone.rightcolumn")
)
)
for key, value in six.iteritems(params):
Expand Down Expand Up @@ -513,7 +516,9 @@ def get_day_intervals(self, day):
"morning": BaseSlot(
start=morning_start, stop=morning_end, gate="", date=day
),
"break": BaseSlot(start=break_start, stop=break_stop, gate="", date=day),
"break": BaseSlot(
start=break_start, stop=break_stop, gate="", date=day
),
"afternoon": BaseSlot(
start=afternoon_start, stop=afternoon_end, gate="", date=day
),
Expand Down Expand Up @@ -542,7 +547,9 @@ def weektable_boundaries(self):
for key, value in six.iteritems(boundaries):
boundaries[key] = hm2seconds(value)
return {
"morning": BaseSlot(boundaries["morning_start"], boundaries["morning_end"]),
"morning": BaseSlot(
boundaries["morning_start"], boundaries["morning_end"]
),
"afternoon": BaseSlot(
boundaries["afternoon_start"], boundaries["afternoon_end"]
),
Expand Down Expand Up @@ -630,11 +637,15 @@ def get_pauses_in_day_folder(self, booking_date):

weekday = booking_date.weekday()

today_pauses = [row for row in pause_table if row["day"] == str(weekday)]
today_pauses = [
row for row in pause_table if row["day"] == str(weekday)
]
pauses = []
for pause in today_pauses:
pause = Pause(
start=pause["pause_start"][:2] + ":" + pause["pause_start"][2:],
start=pause["pause_start"][:2]
+ ":"
+ pause["pause_start"][2:],
stop=pause["pause_end"][:2] + ":" + pause["pause_end"][2:],
date=booking_date,
)
Expand All @@ -657,7 +668,9 @@ def get_existing_slots_in_day_folder(self, booking_date):
def get_busy_slots_in_stormynight(self, booking_date):
"""This will show the slots that will not show elsewhere"""
morning_slots = self.get_busy_slots_in_period(booking_date, "morning")
afternoon_slots = self.get_busy_slots_in_period(booking_date, "afternoon")
afternoon_slots = self.get_busy_slots_in_period(
booking_date, "afternoon"
)
all_slots = self.get_existing_slots_in_day_folder(booking_date)
return sorted(
[
Expand Down Expand Up @@ -715,7 +728,9 @@ def get_busy_slots(self, booking_date, period="day"):
for slot in slots:
if slot.context.portal_type == PAUSE_PORTAL_TYPE:
for gate in self.get_gates(booking_date):
slots_by_gate.setdefault(gate.get("name", ""), []).append(slot)
slots_by_gate.setdefault(gate.get("name", ""), []).append(
slot
)
else:
slots_by_gate.setdefault(slot.gate, []).append(slot)
return slots_by_gate
Expand Down Expand Up @@ -745,10 +760,14 @@ def get_free_slots(self, booking_date, period="day"):
availability.setdefault(gate, [])
all_gate_slots = slots_by_gate.get(gate, [])
pauses_slots = [
x for x in all_gate_slots if x.context.portal_type == PAUSE_PORTAL_TYPE
x
for x in all_gate_slots
if x.context.portal_type == PAUSE_PORTAL_TYPE
]
booking_slots = [
x for x in all_gate_slots if x.context.portal_type != PAUSE_PORTAL_TYPE
x
for x in all_gate_slots
if x.context.portal_type != PAUSE_PORTAL_TYPE
]
gate_slots = []
gate_slots.extend(pauses_slots)
Expand Down Expand Up @@ -784,7 +803,8 @@ def get_freebusy_slots(self, booking_date, period="day"):
busy = self.get_busy_slots(booking_date, period)
keys = set(list(free.keys()) + list(busy.keys()))
return dict(
(key, sorted(free.get(key, []) + busy.get(key, []))) for key in keys
(key, sorted(free.get(key, []) + busy.get(key, [])))
for key in keys
)

def get_anonymous_slots(self, booking_date, period="day"):
Expand Down Expand Up @@ -833,11 +853,12 @@ def booking_type_durations(self):

def get_booking_type_duration(self, booking_type):
"""Return the seconds for this booking_type"""

if type(booking_type) is BookingType:
return int(booking_type.duration) * 60

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

# XXX: se il booking_type non esiste, ritorna 1 minuto, è corretto ????
return 1
Expand Down Expand Up @@ -892,7 +913,8 @@ def get_first_slot(self, booking_type, booking_date, period="day"):
for slots in six.itervalues(availability):
for slot in slots:
if len(slot) >= duration and (
booking_date > self.first_bookable_date or slot.start() >= hm_now
booking_date > self.first_bookable_date
or slot.start() >= hm_now
):
good_slots.append(slot)
if not good_slots:
Expand Down

0 comments on commit d3d4b34

Please sign in to comment.