[gen] Calendar field: prepared the timeline to accept multiple events in a single cell.
This commit is contained in:
parent
722c5e28c7
commit
93b2740906
|
@ -64,32 +64,34 @@ 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:
|
||||||
# Gathered info will be an Object instance
|
eventType = event.eventType
|
||||||
info = Object(color=self.color)
|
# Gathered info will be an Object instance
|
||||||
if inTimeline:
|
info = Object(event=event, color=self.color)
|
||||||
# Get the background color for this cell if it has been
|
if inTimeline:
|
||||||
# defined, or (a) nothing if showUncolored is False, (b) a
|
# Get the background color for this cell if it has been defined,
|
||||||
# tooltipped dot else.
|
# or (a) nothing if showUncolored is False, (b) a tooltipped dot
|
||||||
if eventType in colors:
|
# else.
|
||||||
info.bgColor = colors[eventType]
|
if eventType in colors:
|
||||||
info.symbol = None
|
info.bgColor = colors[eventType]
|
||||||
else:
|
|
||||||
info.bgColor = None
|
|
||||||
if calendar.showUncolored:
|
|
||||||
info.symbol = '<acronym title="%s">▪</acronym>' % \
|
|
||||||
eventNames[eventType]
|
|
||||||
else:
|
|
||||||
info.symbol = None
|
info.symbol = None
|
||||||
else:
|
else:
|
||||||
# Get the event name
|
info.bgColor = None
|
||||||
info.name = eventNames[eventType]
|
if calendar.showUncolored:
|
||||||
res.append(info)
|
info.symbol = '<acronym title="%s">▪</acronym>' % \
|
||||||
|
eventNames[eventType]
|
||||||
|
else:
|
||||||
|
info.symbol = None
|
||||||
|
else:
|
||||||
|
# Get the event name
|
||||||
|
info.name = eventNames[eventType]
|
||||||
|
res.append(info)
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
class Event(Persistent):
|
class Event(Persistent):
|
||||||
|
@ -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 ''
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue