Small refactor in dav.py

This commit is contained in:
Markus Unterwaditzer 2017-10-26 02:22:18 +02:00
parent f7b6e67095
commit bd2e09a84b

View file

@ -792,32 +792,28 @@ class CalDAVStorage(DAVStorage):
@staticmethod @staticmethod
def _get_list_filters(components, start, end): def _get_list_filters(components, start, end):
if components: caldavfilter = '''
caldavfilter = ''' <C:comp-filter name="VCALENDAR">
<C:comp-filter name="VCALENDAR"> <C:comp-filter name="{component}">
<C:comp-filter name="{component}"> {timefilter}
{timefilter}
</C:comp-filter>
</C:comp-filter> </C:comp-filter>
''' </C:comp-filter>
'''
if start is not None and end is not None: timefilter = ''
start = start.strftime(CALDAV_DT_FORMAT)
end = end.strftime(CALDAV_DT_FORMAT)
timefilter = ('<C:time-range start="{start}" end="{end}"/>' if start is not None and end is not None:
.format(start=start, end=end)) start = start.strftime(CALDAV_DT_FORMAT)
else: end = end.strftime(CALDAV_DT_FORMAT)
timefilter = ''
for component in components: timefilter = ('<C:time-range start="{start}" end="{end}"/>'
yield caldavfilter.format(component=component, .format(start=start, end=end))
timefilter=timefilter) if not components:
else: components = ('VTODO', 'VEVENT')
if start is not None and end is not None:
for x in CalDAVStorage._get_list_filters(('VTODO', 'VEVENT'), for component in components:
start, end): yield caldavfilter.format(component=component,
yield x timefilter=timefilter)
def list(self): def list(self):
caldavfilters = list(self._get_list_filters( caldavfilters = list(self._get_list_filters(
@ -833,8 +829,8 @@ class CalDAVStorage(DAVStorage):
# instead? # instead?
# #
# See https://github.com/dmfs/tasks/issues/118 for backstory. # See https://github.com/dmfs/tasks/issues/118 for backstory.
for x in DAVStorage.list(self): yield from DAVStorage.list(self)
yield x return
data = '''<?xml version="1.0" encoding="utf-8" ?> data = '''<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" <C:calendar-query xmlns:D="DAV:"