Skip to content

Commit 5128161

Browse files
committed
finished new Query object
changed calendar get_events to comply with include recurring and new Query object
1 parent 12e6775 commit 5128161

File tree

2 files changed

+126
-96
lines changed

2 files changed

+126
-96
lines changed

O365/calendar.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,8 +1780,9 @@ def delete(self):
17801780

17811781
return True
17821782

1783-
def get_events(self, limit=25, *, query=None, order_by=None, batch=None,
1784-
download_attachments=False, include_recurring=True):
1783+
def get_events(self, limit: int = 25, *, query=None, order_by=None, batch=None,
1784+
download_attachments=False, include_recurring=True,
1785+
start_recurring=None, end_recurring=None):
17851786
""" Get events from this Calendar
17861787
17871788
:param int limit: max no. of events to get. Over 999 uses batch.
@@ -1793,6 +1794,8 @@ def get_events(self, limit=25, *, query=None, order_by=None, batch=None,
17931794
batches allowing to retrieve more items than the limit.
17941795
:param download_attachments: downloads event attachments
17951796
:param bool include_recurring: whether to include recurring events or not
1797+
:param start_recurring: a string datetime or a Query object with just a start condition
1798+
:param end_recurring: a string datetime or a Query object with just an end condition
17961799
:return: list of events in this calendar
17971800
:rtype: list[Event] or Pagination
17981801
"""
@@ -1822,22 +1825,29 @@ def get_events(self, limit=25, *, query=None, order_by=None, batch=None,
18221825
if include_recurring:
18231826
start = None
18241827
end = None
1825-
if query and not isinstance(query, str):
1826-
# extract start and end from query because
1827-
# those are required by a calendarView
1828-
start = query.get_filter_by_attribute('start/')
1829-
end = query.get_filter_by_attribute('start/')
1830-
1831-
if start:
1832-
start = start.replace("'", '') # remove the quotes
1833-
query.remove_filter('start')
1834-
if end:
1835-
end = end.replace("'", '') # remove the quotes
1836-
query.remove_filter('end')
1837-
1828+
if start_recurring is None:
1829+
pass
1830+
elif isinstance(start_recurring, str):
1831+
start = start_recurring
1832+
elif isinstance(start_recurring, dt.datetime):
1833+
start = start_recurring.isoformat()
1834+
else:
1835+
# it's a Query Object
1836+
start = start_recurring.get_filter_by_attribute('start/')
1837+
if end_recurring is None:
1838+
pass
1839+
elif isinstance(end_recurring, str):
1840+
end = end_recurring
1841+
elif isinstance(end_recurring, dt.datetime):
1842+
end = end_recurring.isoformat()
1843+
else:
1844+
# it's a Query Object
1845+
end = end_recurring.get_filter_by_attribute('end/')
18381846
if start is None or end is None:
18391847
raise ValueError("When 'include_recurring' is True you must provide "
1840-
"a 'start' and 'end' datetime inside a 'Query' instance.")
1848+
"a 'start_recurring' and 'end_recurring' with a datetime string.")
1849+
start = start.replace("'", '') # remove the quotes
1850+
end = end.replace("'", '') # remove the quotes
18411851

18421852
params[self._cc('startDateTime')] = start
18431853
params[self._cc('endDateTime')] = end

0 commit comments

Comments
 (0)