[gen] Calendar: added the possibility in some calendar to view events from another calendar.
This commit is contained in:
parent
fdd9f4c375
commit
82a8ac99b4
|
@ -15,7 +15,7 @@ class Calendar(Type):
|
||||||
specificReadPermission=False, specificWritePermission=False,
|
specificReadPermission=False, specificWritePermission=False,
|
||||||
width=None, height=300, colspan=1, master=None,
|
width=None, height=300, colspan=1, master=None,
|
||||||
masterValue=None, focus=False, mapping=None, label=None,
|
masterValue=None, focus=False, mapping=None, label=None,
|
||||||
maxEventLength=50):
|
maxEventLength=50, otherCalendars=None):
|
||||||
Type.__init__(self, validator, (0,1), None, default, False, False,
|
Type.__init__(self, validator, (0,1), None, default, False, False,
|
||||||
show, page, group, layouts, move, False, False,
|
show, page, group, layouts, move, False, False,
|
||||||
specificReadPermission, specificWritePermission,
|
specificReadPermission, specificWritePermission,
|
||||||
|
@ -27,6 +27,18 @@ class Calendar(Type):
|
||||||
# It is not possible to create events that span more days than
|
# It is not possible to create events that span more days than
|
||||||
# maxEventLength.
|
# maxEventLength.
|
||||||
self.maxEventLength = maxEventLength
|
self.maxEventLength = maxEventLength
|
||||||
|
# If a method is specified in the following parameters, it must return
|
||||||
|
# a list of calendars whose events must be shown within this agenda.
|
||||||
|
# Every element in this list must be a sub-list [object, name, color]
|
||||||
|
# (not a tuple):
|
||||||
|
# - object must refer to the other object on which the other calendar
|
||||||
|
# field is defined;
|
||||||
|
# - name is the name of the field on this object that stores the
|
||||||
|
# calendar;
|
||||||
|
# - color must be a string containing the HTML color (including the
|
||||||
|
# leading "#" when relevant) into which events of the calendar must
|
||||||
|
# appear.
|
||||||
|
self.otherCalendars = otherCalendars
|
||||||
|
|
||||||
def getSiblingMonth(self, month, prevNext):
|
def getSiblingMonth(self, month, prevNext):
|
||||||
'''Gets the next or previous month (depending of p_prevNext) relative
|
'''Gets the next or previous month (depending of p_prevNext) relative
|
||||||
|
@ -83,6 +95,16 @@ class Calendar(Type):
|
||||||
currentDay = currentDay + 1
|
currentDay = currentDay + 1
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def getOtherCalendars(self, obj):
|
||||||
|
'''Returns the list of other calendars whose events must also be shown
|
||||||
|
on this calendar.'''
|
||||||
|
if self.otherCalendars:
|
||||||
|
res = self.callMethod(obj, self.otherCalendars)
|
||||||
|
# Replace field names with field objects
|
||||||
|
for i in range(len(res)):
|
||||||
|
res[i][1] = res[i][0].getField(res[i][1])
|
||||||
|
return res
|
||||||
|
|
||||||
def getEventsAt(self, obj, date, asDict=True):
|
def getEventsAt(self, obj, date, asDict=True):
|
||||||
'''Returns the list of events that exist at some p_date (=day).'''
|
'''Returns the list of events that exist at some p_date (=day).'''
|
||||||
if not hasattr(obj, self.name): return
|
if not hasattr(obj, self.name): return
|
||||||
|
@ -109,6 +131,18 @@ class Calendar(Type):
|
||||||
if not events: return False
|
if not events: return False
|
||||||
return events[0].eventType == otherEvents[0]['eventType']
|
return events[0].eventType == otherEvents[0]['eventType']
|
||||||
|
|
||||||
|
def getOtherEventsAt(self, obj, date, otherCalendars):
|
||||||
|
'''Gets events that are defined in p_otherCalendars at some p_date.'''
|
||||||
|
res = []
|
||||||
|
for o, field, color in otherCalendars:
|
||||||
|
events = field.getEventsAt(o.o, date, asDict=False)
|
||||||
|
if events:
|
||||||
|
eventType = events[0].eventType
|
||||||
|
label = '%s_event_%s' % (field.labelId, eventType)
|
||||||
|
info = Object(name=obj.translate(label), color=color)
|
||||||
|
res.append(info.__dict__)
|
||||||
|
return res
|
||||||
|
|
||||||
def createEvent(self, obj, date, handleEventSpan=True):
|
def createEvent(self, obj, date, handleEventSpan=True):
|
||||||
'''Create a new event in the calendar, at some p_date (day). If
|
'''Create a new event in the calendar, at some p_date (day). If
|
||||||
p_handleEventSpan is True, we will use rq["eventSpan"] and also
|
p_handleEventSpan is True, we will use rq["eventSpan"] and also
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
nextMonth python: contextObj.callField(fieldName, 'getSiblingMonth', month, 'next');
|
nextMonth python: contextObj.callField(fieldName, 'getSiblingMonth', month, 'next');
|
||||||
widget python: contextObj.getAppyType(fieldName, asDict=True);
|
widget python: contextObj.getAppyType(fieldName, asDict=True);
|
||||||
mayEdit python: contextObj.allows(widget['writePermission']);
|
mayEdit python: contextObj.allows(widget['writePermission']);
|
||||||
objUrl contextObj/absolute_url"
|
objUrl contextObj/absolute_url;
|
||||||
|
otherCalendars python: contextObj.callField(fieldName, 'getOtherCalendars', contextObj);"
|
||||||
tal:attributes="id ajaxHookId">
|
tal:attributes="id ajaxHookId">
|
||||||
|
|
||||||
<script type="text/javascript"
|
<script type="text/javascript"
|
||||||
|
@ -73,6 +74,14 @@
|
||||||
tal:content="python: _('%s_event_%s' % (widget['labelId'], eventType))"></span>
|
tal:content="python: _('%s_event_%s' % (widget['labelId'], eventType))"></span>
|
||||||
</div>
|
</div>
|
||||||
</tal:events>
|
</tal:events>
|
||||||
|
<tal:comment replace="nothing">Events from other calendars</tal:comment>
|
||||||
|
<tal:others condition="otherCalendars">
|
||||||
|
<tal:e define="otherEvents python: contextObj.callField(fieldName,'getOtherEventsAt',contextObj,date,otherCalendars)"
|
||||||
|
condition="otherEvents">
|
||||||
|
<div tal:repeat="event otherEvents" tal:content="event/name"
|
||||||
|
tal:attributes="style python: 'color: %s;; font-style: italic' % event['color']"></div>
|
||||||
|
</tal:e>
|
||||||
|
</tal:others>
|
||||||
</tal:day>
|
</tal:day>
|
||||||
</td>
|
</td>
|
||||||
</tal:cell>
|
</tal:cell>
|
||||||
|
|
Loading…
Reference in a new issue