Changeset View
Changeset View
Standalone View
Standalone View
pykolab/xml/recurrence_rule.py
Show First 20 Lines • Show All 175 Lines • ▼ Show 20 Lines | def _set_map_value(self, val, pmap, setter): | ||||
if isinstance(val, list): | if isinstance(val, list): | ||||
val = val[0] | val = val[0] | ||||
if val in pmap: | if val in pmap: | ||||
getattr(self, setter)(pmap[val]) | getattr(self, setter)(pmap[val]) | ||||
elif val in pmap.values(): | elif val in pmap.values(): | ||||
getattr(self, setter)(val) | getattr(self, setter)(val) | ||||
def _translate_value(self, val, map): | def _translate_value(self, val, map): | ||||
name_map = dict([(v, k) for (k, v) in map.iteritems()]) | name_map = dict([(v, k) for (k, v) in map.items()]) | ||||
return name_map[val] if val in name_map else 'UNKNOWN' | return name_map[val] if val in name_map else 'UNKNOWN' | ||||
def to_ical(self): | def to_ical(self): | ||||
rrule = icalendar.vRecur(dict((k,v) for k,v in self.to_dict(True).items() if not (type(v) == str and v == '' or type(v) == list and len(v) == 0))) | rrule = icalendar.vRecur(dict((k,v) for k,v in self.to_dict(True).items() if not (type(v) == str and v == '' or type(v) == list and len(v) == 0))) | ||||
return rrule | return rrule | ||||
def to_dict(self, raw=False): | def to_dict(self, raw=False): | ||||
if not self.isValid() or self.frequency() == kolabformat.RecurrenceRule.FreqNone: | if not self.isValid() or self.frequency() == kolabformat.RecurrenceRule.FreqNone: | ||||
return None | return None | ||||
data = dict() | data = dict() | ||||
for p, getter in self.properties_map.iteritems(): | for p, getter in self.properties_map.items(): | ||||
val = None | val = None | ||||
args = {} | args = {} | ||||
if hasattr(self, getter): | if hasattr(self, getter): | ||||
if getter.startswith('get_'): | if getter.startswith('get_'): | ||||
args = dict(translated=True) | args = dict(translated=True) | ||||
if hasattr(self, getter): | if hasattr(self, getter): | ||||
val = getattr(self, getter)(**args) | val = getattr(self, getter)(**args) | ||||
if isinstance(val, kolabformat.cDateTime): | if isinstance(val, kolabformat.cDateTime): | ||||
Show All 14 Lines |