Ejemplo n.º 1
0
    def eventsByDay(self, start, end):
        """
        Returns a day-keyed dictionary of days between start and end with events.
        Each day in the sequence is returned as a event list sorted by startTime.
        Also, optionally, selects by several criteria
        """
        days = {}
        query = self.eventsByDateRange(start, end)
        # get the dates, taking recurrence into account
        for result in query:
            recurs = result.get('recurs', 'daily')
            estart = result['start']
            ldate = min(end, result['end'])
            if recurs == 'weekly':
                dates = caldate.weekly(start, ldate, estart)
            elif recurs == 'biweekly':
                dates = caldate.biweekly(start, ldate, estart)
            elif recurs == 'monthly':
                dates = caldate.monthly(start, ldate, estart)
            else:  # daily
                dates = caldate.daily(start, ldate, estart)
            for d in dates:
                days.setdefault(d, []).append(result)

        return days
Ejemplo n.º 2
0
    def getevents(self, first, last, **kwa):
        """ given start and end dates, return a list of days that have events
        """

        ctool = self.calendar
        catalog = getToolByName(self.context, 'portal_catalog')
        site_properties = getToolByName(self.context, 'portal_properties').site_properties

        ampm = site_properties.getProperty('localLongTimeFormat').find('%p') >= 0

        first_date = first.earliestTime()
        last_date = last.latestTime()

        query = catalog(
            portal_type=ctool.getCalendarTypes(),
            review_state=ctool.getCalendarStates(),
            start={'query': last_date, 'range': 'max'},
            end={'query': first_date, 'range': 'min'},
            sort_on='start',
            **kwa)

        # compile a list of the days that have events
        events = []

        for result in query:

            # get the dates, taking recurrence into account
            recurs = getattr(result, 'recurs', 'daily')
            start = result.start
            ldate = min(last_date, result.end.latestTime())
            if recurs == 'weekly':
                dates = caldate.weekly(first_date, ldate, start)
            elif recurs == 'biweekly':
                dates = caldate.biweekly(first_date, ldate, start)
            elif recurs == 'monthly':
                dates = caldate.monthly(first_date, ldate, start)
            else:  # daily
                dates = caldate.daily(first_date, ldate, start)

            if dates:
                if ampm:
                    st = result.start.AMPMMinutes().lstrip('0')
                else:
                    st = result.start.TimeMinutes()

                time = list(result.start.parts()[3:5])
                # put event in list
                for day in dates:
                    startdt = DateTime(*(list(day.parts()[0:3]) + time))
                    events.append((startdt, st, result))

        # sort without considering result part
        events.sort(
            lambda x, y: cmp(x[:2], y[:2])
            )
        return events