Skip to content

Commit

Permalink
Added sort_reverse option on Calendar.search to reverse the sorting o…
Browse files Browse the repository at this point in the history
…rder of the found objects
  • Loading branch information
twissell- authored and tobixen committed Aug 13, 2024
1 parent 54ecadf commit 9390d8e
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions caldav/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,9 @@ class hierarchy into a separate file)
import sys
import uuid
from collections import defaultdict
from datetime import date
from datetime import datetime
from datetime import timedelta
from datetime import timezone
from typing import Any
from typing import List
from typing import Optional
from typing import Set
from typing import Tuple
from typing import TYPE_CHECKING
from typing import TypeVar
from typing import Union
from urllib.parse import ParseResult
from urllib.parse import quote
from urllib.parse import SplitResult
from urllib.parse import unquote
from datetime import date, datetime, timedelta, timezone
from typing import TYPE_CHECKING, Any, List, Optional, Set, Tuple, TypeVar, Union
from urllib.parse import ParseResult, SplitResult, quote, unquote

import icalendar
import vobject
Expand All @@ -35,12 +22,10 @@ class hierarchy into a separate file)
from lxml.etree import _Element
from vobject.base import VBase

from caldav.lib.python_utilities import to_normal_str, to_unicode, to_wire

from .elements.base import BaseElement
from .elements.cdav import CalendarData
from .elements.cdav import CompFilter
from caldav.lib.python_utilities import to_normal_str
from caldav.lib.python_utilities import to_unicode
from caldav.lib.python_utilities import to_wire
from .elements.cdav import CalendarData, CompFilter

try:
from typing import ClassVar, Optional, Union
Expand Down Expand Up @@ -1132,6 +1117,7 @@ def search(
todo: Optional[bool] = None,
include_completed: bool = False,
sort_keys: Sequence[str] = (),
sort_reverse: bool = False,
split_expanded: bool = True,
props: Optional[List[CalendarData]] = None,
**kwargs,
Expand Down Expand Up @@ -1163,6 +1149,7 @@ def search(
* start, end: do a time range search
* filters - other kind of filters (in lxml tree format)
* sort_keys - list of attributes to use when sorting
* sort_reverse - reverse the sorting order
not supported yet:
* negated text match
Expand Down Expand Up @@ -1290,7 +1277,7 @@ def sort_key_func(x):
return ret

if sort_keys:
objects.sort(key=sort_key_func)
objects.sort(key=sort_key_func, reverse=sort_reverse)

## partial workaround for https://github.com/python-caldav/caldav/issues/201
for obj in objects:
Expand Down

0 comments on commit 9390d8e

Please sign in to comment.