Exemple #1
0
        def do(event):
            if recurrence_id:
                return
            add_recurrence = not all_empty(record, 'rdate', 'rrule')
            recurrence_installed = Recurrence.installed_on(event.item)
            if not recurrence_installed and not add_recurrence:
                pass # no recurrence, nothing to do
            elif recurrence_id:
                pass # modification, no rules to set
            else:
                recur = Recurrence(event.item)
                if add_recurrence and not recurrence_installed:
                    recur.add()
                for datetype in 'rdate', 'exdate':
                    record_field = getattr(record, datetype)
                    if record_field is not eim.NoChange:
                        if record_field is None:
                            dates = ()
                        else:
                            dates = fromICalendarDateTime(record_field, multivalued=True)[0]
                        date_set = getattr(recur, datetype + 's')
                        if date_set.symmetric_difference(dates):
                            date_set.clear()
                            date_set.update(dates)

                if record.rrule is not eim.NoChange:
                    if record.rrule in emptyValues:
                        recur.frequency = None
                    else:
                        # EIM serializes multiple RRULEs colon separated,
                        # ignoring all but the first for now.
                        rule_dict = {}
                        first_rule, sep, later_rules = record.rrule.upper().partition(':')
                        for key_value_string in first_rule.split(';'):
                            key, sep, value = key_value_string.partition('=')
                            rule_dict[key] = value

                        # count and until are mutually exclusive, special case
                        if 'COUNT' in rule_dict:
                            recur.count = int(rule_dict['COUNT'])
                        elif 'UNTIL' in rule_dict:
                            recur.until = fromICalendarDateTime(rule_dict['UNTIL'])[0]
                        else:
                            recur.until = None

                        for attr, tup in rrule_attr_dispatch.items():
                            rule_key, convert = tup
                            if rule_key in rule_dict:
                                setattr(recur, attr, convert(rule_dict[rule_key]))
                            else:
                                reset_cell_default(recur, attr)

                if not recur.frequency and not recur.rdates:
                    if recurrence_installed:
                        recur.remove()
Exemple #2
0
def getRecurrenceFields(event):
    """
    Take an event, return EIM strings for rrule, exrule, rdate, exdate, any
    or all of which may be None.

    """
    item = event.item
    if not Recurrence.installed_on(item) or not Recurrence(item).rruleset:
        return (None, None, None, None)

    recur = Recurrence(item)
    if recur.frequency:
        rrule_dict = {}
        if recur.count:
            rrule_dict['COUNT'] = str(recur.count)
        elif recur.until:
            floating = event.start.tzinfo == TimeZone.floating
            until_tzinfo = TimeZone.floating if floating else TimeZone.utc
            until = recur.until.astimezone(until_tzinfo)
            rrule_dict['UNTIL'] = formatDateTime(until, False, False)

        for attr, tup in rrule_attr_dispatch.items():
            rule_key, ignore = tup
            value = getattr(recur, attr)
            if value:
                rrule_dict[rule_key] = str(value).upper()

        rrule = ";".join("=".join(tup) for tup in rrule_dict.items())
    else:
        rrule = None

    if len(recur.rdates) > 0:
        rdates = toICalendarDateTime(recur.rdates, event.is_day, False)
    else:
        rdates = None

    if len(recur.exdates) > 0:
        exdates = toICalendarDateTime(recur.exdates, event.is_day, False)
    else:
        exdates = None

    return rrule, None, rdates, exdates
Exemple #3
0
    def getItemForAlias(self, alias):
        if str(alias).startswith("@"):
            # a well-known-name
            return super(SharingTranslator, self).getItemForAlias(alias)

        uuid, recurrence_id = splitUUID(alias)
        if not recurrence_id:
            return super(SharingTranslator, self).getItemForAlias(alias)

        # a modification
        master = eim.item_for_uuid(uuid)
        return Recurrence(master).get_occurrence(recurrence_id)
Exemple #4
0
    def withItemForUUID(self, alias, itype=Item, **attrs):
        """Handle recurrence modification aliases."""
        uuid, recurrence_id = splitUUID(alias)
        if not recurrence_id:
            return super(SharingTranslator, self).withItemForUUID(uuid, itype, **attrs)

        occurrence = self.getItemForAlias(alias)
        master = self.getItemForAlias(uuid)
        master_recur = Recurrence(master)

        add_on = itype if itype is not Item else None

        # recurrence triage is a special case
        if add_on is Triage and 'manual' in attrs and 'manual_timestamp' in attrs:
            status, timestamp = attrs['manual'], attrs['manual_timestamp']
            if status is eim.Inherit:
                master_recur.clear_occurrence_triage(recurrence_id)
            else:
                master_recur.triage_occurrence(recurrence_id, timestamp, status)
            del attrs['manual']
            del attrs['manual_timestamp']

        for name, value in attrs.items():
            if value is eim.Inherit:
                occurrence.remove_change(add_on, name)
            elif value is not eim.NoChange:
                occurrence.modify(add_on, name, value)

        value = occurrence if add_on is None else add_on(occurrence)
        if issubclass(itype, Extension):
            if not itype.installed_on(occurrence) and attrs:
                value.add()

        def decorator(func):
            try:
                return func(value)
            except Exception, e:
                self.recordFailure(e)
Exemple #5
0
def getRecurrenceFields(event):
    """
    Take an event, return EIM strings for rrule, exrule, rdate, exdate, any
    or all of which may be None.

    """
    item = event.item
    if not Recurrence.installed_on(item) or not Recurrence(item).rruleset:
        return (None, None, None, None)

    recur = Recurrence(item)
    if recur.frequency:
        rrule_dict = {}
        if recur.count:
            rrule_dict['COUNT'] = str(recur.count)
        elif recur.until:
            floating = event.start.tzinfo == TimeZone.floating
            until_tzinfo = TimeZone.floating if floating else TimeZone.utc
            until = recur.until.astimezone(until_tzinfo)
            rrule_dict['UNTIL'] = formatDateTime(until, False, False)

        for attr, tup in rrule_attr_dispatch.items():
            rule_key, ignore = tup
            value = getattr(recur, attr)
            if value:
                rrule_dict[rule_key] = str(value).upper()

        rrule = ";".join("=".join(tup) for tup in rrule_dict.items())
    else:
        rrule = None

    if len(recur.rdates) > 0:
        rdates = toICalendarDateTime(recur.rdates, event.is_day, False)
    else:
        rdates = None

    if len(recur.exdates) > 0:
        exdates = toICalendarDateTime(recur.exdates, event.is_day, False)
    else:
        exdates = None

    return rrule, None, rdates, exdates
Exemple #6
0
    def withItemForUUID(self, alias, itype=Item, **attrs):
        """Handle recurrence modification aliases."""
        uuid, recurrence_id = splitUUID(alias)
        if not recurrence_id:
            return super(SharingTranslator,
                         self).withItemForUUID(uuid, itype, **attrs)

        occurrence = self.getItemForAlias(alias)
        master = self.getItemForAlias(uuid)
        master_recur = Recurrence(master)

        add_on = itype if itype is not Item else None

        # recurrence triage is a special case
        if add_on is Triage and 'manual' in attrs and 'manual_timestamp' in attrs:
            status, timestamp = attrs['manual'], attrs['manual_timestamp']
            if status is eim.Inherit:
                master_recur.clear_occurrence_triage(recurrence_id)
            else:
                master_recur.triage_occurrence(recurrence_id, timestamp,
                                               status)
            del attrs['manual']
            del attrs['manual_timestamp']

        for name, value in attrs.items():
            if value is eim.Inherit:
                occurrence.remove_change(add_on, name)
            elif value is not eim.NoChange:
                occurrence.modify(add_on, name, value)

        value = occurrence if add_on is None else add_on(occurrence)
        if issubclass(itype, Extension):
            if not itype.installed_on(occurrence) and attrs:
                value.add()

        def decorator(func):
            try:
                return func(value)
            except Exception, e:
                self.recordFailure(e)
Exemple #7
0
    def export_item(self, item):
        mask = SharingMask(item)

        triage = Triage(item)
        recurring = Recurrence.installed_on(item) and Recurrence(item).rruleset
        if recurring:
            encoded_triage = eim.NoChange
        elif triage.manual and triage.manual_timestamp:
            code = normalize_triage_code(triage.manual)
            manual_timestamp = -1 * triage.manual_timestamp
            encoded_triage = "%s %.2f 0" % (code, manual_timestamp)
        else:
            encoded_triage = eim.Inherit

        yield model.ItemRecord(
            item,                                        # uuid
            self.obfuscate(mask.title),                  # title
            encoded_triage,                              # triage
            with_nochange(mask.created, decimal_int),    # createdOn
            eim.NoChange,                                # hasBeenSent
            eim.NoChange,                                # needsReply
            eim.NoChange,                                # read
        )

        eim_wrapped = eim.EIM(item)

        yield model.NoteRecord(
            item,                                        # uuid
            self.obfuscate(mask.body),                   # body
            empty_as_inherit(eim_wrapped, 'ical_uid'),   # icalUid
            eim.Inherit,                                 # icalendarProperties
            eim.Inherit,                                 # icalendarParameters
            empty_as_inherit(eim_wrapped, 'ical_extra')  # icalendarExtra
        )


        if not ReminderList(item).reminders:
            description = None
            trigger = None
            duration = None
            repeat = None

        elif not getattr(item, 'recurrence_id', False):
            reminder = ReminderList(item).reminders[0]
            trigger = None
            if reminder.delta:
                trigger = timedeltaToString(reminder.delta)
            elif reminder.fixed_trigger:
                fixed = reminder.fixed_trigger.astimezone(TimeZone.utc)
                trigger = toICalendarDateTime(fixed, False)

            duration = eim.NoChange
            repeat = eim.NoChange
            description = getattr(reminder, 'description', None)
            if not description:
                description = "Event Reminder"

        else: # we've inherited this reminder
            description = eim.Inherit
            trigger = eim.Inherit
            duration = eim.Inherit
            repeat = eim.Inherit

        yield model.DisplayAlarmRecord(
            item,
            description,
            trigger,
            duration,
            repeat,
        )
Exemple #8
0
        def do(event):
            if recurrence_id:
                return
            add_recurrence = not all_empty(record, 'rdate', 'rrule')
            recurrence_installed = Recurrence.installed_on(event.item)
            if not recurrence_installed and not add_recurrence:
                pass  # no recurrence, nothing to do
            elif recurrence_id:
                pass  # modification, no rules to set
            else:
                recur = Recurrence(event.item)
                if add_recurrence and not recurrence_installed:
                    recur.add()
                for datetype in 'rdate', 'exdate':
                    record_field = getattr(record, datetype)
                    if record_field is not eim.NoChange:
                        if record_field is None:
                            dates = ()
                        else:
                            dates = fromICalendarDateTime(record_field,
                                                          multivalued=True)[0]
                        date_set = getattr(recur, datetype + 's')
                        if date_set.symmetric_difference(dates):
                            date_set.clear()
                            date_set.update(dates)

                if record.rrule is not eim.NoChange:
                    if record.rrule in emptyValues:
                        recur.frequency = None
                    else:
                        # EIM serializes multiple RRULEs colon separated,
                        # ignoring all but the first for now.
                        rule_dict = {}
                        first_rule, sep, later_rules = record.rrule.upper(
                        ).partition(':')
                        for key_value_string in first_rule.split(';'):
                            key, sep, value = key_value_string.partition('=')
                            rule_dict[key] = value

                        # count and until are mutually exclusive, special case
                        if 'COUNT' in rule_dict:
                            recur.count = int(rule_dict['COUNT'])
                        elif 'UNTIL' in rule_dict:
                            recur.until = fromICalendarDateTime(
                                rule_dict['UNTIL'])[0]
                        else:
                            recur.until = None

                        for attr, tup in rrule_attr_dispatch.items():
                            rule_key, convert = tup
                            if rule_key in rule_dict:
                                setattr(recur, attr,
                                        convert(rule_dict[rule_key]))
                            else:
                                reset_cell_default(recur, attr)

                if not recur.frequency and not recur.rdates:
                    if recurrence_installed:
                        recur.remove()
Exemple #9
0
    def export_item(self, item):
        mask = SharingMask(item)

        triage = Triage(item)
        recurring = Recurrence.installed_on(item) and Recurrence(item).rruleset
        if recurring:
            encoded_triage = eim.NoChange
        elif triage.manual and triage.manual_timestamp:
            code = normalize_triage_code(triage.manual)
            manual_timestamp = -1 * triage.manual_timestamp
            encoded_triage = "%s %.2f 0" % (code, manual_timestamp)
        else:
            encoded_triage = eim.Inherit

        yield model.ItemRecord(
            item,  # uuid
            self.obfuscate(mask.title),  # title
            encoded_triage,  # triage
            with_nochange(mask.created, decimal_int),  # createdOn
            eim.NoChange,  # hasBeenSent
            eim.NoChange,  # needsReply
            eim.NoChange,  # read
        )

        eim_wrapped = eim.EIM(item)

        yield model.NoteRecord(
            item,  # uuid
            self.obfuscate(mask.body),  # body
            empty_as_inherit(eim_wrapped, 'ical_uid'),  # icalUid
            eim.Inherit,  # icalendarProperties
            eim.Inherit,  # icalendarParameters
            empty_as_inherit(eim_wrapped, 'ical_extra')  # icalendarExtra
        )

        if not ReminderList(item).reminders:
            description = None
            trigger = None
            duration = None
            repeat = None

        elif not getattr(item, 'recurrence_id', False):
            reminder = ReminderList(item).reminders[0]
            trigger = None
            if reminder.delta:
                trigger = timedeltaToString(reminder.delta)
            elif reminder.fixed_trigger:
                fixed = reminder.fixed_trigger.astimezone(TimeZone.utc)
                trigger = toICalendarDateTime(fixed, False)

            duration = eim.NoChange
            repeat = eim.NoChange
            description = getattr(reminder, 'description', None)
            if not description:
                description = "Event Reminder"

        else:  # we've inherited this reminder
            description = eim.Inherit
            trigger = eim.Inherit
            duration = eim.Inherit
            repeat = eim.Inherit

        yield model.DisplayAlarmRecord(
            item,
            description,
            trigger,
            duration,
            repeat,
        )