[Zope-CMF] Calendar
Charlie Clark
charlie at begeistert.org
Mon Nov 27 11:09:16 EST 2006
Am 27.11.2006 um 14:14 schrieb Charlie Clark:
> He isn't my friend - my brain has difficulties with the command
> line %-) but I asked the question after reading the source. I'm
> working on my own script to do the work but think it might be a
> good idea to have it in the tool itself. BTW. it's the first time
> I've come across getToolByName.
This is method I've come up with:
def getNextEvent(self):
""" Get the next event from the calendar"""
today = DateTime()
print today
query = self.portal_catalog(
portal_type=self.getCalendarTypes(),
review_state=self.getCalendarStates(),
start={'query': today, 'range': 'max'},
sort_on='start')
def sort_function(x,y): # this should be a utility method
for the class
# as indeed should the check for
uniqueness
z = cmp(x.start,y.start)
if not z:
return cmp(x.end,y.end)
return z
rids = []
results = []
for result in query:
if not result.getRID in rids:
rids.append(result.getRID)
results.append(result)
if results:
results.sort(sort_function)
return results[0]
return None # probably unnecessary
I've also written a simple next_event_view script and
next_event_view_template
I'd write a test for this but I've never written a test so it might
go horribly wrong! ;-)
If you wish I'd be happy to submit this although I think the changes
for unique results and sorting should also be reflected.
Charlie
--
Charlie Clark
Helmholtzstr. 20
Düsseldorf
D- 40215
Tel: +49-211-938-5360
GSM: +49-178-782-6226
More information about the Zope-CMF
mailing list