[CMF-checkins] CVS: CMF/CMFCalendar - CalendarTool.py:1.10

Yvo Schubbe schubbe at web.de
Sun Jan 11 07:45:35 EST 2004


Update of /cvs-repository/CMF/CMFCalendar
In directory cvs.zope.org:/tmp/cvs-serv9422/CMFCalendar

Modified Files:
	CalendarTool.py 
Log Message:
make aj happy:
- replaced deprecated '_usage' query parameters
cleanup:
- whitespace
- long lines


=== CMF/CMFCalendar/CalendarTool.py 1.9 => 1.10 ===
--- CMF/CMFCalendar/CalendarTool.py:1.9	Fri May 23 13:50:30 2003
+++ CMF/CMFCalendar/CalendarTool.py	Sun Jan 11 07:45:35 2004
@@ -17,21 +17,22 @@
 
 import calendar
 calendar.setfirstweekday(6) #start day  Mon(0)-Sun(6)
-from DateTime import DateTime
 
-from Products.CMFCore.utils import UniqueObject
-from OFS.SimpleItem import SimpleItem
-from Globals import InitializeClass
 from AccessControl import ClassSecurityInfo
-from Products.CMFCore.CMFCorePermissions import ManagePortal
+from DateTime import DateTime
+from Globals import InitializeClass
+from OFS.SimpleItem import SimpleItem
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 
+from Products.CMFCore.CMFCorePermissions import ManagePortal
+from Products.CMFCore.utils import UniqueObject
+
+
 class CalendarTool (UniqueObject, SimpleItem):
     """ a calendar tool for encapsualting how calendars work and are displayed """
     id = 'portal_calendar'
     meta_type= 'CMF Calendar Tool'
     security = ClassSecurityInfo()
-    plone_tool = 1
 
     manage_options = ( ({ 'label' : 'Overview', 'action' : 'manage_overview' }
                      ,  { 'label' : 'Configure', 'action' : 'manage_configure' }
@@ -49,7 +50,7 @@
     security.declareProtected( ManagePortal, 'manage_configure' )
     manage_configure = PageTemplateFile('www/configureCalendarTool', globals(),
                                    __name__='manage_configure')
-    
+
     def __init__(self):
         self.calendar_types = ['Event']
         self.use_session = ""
@@ -61,7 +62,7 @@
         self.use_session = use_session
         if hasattr(self.REQUEST, 'RESPONSE'):
             self.REQUEST.RESPONSE.redirect('manage_configure')
-        
+
     security.declarePublic('getCalendarTypes')
     def getCalendarTypes(self):
         """ Returns a list of type that will show in the calendar """
@@ -74,9 +75,9 @@
 
     security.declarePublic('getDays')
     def getDays(self):
-        """ Returns a list of days with the correct start day first """        
+        """ Returns a list of days with the correct start day first """
         return calendar.weekheader(2).split()
-        
+
     security.declarePublic('getWeeksList')
     def getWeeksList(self, month='1', year='2002'):
         """Creates a series of weeks, each of which contains an integer day number.
@@ -89,7 +90,7 @@
         #  [21, 22, 23, 24, 25, 26, 27],
         #  [28, 29, 30, 31, 0, 0, 0]]
         daysByWeek=calendar.monthcalendar(year, month)
-    
+
         return daysByWeek
 
     security.declarePublic('getEventsForCalendar')
@@ -107,9 +108,9 @@
         #  [28, 29, 30, 31, 0, 0, 0]]
         daysByWeek=calendar.monthcalendar(year, month)
         weeks=[]
-        
+
         events=self.catalog_getevents(year, month)
-    
+
         for week in daysByWeek:
             days=[]
             for day in week:
@@ -117,11 +118,11 @@
                     days.append(events[day])
                 else:
                     days.append({'day': day, 'event': 0, 'eventslist':[]})
-                
+
             weeks.append(days)
-            
+
         return weeks
-    
+
     security.declarePublic('catalog_getevents')
     def catalog_getevents(self, year, month):
         """ given a year and month return a list of days that have events """
@@ -129,17 +130,16 @@
         last_day=calendar.monthrange(year, month)[1]
         ## This line was cropping the last day of the month out of the
         ## calendar when doing the query
-    	## last_date=DateTime(str(month)+'/'+str(last_day)+'/'+str(year))
-    	last_date=first_date + last_day    
-        
-    	query=self.portal_catalog(portal_type=self.calendar_types,
-                                  review_state='published',	                          
-                                  start=last_date,
-                                  start_usage='range:max',
-                                  end=first_date,
-                                  end_usage='range:min',
-                                  sort_on='start')
-        
+        ## last_date=DateTime(str(month)+'/'+str(last_day)+'/'+str(year))
+        last_date=first_date + last_day
+
+        query = self.portal_catalog(
+                        portal_type=self.calendar_types,
+                        review_state='published',
+                        start={'query': last_date, 'range': 'max'},
+                        end={'query': first_date, 'range': 'min'},
+                        sort_on='start' )
+
         # compile a list of the days that have events
         eventDays={}
         for daynumber in range(1, 32): # 1 to 31
@@ -152,7 +152,9 @@
                 includedevents.append(result.getRID())
             event={}
             # we need to deal with events that end next month
-            if  result.end.month() != month:  # doesn't work for events that last ~12 months - fix it if it's a problem, otherwise ignore
+            if  result.end.month() != month:
+                # doesn't work for events that last ~12 months
+                # fix it if it's a problem, otherwise ignore
                 eventEndDay = last_day
                 event['end'] = None
             else:
@@ -168,12 +170,15 @@
             event['title'] = result.Title or result.id
             if eventStartDay != eventEndDay:
                 allEventDays = range(eventStartDay, eventEndDay+1)
-                eventDays[eventStartDay]['eventslist'].append({'end':None, 'start':result.start.Time(), 'title':result.Title})
+                eventDays[eventStartDay]['eventslist'].append( {'end': None,
+                        'start': result.start.Time(), 'title': result.Title} )
                 eventDays[eventStartDay]['event'] = 1
                 for eventday in allEventDays[1:-1]:
-                    eventDays[eventday]['eventslist'].append({'end':None, 'start':None, 'title':result.Title})
+                    eventDays[eventday]['eventslist'].append( {'end': None,
+                                       'start': None, 'title': result.Title} )
                     eventDays[eventday]['event'] = 1
-                eventDays[eventEndDay]['eventslist'].append({'end':result.end.Time(), 'start':None, 'title':result.Title})
+                eventDays[eventEndDay]['eventslist'].append( {'end':
+                    result.end.Time(), 'start': None, 'title': result.Title} )
                 eventDays[eventEndDay]['event'] = 1
             else:
                 eventDays[eventStartDay]['eventslist'].append(event)
@@ -192,32 +197,33 @@
             A) Start on this day  OR
             B) End on this day  OR
             C) Start before this day  AND  end after this day"""
-        
+
         catalog = self.portal_catalog
-        
+
         first_date, last_date = self.getBeginAndEndTimes(thisDay.day(), thisDay.month(), thisDay.year())
         #first_date=DateTime(thisDay.Date()+" 00:00:00")
         #last_date=DateTime(thisDay.Date()+" 23:59:59")
 
         # Get all events that Start on this day
-        query=self.portal_catalog(portal_type=self.calendar_types,
-                                  review_state='published',	                          
-                                  start=(first_date,last_date),
-                                  start_usage='range:min:max')
-        
+        query = self.portal_catalog(
+                        portal_type=self.calendar_types,
+                        review_state='published',
+                        start={'query': (first_date, last_date),
+                               'range': 'minmax'} )
+
         # Get all events that End on this day
-        query+=self.portal_catalog(portal_type=self.calendar_types,
-                                  review_state='published',	                          
-                                  end=(first_date,last_date),
-                                  end_usage='range:min:max')
+        query += self.portal_catalog(
+                         portal_type=self.calendar_types,
+                         review_state='published',
+                         end={'query': (first_date, last_date),
+                              'range': 'minmax'} )
 
         # Get all events that Start before this day AND End after this day
-        query+=self.portal_catalog(portal_type=self.calendar_types,
-                                  review_state='published',
-                                  start=first_date,
-                                  start_usage='range:max',
-                                  end=last_date,
-                                  end_usage='range:min')
+        query += self.portal_catalog(
+                         portal_type=self.calendar_types,
+                         review_state='published',
+                         start={'query': first_date, 'range': 'max'},
+                         end={'query': last_date, 'range': 'min'} )
 
         # Unique the results
         results = []
@@ -227,66 +233,64 @@
             if not rid in rids:
                 results.append(item)
                 rids.append(rid)
-                
+
         def sort_function(x,y):
             z = cmp(x.start,y.start)
-            if not z: 
+            if not z:
                 return cmp(x.end,y.end)
             return z
-        
+
         # Sort by start date
         results.sort(sort_function)
-                
+
         return results
-                
-        
+
     security.declarePublic('getPreviousMonth')
     def getPreviousMonth(self, month, year):
         # given any particular year and month, this method will return a datetime object
         # for one month prior
-        
+
         try: month=int(month)
         except: raise "Calendar Type Error", month
         try: year=int(year)
         except: raise "Calendar Type Error", year
-        
+
         if month==0 or month==1:
             month, year = 12, year - 1
         else:
             month-=1
-        
-        return DateTime(str(month) + '/1/' + str(year))    
-    
+
+        return DateTime(str(month) + '/1/' + str(year))
+
     security.declarePublic('getNextMonth')
     def getNextMonth(self, month, year):
         # given any particular year and month, this method will return a datetime object
         # for one month after
-    
+
         try: month=int(month)
         except: raise "Calendar Type Error", month
         try: year=int(year)
         except: raise "Calendar Type Error", year
-        
+
         if month==12:
             month, year = 1, year + 1
         else:
             month+=1
-        
+
         return DateTime(str(month) + '/1/' + str(year))
 
     security.declarePublic('getBeginAndEndTimes')
     def getBeginAndEndTimes(self, day, month, year):
         # Given any day, month and year this method returns 2 DateTime objects
         # That represent the exact start and the exact end of that particular day.
-        
+
         day=str(day)
         month=str(month)
         year=str(year)
-        
+
         begin=DateTime(month+'/'+day+'/'+year+' 12:00:00AM')
         end=DateTime(month+'/'+day+'/'+year+' 11:59:59PM')
-        
-        return (begin, end)    
-        
-    
+
+        return (begin, end)
+
 InitializeClass(CalendarTool)




More information about the CMF-checkins mailing list