Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
CMFCalendar.CalendarTool.CalendarTool Class Reference
Inheritance diagram for CMFCalendar.CalendarTool.CalendarTool:
Inheritance graph
[legend]
Collaboration diagram for CMFCalendar.CalendarTool.CalendarTool:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def edit_configuration
def getFirstWeekDay
def getCalendarTypes
def getCalendarStates
def getUseSession
def getDays
def getWeeksList
def getEventsForCalendar
def catalog_getevents
def getEventsForThisDay
def getPreviousMonth
def getNextMonth
def getBeginAndEndTimes

Public Attributes

 calendar_types
 calendar_states
 firstweekday

Static Public Attributes

string id = 'portal_calendar'
string meta_type = 'CMF Calendar Tool'
tuple security = ClassSecurityInfo()
tuple calendar_types = ('Event',)
tuple calendar_states = ('published',)
 use_session = False
int firstweekday = 6
tuple manage_options
tuple manage_overview
tuple manage_configure

Private Member Functions

def _getCalendar

Detailed Description

A tool for encapsulating how calendars work and are displayed 

Definition at line 33 of file CalendarTool.py.


Member Function Documentation

Wrapper to ensure we set the first day of the week every time

Definition at line 95 of file CalendarTool.py.

00095 
00096     def _getCalendar(self):
00097         """ Wrapper to ensure we set the first day of the week every time
00098         """
00099         calendar.setfirstweekday(self.getFirstWeekDay())
00100         return calendar

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFCalendar.CalendarTool.CalendarTool.catalog_getevents (   self,
  year,
  month 
)
given a year and month return a list of days that have events 

Definition at line 179 of file CalendarTool.py.

00179 
00180     def catalog_getevents(self, year, month):
00181         """ given a year and month return a list of days that have events 
00182         """
00183         # XXX: this method violates the rules for tools/utilities:
00184         # it depends on a non-utility tool
00185         year = int(year)
00186         month = int(month)
00187         last_day = self._getCalendar().monthrange(year, month)[1]
00188         first_date = self.getBeginAndEndTimes(1, month, year)[0]
00189         last_date = self.getBeginAndEndTimes(last_day, month, year)[1]
00190 
00191         ctool = getToolByName(self, 'portal_catalog')
00192         query = ctool(
00193                         portal_type=self.getCalendarTypes(),
00194                         review_state=self.getCalendarStates(),
00195                         start={'query': last_date, 'range': 'max'},
00196                         end={'query': first_date, 'range': 'min'},
00197                         sort_on='start' )
00198 
00199         # compile a list of the days that have events
00200         eventDays={}
00201         for daynumber in range(1, 32): # 1 to 31
00202             eventDays[daynumber] = {'eventslist': [],
00203                                     'event': 0,
00204                                     'day': daynumber}
00205         includedevents = []
00206         for result in query:
00207             if result.getRID() in includedevents:
00208                 break
00209             else:
00210                 includedevents.append(result.getRID())
00211             event={}
00212             # we need to deal with events that end next month
00213             if  result.end.month() != month:
00214                 # doesn't work for events that last ~12 months
00215                 # fix it if it's a problem, otherwise ignore
00216                 eventEndDay = last_day
00217                 event['end'] = None
00218             else:
00219                 eventEndDay = result.end.day()
00220                 event['end'] = result.end.Time()
00221             # and events that started last month
00222             if result.start.month() != month:  # same as above (12 month thing)
00223                 eventStartDay = 1
00224                 event['start'] = None
00225             else:
00226                 eventStartDay = result.start.day()
00227                 event['start'] = result.start.Time()
00228 
00229             event['title'] = result.Title or result.getId
00230 
00231             if eventStartDay != eventEndDay:
00232                 allEventDays = range(eventStartDay, eventEndDay+1)
00233                 eventDays[eventStartDay]['eventslist'].append(
00234                         {'end': None,
00235                          'start': result.start.Time(),
00236                          'title': event['title']} )
00237                 eventDays[eventStartDay]['event'] = 1
00238 
00239                 for eventday in allEventDays[1:-1]:
00240                     eventDays[eventday]['eventslist'].append(
00241                         {'end': None,
00242                          'start': None,
00243                          'title': event['title']} )
00244                     eventDays[eventday]['event'] = 1
00245 
00246                 if result.end == result.end.earliestTime():
00247                     last_day_data = eventDays[allEventDays[-2]]
00248                     last_days_event = last_day_data['eventslist'][-1]
00249                     last_days_event['end'] = (result.end-1).latestTime().Time()
00250                 else:
00251                     eventDays[eventEndDay]['eventslist'].append( 
00252                         { 'end': result.end.Time()
00253                         , 'start': None, 'title': event['title']} )
00254                     eventDays[eventEndDay]['event'] = 1
00255             else:
00256                 eventDays[eventStartDay]['eventslist'].append(event)
00257                 eventDays[eventStartDay]['event'] = 1
00258             # This list is not uniqued and isn't sorted
00259             # uniquing and sorting only wastes time
00260             # and in this example we don't need to because
00261             # later we are going to do an 'if 2 in eventDays'
00262             # so the order is not important.
00263             # example:  [23, 28, 29, 30, 31, 23]
00264         return eventDays

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFCalendar.CalendarTool.CalendarTool.edit_configuration (   self,
  show_types,
  use_session,
  show_states = None,
  firstweekday = None 
)
Change the configuration of the calendar tool 

Definition at line 69 of file CalendarTool.py.

00069 
00070                           ):
00071         """ Change the configuration of the calendar tool 
00072         """
00073         # XXX: this method violates the rules for tools/utilities:
00074         # it depends on self.REQUEST
00075         self.calendar_types = tuple(show_types)
00076         self.use_session = bool(use_session)
00077 
00078         if show_states is not None:
00079             self.calendar_states = tuple(show_states)
00080 
00081         if firstweekday is not None:
00082             try:
00083                 fwd = int(firstweekday)
00084 
00085                 if 0 <= fwd <= 6:
00086                     # Do nothing with illegal values
00087                     self.firstweekday = fwd
00088             except ValueError:
00089                 # Do nothing with illegal values
00090                 pass
00091 
00092         if hasattr(self.REQUEST, 'RESPONSE'):
00093             self.REQUEST.RESPONSE.redirect('manage_configure')

def CMFCalendar.CalendarTool.CalendarTool.getBeginAndEndTimes (   self,
  day,
  month,
  year 
)
Get two DateTime objects representing the beginning and end
of the given day

Definition at line 355 of file CalendarTool.py.

00355 
00356     def getBeginAndEndTimes(self, day, month, year):
00357         """ Get two DateTime objects representing the beginning and end
00358         of the given day
00359         """
00360         day = int(day)
00361         month = int(month)
00362         year = int(year)
00363 
00364         begin = DateTime('%d/%02d/%02d 00:00:00' % (year, month, day))
00365         end = DateTime('%d/%02d/%02d 23:59:59' % (year, month, day))
00366 
00367         return (begin, end)
00368 
00369 InitializeClass(CalendarTool)

Here is the caller graph for this function:

Returns a list of workflow states that will show in the calendar 

Definition at line 114 of file CalendarTool.py.

00114 
00115     def getCalendarStates(self):
00116         """ Returns a list of workflow states that will show in the calendar 
00117         """
00118         return self.calendar_states

Here is the caller graph for this function:

Returns a list of type that will show in the calendar 

Definition at line 108 of file CalendarTool.py.

00108 
00109     def getCalendarTypes(self):
00110         """ Returns a list of type that will show in the calendar 
00111         """
00112         return self.calendar_types

Here is the caller graph for this function:

Returns a list of days with the correct start day first 

Definition at line 126 of file CalendarTool.py.

00126 
00127     def getDays(self):
00128         """ Returns a list of days with the correct start day first 
00129         """
00130         return self._getCalendar().weekheader(2).split()

Here is the call graph for this function:

def CMFCalendar.CalendarTool.CalendarTool.getEventsForCalendar (   self,
  month = '1',
  year = '2002' 
)
recreates a sequence of weeks, by days each day is a mapping.
    {'day': #, 'url': None}

Definition at line 149 of file CalendarTool.py.

00149 
00150     def getEventsForCalendar(self, month='1', year='2002'):
00151         """ recreates a sequence of weeks, by days each day is a mapping.
00152             {'day': #, 'url': None}
00153         """
00154         year = int(year)
00155         month = int(month)
00156         # daysByWeek is a list of days inside a list of weeks, like so:
00157         # [[0, 1, 2, 3, 4, 5, 6],
00158         #  [7, 8, 9, 10, 11, 12, 13],
00159         #  [14, 15, 16, 17, 18, 19, 20],
00160         #  [21, 22, 23, 24, 25, 26, 27],
00161         #  [28, 29, 30, 31, 0, 0, 0]]
00162         daysByWeek = self._getCalendar().monthcalendar(year, month)
00163         weeks = []
00164 
00165         events = self.catalog_getevents(year, month)
00166 
00167         for week in daysByWeek:
00168             days = []
00169             for day in week:
00170                 if events.has_key(day):
00171                     days.append(events[day])
00172                 else:
00173                     days.append({'day': day, 'event': 0, 'eventslist':[]})
00174 
00175             weeks.append(days)
00176 
00177         return weeks

Here is the call graph for this function:

given an exact day return ALL events that:
    A) Start on this day  OR
    B) End on this day  OR
    C) Start before this day  AND  end after this day

Definition at line 266 of file CalendarTool.py.

00266 
00267     def getEventsForThisDay(self, thisDay):
00268         """ given an exact day return ALL events that:
00269             A) Start on this day  OR
00270             B) End on this day  OR
00271             C) Start before this day  AND  end after this day
00272         """
00273         # XXX: this method violates the rules for tools/utilities:
00274         # it depends on a non-utility tool
00275         day, month, year = ( int(thisDay.day())
00276                            , int(thisDay.month())
00277                            , int(thisDay.year())
00278                            )
00279 
00280         first_date, last_date = self.getBeginAndEndTimes(day, month, year)
00281         zone = first_date.localZone()
00282         after_midnight_str = '%d-%02d-%02d 00:01:00 %s' % (year,month,day,zone)
00283         after_midnight = DateTime(after_midnight_str)
00284 
00285         # Get all events that Start on this day
00286         ctool = getToolByName(self, 'portal_catalog')
00287         query = ctool(
00288                         portal_type=self.getCalendarTypes(),
00289                         review_state=self.getCalendarStates(),
00290                         start={'query': (first_date, last_date),
00291                                'range': 'minmax'} )
00292 
00293         # Get all events that End on this day
00294         query += ctool(
00295                          portal_type=self.getCalendarTypes(),
00296                          review_state=self.getCalendarStates(),
00297                          end={'query': (after_midnight, last_date),
00298                               'range': 'minmax'} )
00299 
00300         # Get all events that Start before this day AND End after this day
00301         query += ctool(
00302                          portal_type=self.getCalendarTypes(),
00303                          review_state=self.getCalendarStates(),
00304                          start={'query': first_date, 'range': 'max'},
00305                          end={'query': last_date, 'range': 'min'} )
00306 
00307         # Unique the results
00308         results = []
00309         rids = []
00310         for item in query:
00311             rid = item.getRID()
00312             if not rid in rids:
00313                 results.append(item)
00314                 rids.append(rid)
00315 
00316         def sort_function(x,y):
00317             z = cmp(x.start,y.start)
00318             if not z:
00319                 return cmp(x.end,y.end)
00320             return z
00321 
00322         # Sort by start date
00323         results.sort(sort_function)
00324 
00325         return results

Here is the call graph for this function:

Get our first weekday setting

Definition at line 102 of file CalendarTool.py.

00102 
00103     def getFirstWeekDay(self):
00104         """ Get our first weekday setting
00105         """
00106         return self.firstweekday

Here is the caller graph for this function:

def CMFCalendar.CalendarTool.CalendarTool.getNextMonth (   self,
  month,
  year 
)
Get a DateTime object for one month after the given year/month

Definition at line 341 of file CalendarTool.py.

00341 
00342     def getNextMonth(self, month, year):
00343         """ Get a DateTime object for one month after the given year/month
00344         """
00345         month = int(month)
00346         year = int(year)
00347 
00348         if month == 12:
00349             month, year = 1, year + 1
00350         else:
00351             month += 1
00352 
00353         return DateTime(year, month, 1)

def CMFCalendar.CalendarTool.CalendarTool.getPreviousMonth (   self,
  month,
  year 
)
Get a DateTime object for one month prior to the given year/month

Definition at line 327 of file CalendarTool.py.

00327 
00328     def getPreviousMonth(self, month, year):
00329         """ Get a DateTime object for one month prior to the given year/month
00330         """
00331         month = int(month)
00332         year = int(year)
00333 
00334         if month == 0 or month == 1:
00335             month, year = 12, year - 1
00336         else:
00337             month -= 1
00338 
00339         return DateTime(year, month, 1)

Returns the Use_Session option 

Definition at line 120 of file CalendarTool.py.

00120 
00121     def getUseSession(self):
00122         """ Returns the Use_Session option 
00123         """
00124         return bool(self.use_session)

def CMFCalendar.CalendarTool.CalendarTool.getWeeksList (   self,
  month = '1',
  year = '2002' 
)
Return a series of weeks, each containing an integer day number.
A day number of 0 means that day is in the previous or next month.

Definition at line 132 of file CalendarTool.py.

00132 
00133     def getWeeksList(self, month='1', year='2002'):
00134         """ Return a series of weeks, each containing an integer day number.
00135         A day number of 0 means that day is in the previous or next month.
00136         """
00137         year = int(year)
00138         month = int(month)
00139         # daysByWeek is a list of days inside a list of weeks, like so:
00140         # [[0, 1, 2, 3, 4, 5, 6],
00141         #  [7, 8, 9, 10, 11, 12, 13],
00142         #  [14, 15, 16, 17, 18, 19, 20],
00143         #  [21, 22, 23, 24, 25, 26, 27],
00144         #  [28, 29, 30, 31, 0, 0, 0]]
00145         daysByWeek = self._getCalendar().monthcalendar(year, month)
00146 
00147         return daysByWeek

Here is the call graph for this function:


Member Data Documentation

Definition at line 44 of file CalendarTool.py.

Definition at line 78 of file CalendarTool.py.

Definition at line 43 of file CalendarTool.py.

Definition at line 74 of file CalendarTool.py.

Definition at line 46 of file CalendarTool.py.

Definition at line 86 of file CalendarTool.py.

string CMFCalendar.CalendarTool.CalendarTool.id = 'portal_calendar' [static]

Definition at line 37 of file CalendarTool.py.

Initial value:
PageTemplateFile('www/configureCalendarTool', globals(),
                                   __name__='manage_configure')

Definition at line 60 of file CalendarTool.py.

Initial value:
(({'label' : 'Overview', 'action' : 'manage_overview'},
                       {'label' : 'Configure', 'action' : 'manage_configure'},
                      ) + SimpleItem.manage_options)

Definition at line 48 of file CalendarTool.py.

Initial value:
PageTemplateFile('www/explainCalendarTool', globals(),
                                   __name__='manage_overview')

Definition at line 56 of file CalendarTool.py.

string CMFCalendar.CalendarTool.CalendarTool.meta_type = 'CMF Calendar Tool' [static]

Definition at line 38 of file CalendarTool.py.

tuple CMFCalendar.CalendarTool.CalendarTool.security = ClassSecurityInfo() [static]

Definition at line 39 of file CalendarTool.py.

Definition at line 45 of file CalendarTool.py.


The documentation for this class was generated from the following file: