Skip to content

Commit 875b3fe

Browse files
committed
tweaking both the test code and adding support for supression of completed recurrences in the rrule expanding
1 parent 3a2b4ed commit 875b3fe

3 files changed

Lines changed: 49 additions & 5 deletions

File tree

caldav/calendarobjectresource.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def split_expanded(self) -> List[Self]:
160160
ret.append(obj)
161161
return ret
162162

163-
def expand_rrule(self, start: datetime, end: datetime) -> None:
163+
def expand_rrule(self, start: datetime, end: datetime, include_completed: bool=True) -> None:
164164
"""This method will transform the calendar content of the
165165
event and expand the calendar data from a "master copy" with
166166
RRULE set and into a "recurrence set" with RECURRENCE-ID set
@@ -186,6 +186,7 @@ def expand_rrule(self, start: datetime, end: datetime) -> None:
186186
# FIXME too much copying
187187
stripped_event = self.copy(keep_uid=True)
188188

189+
## TODO: use icalendar_instance instead
189190
if stripped_event.vobject_instance is None:
190191
raise ValueError(
191192
"Unexpected value None for stripped_event.vobject_instance"
@@ -203,6 +204,9 @@ def expand_rrule(self, start: datetime, end: datetime) -> None:
203204
calendar = self.icalendar_instance
204205
calendar.subcomponents = []
205206
for occurrence in recurrings:
207+
## Ignore completed task recurrences
208+
if not include_completed and occurrence.name=='VTODO' and occurrence.get('STATUS') in ('COMPLETED', 'CANCELLED'):
209+
continue
206210
if "RECURRENCE-ID" not in occurrence:
207211
occurrence.add("RECURRENCE-ID", occurrence.get("DTSTART"))
208212
calendar.add_component(occurrence)

caldav/collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ def search(
924924
continue
925925
recurrence_properties = ["exdate", "exrule", "rdate", "rrule"]
926926
if any(key in component for key in recurrence_properties):
927-
o.expand_rrule(start, end)
927+
o.expand_rrule(start, end, include_completed=include_completed)
928928

929929
## An expanded recurring object comes as one Event() with
930930
## icalendar data containing multiple objects. The caller may

tests/test_caldav_unit.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,30 @@
193193
UID:8a8736b4-bc35-4085-a98b-89c2f52a5c51
194194
SEQUENCE:1
195195
CREATED:20250411T234336Z
196+
LAST-MODIFIED:20250414T082134Z
197+
SUMMARY:Clean Rosie filter
198+
STATUS:CANCELLED
199+
DTSTART;VALUE=DATE:20250418
200+
RECURRENCE-ID;VALUE=DATE:20250418
201+
PRIORITY:0
202+
END:VTODO
203+
BEGIN:VTODO
204+
DTSTAMP:20250522T075151Z
205+
UID:8a8736b4-bc35-4085-a98b-89c2f52a5c51
206+
SEQUENCE:1
207+
CREATED:20250411T234336Z
208+
LAST-MODIFIED:20250414T082134Z
209+
SUMMARY:Clean Rosie filter
210+
STATUS:CANCELLED
211+
DTSTART;VALUE=DATE:20250422
212+
RECURRENCE-ID;VALUE=DATE:20250422
213+
PRIORITY:0
214+
END:VTODO
215+
BEGIN:VTODO
216+
DTSTAMP:20250522T075151Z
217+
UID:8a8736b4-bc35-4085-a98b-89c2f52a5c51
218+
SEQUENCE:1
219+
CREATED:20250411T234336Z
196220
LAST-MODIFIED:20250425T124511Z
197221
SUMMARY:Clean Rosie filter
198222
STATUS:COMPLETED
@@ -207,6 +231,20 @@
207231
UID:8a8736b4-bc35-4085-a98b-89c2f52a5c51
208232
SEQUENCE:1
209233
CREATED:20250411T234336Z
234+
LAST-MODIFIED:20250425T124511Z
235+
SUMMARY:Clean Rosie filter
236+
STATUS:CANCELLED
237+
DTSTART;VALUE=DATE:20250429
238+
RECURRENCE-ID;VALUE=DATE:20250429
239+
COMPLETED:20250425T124511Z
240+
PERCENT-COMPLETE:100
241+
PRIORITY:0
242+
END:VTODO
243+
BEGIN:VTODO
244+
DTSTAMP:20250522T075151Z
245+
UID:8a8736b4-bc35-4085-a98b-89c2f52a5c51
246+
SEQUENCE:1
247+
CREATED:20250411T234336Z
210248
LAST-MODIFIED:20250502T113705Z
211249
SUMMARY:Clean Rosie filter
212250
STATUS:COMPLETED
@@ -357,15 +395,17 @@ def testSearchForRecurringTask(self):
357395
mytasks = calendar.search(
358396
todo=True,
359397
expand="client",
360-
start=datetime(2025, 6, 6),
361-
end=datetime(2025, 7, 6),
398+
start=datetime(2025, 5, 5),
399+
end=datetime(2025, 6, 5),
362400
)
363401
assert len(mytasks) == 9
402+
403+
## It should not include the COMPLETED recurrences
364404
mytasks = calendar.search(
365405
todo=True,
366406
expand="client",
367407
start=datetime(2025, 1, 1),
368-
end=datetime(2025, 7, 6),
408+
end=datetime(2025, 6, 5),
369409
)
370410
assert len(mytasks) == 9
371411

0 commit comments

Comments
 (0)