예제 #1
0
    def visit_event(self, cnode):
        item = CNode(name='CalendarItem')

        def conv(ebus, ews, f):
            # Convert ews[ebus] = f(ebus element)
            if not cnode.attr.has_key(ebus): return
            ebus_val = cnode.attr[ebus]
            new = f(ebus_val)
            # if not new: return
            new_e = CNode(name=ews, content=new)
            item.add_child(new_e)

        allday = type(cnode.attr['start']) == datetime.date

        conv('summary', 'Subject', str)
        conv('class', 'Sensitivity', class2sensitivity)
        conv('description', 'Body', identity)

        if allday:
            old_start = cnode.attr['start']
            old_end = cnode.attr['end']

            new_start = datetime.datetime(old_start.year,
                                          old_start.month,
                                          old_start.day - 1,
                                          22,
                                          tzinfo=icalendar.UTC)

            new_end = datetime.datetime(old_end.year,
                                        old_end.month,
                                        old_end.day - 1,
                                        22,
                                        tzinfo=icalendar.UTC)

            start_e = CNode('Start', content=ical2xsdt(new_start))
            end_e = CNode('End', content=ical2xsdt(new_end))

            item.add_child(start_e)
            item.add_child(end_e)
            
            allday = CNode(name='IsAllDayEvent',content='true')
            item.add_child(allday)

        else:
            conv('start', 'Start', ical2xsdt)
            conv('end', 'End', ical2xsdt)


        rec = self.accept1(cnode, 'Recurrence')
        if rec:
            item.add_child(rec)

        if not allday:
            tzid = cnode.search('tzid')
            if tzid:
                tzid = tzid.content
                tz_e = self.timezones[tzid]
                tz_e = self.visit(tz_e)
                item.add_child(tz_e)

        conv('location', 'Location', identity)

        body_e = item.search('Body')
        if body_e:
            body_e.attr['BodyType'] = 'Text'


        return item