* Don't force to pass a list to vDDDLists and allow setting individual RDATE

and EXDATE values without having to wrap them in a list.
* Fix encoding function to allow setting RDATE and EXDATE values and not to
  have bypass encoding with an icalendar property.
pull/86/head
Johannes Raggam 2013-01-29 23:48:58 +01:00
rodzic c2a77b45a7
commit 8f48b074f0
4 zmienionych plików z 45 dodań i 24 usunięć

Wyświetl plik

@ -4,6 +4,14 @@ Changelog
3.3dev (unreleased)
-------------------
* Don't force to pass a list to vDDDLists and allow setting individual RDATE
and EXDATE values without having to wrap them in a list.
[thet]
* Fix encoding function to allow setting RDATE and EXDATE values and not to
have bypass encoding with an icalendar property.
[thet]
* Allow setting of timezone for vDDDLists and support timezone properties for
RDATE and EXDATE component properties.
[thet]

Wyświetl plik

@ -235,16 +235,19 @@ class Component(CaselessDict):
"""Conditional convertion of values.
"""
if cond:
klass = types_factory.for_property(name)
_klass = klass(value)
if hasattr(value, 'params') and len(value.params.keys()) > 0:
_klass.params = value.params
return _klass
return value
if not cond: return value
klass = types_factory.for_property(name)
obj = klass(value)
if hasattr(value, 'params') and len(value.params.keys()) > 0:
# TODO: How can a python native value have params?
obj.params = value.params
return obj
def set(self, name, value, encode=1):
if type(value) == ListType:
if encode and type(value) == ListType\
and name.lower() not in ['rdate', 'exdate']:
# Individually convert each value to an ical type except rdate and
# exdate, which encoded to vDDDLists, which needs a list
self[name] = [self._encode(name, v, encode) for v in value]
else:
self[name] = self._encode(name, value, encode)

Wyświetl plik

@ -340,11 +340,6 @@ class vDDDLists:
>>> str(dt_list[2])
'1996-04-04 01:00:00+00:00'
>>> dt_list = vDDDLists('19960402T010000Z')
Traceback (most recent call last):
...
ValueError: Value MUST be a list (of date instances)
>>> dt_list = vDDDLists([])
>>> dt_list.to_ical()
''
@ -357,20 +352,11 @@ class vDDDLists:
>>> dt_list.to_ical()
'20000101T000000,20001111T000000'
Timezone support
>>> from icalendar import Event
>>> at = pytz.timezone('Europe/Vienna')
>>> dt = at.localize(datetime(2013,1,29))
>>> event = Event()
>>> event.add('rdate', vDDDLists([dt]), encode=0)
>>> out = event.to_ical()
>>> assert("RDATE;TZID=Europe/Vienna:20130129T000000" in out)
"""
def __init__(self, dt_list):
if not isinstance(dt_list, list):
raise ValueError('Value MUST be a list (of date instances)')
if not hasattr(dt_list, '__iter__'):
dt_list = [dt_list]
vDDD = []
tzid = None
for dt in dt_list:

Wyświetl plik

@ -0,0 +1,24 @@
import datetime
import unittest
import icalendar
import pytz
class TestPropertyValues(unittest.TestCase):
def test_vDDDLists_timezone(self):
e = icalendar.Event()
at = pytz.timezone('Europe/Vienna')
dt1 = at.localize(datetime.datetime(2013,1,1))
dt2 = at.localize(datetime.datetime(2013,1,2))
dt3 = at.localize(datetime.datetime(2013,1,3))
e.add('rdate', [dt1, dt2])
e.add('exdate', dt3)
out = e.to_ical()
import pdb; pdb.set_trace()
self.assertTrue('RDATE;TZID=Europe/Vienna:20130101T000000,20130102T000000' in out)
self.assertTrue('EXDATE;TZID=Europe/Vienna:20130103T000000' in out)
#'BEGIN:VEVENT\r\nDTSTART;TZID=Europe/Vienna;VALUE=DATE-TIME:20130101T000000\r\nRDATE;TZID=Europe/Vienna:20130101T000000,20130102T000000\r\nEXDATE;TZID=Europe/Vienna:20130103T000000\r\nEND:VEVENT\r\n'