Code Repositories xandikos / 4c87142
Add support for calendar-order property. Jelmer Vernooń≥ 22 days ago
6 changed file(s) with 73 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
249249 ^^^^^^^^^^^^^^^^^^^^^^^^^
250250
251251 - calendar-color [supported]
252 - calendar-order [supported]
252253 - getctag [supported]
253254 - refreshrate [supported]
254255
7676 """Set the calendar color."""
7777 raise NotImplementedError(self.set_calendar_color)
7878
79 def get_calendar_order(self):
80 """Return the calendar order."""
81 raise NotImplementedError(self.get_calendar_order)
82
83 def set_calendar_order(self, order):
84 """Set the calendar order."""
85 raise NotImplementedError(self.set_calendar_order)
86
7987 def get_calendar_timezone(self):
8088 """Return calendar timezone.
8189
251259 # TODO(jelmer): Don't hardcode encoding
252260 # TODO(jelmer): Strip invalid characters or raise an exception
253261 el.text = serialized_cal.decode('utf-8')
262
263
264 class CalendarOrderProperty(webdav.Property):
265 """Provides calendar-order property.
266 """
267
268 name = '{http://apple.com/ns/ical/}calendar-order'
269 resource_type = CALENDAR_RESOURCE_TYPE
270
271 def get_value(self, base_href, resource, el, environ):
272 el.text = resource.get_calendar_order()
273
274 def set_value(self, href, resource, el):
275 resource.set_calendar_order(el.text)
254276
255277
256278 class CalendarMultiGetReporter(davcommon.MultiGetReporter):
4444
4545 def get_description(self):
4646 raise NotImplementedError(self.get_description)
47
48 def get_order(self):
49 raise NotImplementedError(self.get_order)
50
51 def set_order(self, order):
52 raise NotImplementedError(self.set_order)
4753
4854
4955 class FileBasedCollectionMetadata(CollectionMetadata):
112118
113119 def get_type(self):
114120 return self._configparser['DEFAULT']['type']
121
122 def get_order(self):
123 return self._configparser['calendar']['order']
124
125 def set_order(self, order):
126 try:
127 self._configparser.add_section('calendar')
128 except configparser.DuplicateSectionError:
129 pass
130 if order is None:
131 del self._configparser['calendar']['order']
132 else:
133 self._configparser['calendar']['order'] = order
155155 'Invalid store type %s set for %r.',
156156 store_type, self.repo)
157157 return store_type
158
159 def get_order(self):
160 config = self._repo.get_config()
161 order = config.get(b'xandikos', b'calendar-order')
162 if order == b'':
163 raise KeyError
164 return order.decode('utf-8')
165
166 def set_order(self, order):
167 config = self._repo.get_config()
168 if order is None:
169 order = ''
170 config.set(b'xandikos', b'calendar-order', order.encode('utf-8'))
171 self._write_config(config)
158172
159173
160174 class locked_index(object):
111111 self._config.set_description(None)
112112 self.assertRaises(KeyError, self._config.get_description)
113113
114 def test_order(self):
115 self.assertRaises(KeyError, self._config.get_order)
116 self._config.set_order('this is a order')
117 self.assertEqual('this is a order', self._config.get_order())
118 self._config.set_order(None)
119 self.assertRaises(KeyError, self._config.get_order)
120
114121
115122 class FileMetadataTests(TestCase, MetadataTests):
116123
402402
403403 def set_calendar_color(self, color):
404404 self.store.set_color(color)
405
406 def get_calendar_order(self):
407 order = self.store.config.get_order()
408 if not order:
409 raise KeyError
410 return order
411
412 def set_calendar_order(self, order):
413 self.store.config.set_order(order)
405414
406415 def get_calendar_timezone(self):
407416 # TODO(jelmer): Read a magic file from the store?
856865 carddav.AddressbookHomeSetProperty(),
857866 caldav.CalendarDescriptionProperty(),
858867 caldav.CalendarColorProperty(),
868 caldav.CalendarOrderProperty(),
859869 caldav.SupportedCalendarComponentSetProperty(),
860870 carddav.AddressbookDescriptionProperty(),
861871 carddav.PrincipalAddressProperty(),