[gen] Calendar field: prepared the timeline to accept multiple events in a single cell.

This commit is contained in:
Gaetan Delannay 2015-03-04 17:00:39 +01:00
parent 722c5e28c7
commit 93b2740906

View file

@ -64,18 +64,20 @@ class Other:
# month rendering) in the calendar integrating this one. # month rendering) in the calendar integrating this one.
self.color = color self.color = color
def getEventsAt(self, res, calendar, date, eventNames, inTimeline, colors): def getEventsInfoAt(self, res, calendar, date, eventNames, inTimeline,
colors):
'''Gets the events defined at p_date in this calendar and append them in '''Gets the events defined at p_date in this calendar and append them in
p_res.''' p_res.'''
events = self.field.getEventsAt(self.obj.o, date) events = self.field.getEventsAt(self.obj.o, date)
if not events: return if not events: return
eventType = events[0].eventType for event in events:
eventType = event.eventType
# Gathered info will be an Object instance # Gathered info will be an Object instance
info = Object(color=self.color) info = Object(event=event, color=self.color)
if inTimeline: if inTimeline:
# Get the background color for this cell if it has been # Get the background color for this cell if it has been defined,
# defined, or (a) nothing if showUncolored is False, (b) a # or (a) nothing if showUncolored is False, (b) a tooltipped dot
# tooltipped dot else. # else.
if eventType in colors: if eventType in colors:
info.bgColor = colors[eventType] info.bgColor = colors[eventType]
info.symbol = None info.symbol = None
@ -134,7 +136,6 @@ class Calendar(Field):
TIMESLOT_USED = 'An event is already defined at this timeslot.' TIMESLOT_USED = 'An event is already defined at this timeslot.'
DAY_FULL = 'No more place for adding this event.' DAY_FULL = 'No more place for adding this event.'
timelineBgColors = {'Fri': '#dedede', 'Sat': '#c0c0c0', 'Sun': '#c0c0c0'} timelineBgColors = {'Fri': '#dedede', 'Sat': '#c0c0c0', 'Sun': '#c0c0c0'}
# For timeline rendering, the row displaying month names # For timeline rendering, the row displaying month names
@ -910,10 +911,12 @@ class Calendar(Field):
res = [] res = []
isTimeline = render == 'timeline' isTimeline = render == 'timeline'
if isinstance(others, Other): if isinstance(others, Other):
others.getEventsAt(res, self, date, eventNames, isTimeline, colors) others.getEventsInfoAt(res, self, date, eventNames, isTimeline,
colors)
else: else:
for other in sutils.IterSub(others): for other in sutils.IterSub(others):
other.getEventsAt(res, self, date, eventNames,isTimeline,colors) other.getEventsInfoAt(res, self, date, eventNames, isTimeline,
colors)
return res return res
def getEventName(self, obj, eventType): def getEventName(self, obj, eventType):
@ -1141,8 +1144,7 @@ class Calendar(Field):
def getCellStyle(self, obj, date, render, events): def getCellStyle(self, obj, date, render, events):
'''Gets the cell style to apply to the cell corresponding to p_date.''' '''Gets the cell style to apply to the cell corresponding to p_date.'''
if render != 'timeline': return '' # Currently, for timelines only if render != 'timeline': return '' # Currently, for timelines only
if not events: return '' if not events or (len(events) > 1): return ''
# Currently, a single event is allowed
event = events[0] event = events[0]
return event.bgColor and ('background-color: %s' % event.bgColor) or '' return event.bgColor and ('background-color: %s' % event.bgColor) or ''