[gen] Calendar field: more work on timeslots.
This commit is contained in:
parent
85007ced67
commit
9934f6d7c9
|
@ -27,6 +27,12 @@ class Timeslot:
|
||||||
# that can be assigned to this slot.
|
# that can be assigned to this slot.
|
||||||
self.eventTypes = eventTypes # "None" means "all"
|
self.eventTypes = eventTypes # "None" means "all"
|
||||||
|
|
||||||
|
def allows(self, eventType):
|
||||||
|
'''It is allowed to have an event of p_eventType in this timeslot?'''
|
||||||
|
# self.eventTypes being None means that no restriction applies
|
||||||
|
if not self.eventTypes: return True
|
||||||
|
return eventType in self.eventTypes
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
class Other:
|
class Other:
|
||||||
'''Identifies a Calendar field that must be shown within another Calendar
|
'''Identifies a Calendar field that must be shown within another Calendar
|
||||||
|
@ -97,6 +103,10 @@ class Calendar(Field):
|
||||||
Other = Other
|
Other = Other
|
||||||
Event = Event
|
Event = Event
|
||||||
IterSub = IterSub
|
IterSub = IterSub
|
||||||
|
# Error messages
|
||||||
|
TIMESLOT_USED = 'An event is already defined at this timeslot.'
|
||||||
|
DAY_FULL = 'No more place for adding this event.'
|
||||||
|
|
||||||
|
|
||||||
timelineBgColors = {'Fri': '#dedede', 'Sat': '#c0c0c0', 'Sun': '#c0c0c0'}
|
timelineBgColors = {'Fri': '#dedede', 'Sat': '#c0c0c0', 'Sun': '#c0c0c0'}
|
||||||
|
|
||||||
|
@ -249,13 +259,13 @@ class Calendar(Field):
|
||||||
|
|
||||||
<!-- Delete successive events ? -->
|
<!-- Delete successive events ? -->
|
||||||
<div class="discreet" style="margin-bottom: 10px"
|
<div class="discreet" style="margin-bottom: 10px"
|
||||||
id=":prefix + 'DelNextEvent'">
|
id=":prefix + 'DelNextEvent'"
|
||||||
<input type="checkbox" name="deleteNext_cb"
|
var="cbId=prefix + '_cb'; hdId=prefix + '_hd'">
|
||||||
id=":prefix + '_cb'"
|
<input type="checkbox" name="deleteNext_cb" id=":cbId"
|
||||||
onClick=":'toggleCheckbox(%s, %s)' % \
|
onClick=":'toggleCheckbox(%s, %s)' % (q(cbId), q(hdId))"/>
|
||||||
(q('%s_cb' % prefix), q('%s_hd' % prefix))"/>
|
<input type="hidden" id=":hdId" name="deleteNext"/>
|
||||||
<input type="hidden" id=":prefix + '_hd'" name="deleteNext"/>
|
<label lfor=":cbId"
|
||||||
<span>:_('del_next_events')</span>
|
style="text-transform: none">:_('del_next_events')</label>
|
||||||
</div>
|
</div>
|
||||||
<input type="button" value=":_('yes')"
|
<input type="button" value=":_('yes')"
|
||||||
onClick=":'triggerCalendarEvent(%s, %s, %s, %s)' % \
|
onClick=":'triggerCalendarEvent(%s, %s, %s, %s)' % \
|
||||||
|
@ -905,6 +915,41 @@ class Calendar(Field):
|
||||||
else:
|
else:
|
||||||
return DateTime() # Now
|
return DateTime() # Now
|
||||||
|
|
||||||
|
def checkCreateEvent(self, obj, eventType, timeslot, events):
|
||||||
|
'''Checks if one may create an event of p_eventType in p_timeslot.
|
||||||
|
Events already defined at p_date are in p_events. If the creation is
|
||||||
|
not possible, an error message is returned.'''
|
||||||
|
# The following errors should not occur if we have a normal user behind
|
||||||
|
# the ui.
|
||||||
|
for e in events:
|
||||||
|
if e.timeslot == timeslot: return Calendar.TIMESLOT_USED
|
||||||
|
elif e.timeslot == 'main': return Calendar.DAY_FULL
|
||||||
|
if events and (timeslot == 'main'): return Calendar.DAY_FULL
|
||||||
|
# Get the Timeslot and check if, at this timeslot, it is allowed to
|
||||||
|
# create an event of p_eventType.
|
||||||
|
for slot in self.timeslots:
|
||||||
|
if slot.id == timeslot:
|
||||||
|
# I have the timeslot
|
||||||
|
if not slot.allows(eventType):
|
||||||
|
_ = obj.translate
|
||||||
|
return _('timeslot_misfit', mapping={'slot': timeslot})
|
||||||
|
|
||||||
|
def mergeEvent(self, eventType, timeslot, events):
|
||||||
|
'''If, after adding an event of p_eventType, all timeslots are used with
|
||||||
|
events of the same type, we can merge them and create a single event
|
||||||
|
of this type in the main timeslot.'''
|
||||||
|
# When defining an event in the main timeslot, no merge is needed
|
||||||
|
if timeslot == 'main': return
|
||||||
|
# Merge is required when all non-main timeslots are used by events of
|
||||||
|
# the same type.
|
||||||
|
if len(events) != (len(self.timeslots)-2): return
|
||||||
|
for event in events:
|
||||||
|
if event.eventType != eventType: return
|
||||||
|
# If we are here, we must merge all events
|
||||||
|
del events[:]
|
||||||
|
events.append(Event(eventType))
|
||||||
|
return True
|
||||||
|
|
||||||
def createEvent(self, obj, date, timeslot, eventType=None, eventSpan=None,
|
def createEvent(self, obj, date, timeslot, eventType=None, eventSpan=None,
|
||||||
handleEventSpan=True):
|
handleEventSpan=True):
|
||||||
'''Create a new event in the calendar, at some p_date (day).
|
'''Create a new event in the calendar, at some p_date (day).
|
||||||
|
@ -941,20 +986,18 @@ class Calendar(Field):
|
||||||
else:
|
else:
|
||||||
daysDict[day] = events = PersistentList()
|
daysDict[day] = events = PersistentList()
|
||||||
# Return an error if the creation cannot occur
|
# Return an error if the creation cannot occur
|
||||||
for e in events:
|
error = self.checkCreateEvent(obj, eventType, timeslot, events)
|
||||||
if e.timeslot == timeslot:
|
if error: return error
|
||||||
return 'An event for this timeslot already exist'
|
# Merge this event with others when relevant
|
||||||
elif e.timeslot == 'main':
|
merged = self.mergeEvent(eventType, timeslot, events)
|
||||||
return 'No more place for adding this event'
|
if not merged:
|
||||||
if events and (timeslot == 'main'):
|
# Create and store the event
|
||||||
return 'No more place (2) for adding this event'
|
events.append(Event(eventType, timeslot))
|
||||||
# Create and store the event
|
# Sort events in the order of timeslots
|
||||||
events.append(Event(eventType, timeslot))
|
if len(events) > 1:
|
||||||
# Sort events in the order of timeslots
|
timeslots = [slot.id for slot in self.timeslots]
|
||||||
timeslots = [slot.id for slot in self.timeslots]
|
events.data.sort(key=lambda e: timeslots.index(e.timeslot))
|
||||||
if len(events) > 1:
|
events._p_changed = 1
|
||||||
events.data.sort(key=lambda e: timeslots.index(e.timeslot))
|
|
||||||
events._p_changed = 1
|
|
||||||
# Span the event on the successive days if required
|
# Span the event on the successive days if required
|
||||||
if handleEventSpan and eventSpan:
|
if handleEventSpan and eventSpan:
|
||||||
nbOfDays = min(int(eventSpan), self.maxEventLength)
|
nbOfDays = min(int(eventSpan), self.maxEventLength)
|
||||||
|
|
|
@ -723,6 +723,10 @@ msgstr ""
|
||||||
msgid "timeslot_main"
|
msgid "timeslot_main"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#. Default: "Cannot create such an event in the ${slot} slot."
|
||||||
|
msgid "timeslot_misfit"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#. Default: "Inserted by ${userName}"
|
#. Default: "Inserted by ${userName}"
|
||||||
msgid "history_insert"
|
msgid "history_insert"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
|
@ -723,6 +723,10 @@ msgstr ""
|
||||||
msgid "timeslot_main"
|
msgid "timeslot_main"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#. Default: "Cannot create such an event in the ${slot} slot."
|
||||||
|
msgid "timeslot_misfit"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#. Default: "Inserted by ${userName}"
|
#. Default: "Inserted by ${userName}"
|
||||||
msgid "history_insert"
|
msgid "history_insert"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
|
@ -723,6 +723,10 @@ msgstr ""
|
||||||
msgid "timeslot_main"
|
msgid "timeslot_main"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#. Default: "Cannot create such an event in the ${slot} slot."
|
||||||
|
msgid "timeslot_misfit"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#. Default: "Inserted by ${userName}"
|
#. Default: "Inserted by ${userName}"
|
||||||
msgid "history_insert"
|
msgid "history_insert"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
|
@ -724,6 +724,10 @@ msgstr "Timeslot"
|
||||||
msgid "timeslot_main"
|
msgid "timeslot_main"
|
||||||
msgstr "All day"
|
msgstr "All day"
|
||||||
|
|
||||||
|
#. Default: "Cannot create such an event in the ${slot} slot."
|
||||||
|
msgid "timeslot_misfit"
|
||||||
|
msgstr "Cannot create such an event in the ${slot} slot."
|
||||||
|
|
||||||
#. Default: "Inserted by ${userName}"
|
#. Default: "Inserted by ${userName}"
|
||||||
msgid "history_insert"
|
msgid "history_insert"
|
||||||
msgstr "Inserted by ${userName}"
|
msgstr "Inserted by ${userName}"
|
||||||
|
|
|
@ -723,6 +723,10 @@ msgstr ""
|
||||||
msgid "timeslot_main"
|
msgid "timeslot_main"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#. Default: "Cannot create such an event in the ${slot} slot."
|
||||||
|
msgid "timeslot_misfit"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#. Default: "Inserted by ${userName}"
|
#. Default: "Inserted by ${userName}"
|
||||||
msgid "history_insert"
|
msgid "history_insert"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
|
@ -724,6 +724,10 @@ msgstr "Plage horaire"
|
||||||
msgid "timeslot_main"
|
msgid "timeslot_main"
|
||||||
msgstr "Toute la journée"
|
msgstr "Toute la journée"
|
||||||
|
|
||||||
|
#. Default: "Cannot create such an event in the ${slot} slot."
|
||||||
|
msgid "timeslot_misfit"
|
||||||
|
msgstr "Impossible de créer ce type d'événement dans la plage horaire ${slot}."
|
||||||
|
|
||||||
#. Default: "Inserted by ${userName}"
|
#. Default: "Inserted by ${userName}"
|
||||||
msgid "history_insert"
|
msgid "history_insert"
|
||||||
msgstr "Inséré par ${userName}"
|
msgstr "Inséré par ${userName}"
|
||||||
|
|
|
@ -723,6 +723,10 @@ msgstr ""
|
||||||
msgid "timeslot_main"
|
msgid "timeslot_main"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#. Default: "Cannot create such an event in the ${slot} slot."
|
||||||
|
msgid "timeslot_misfit"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#. Default: "Inserted by ${userName}"
|
#. Default: "Inserted by ${userName}"
|
||||||
msgid "history_insert"
|
msgid "history_insert"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
|
@ -723,6 +723,10 @@ msgstr ""
|
||||||
msgid "timeslot_main"
|
msgid "timeslot_main"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#. Default: "Cannot create such an event in the ${slot} slot."
|
||||||
|
msgid "timeslot_misfit"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#. Default: "Inserted by ${userName}"
|
#. Default: "Inserted by ${userName}"
|
||||||
msgid "history_insert"
|
msgid "history_insert"
|
||||||
msgstr "Ingevuld door ${userName}"
|
msgstr "Ingevuld door ${userName}"
|
||||||
|
|
Loading…
Reference in a new issue