diff --git a/news/656.feature.1 b/news/656.feature.1 new file mode 100644 index 000000000..28d78560f --- /dev/null +++ b/news/656.feature.1 @@ -0,0 +1 @@ +Added the ``ORDER`` property parameter from :rfc:`9073#section-5.1` (Event Publishing Extensions to iCalendar). It is available on any TEXT-valued property (such as :class:`~icalendar.prop.text.vText`, used by ``CONTACT``). See :issue:`656`. @HannaEpelboim \ No newline at end of file diff --git a/src/icalendar/param.py b/src/icalendar/param.py index bca86330f..1d4cdf7ea 100644 --- a/src/icalendar/param.py +++ b/src/icalendar/param.py @@ -838,6 +838,21 @@ def _del_GAP(prop): # noqa: N802 GAP = property(_get_GAP, _set_GAP, _del_GAP) +ORDER = string_parameter( + "ORDER", + """Specify the ordering of the property instance it is attached to. + + Conformance: + This property parameter is specified in :rfc:`9073#section-5.1`. + + The value is an integer >= 1, with a value of 1 + meaning the instance appears first. + """, + default=lambda: None, + convert=int, + convert_to=str, +) + __all__ = [ "ALTREP", "CN", @@ -853,6 +868,7 @@ def _del_GAP(prop): # noqa: N802 "LANGUAGE", "LINKREL", "MEMBER", + "ORDER", "PARTSTAT", "RANGE", "RELATED", diff --git a/src/icalendar/prop/text.py b/src/icalendar/prop/text.py index 3c4e7f5c1..2b2207bcc 100644 --- a/src/icalendar/prop/text.py +++ b/src/icalendar/prop/text.py @@ -173,7 +173,7 @@ def ical_value(self) -> str: """The string value of the text.""" return str(self) - from icalendar.param import ALTREP, GAP, LANGUAGE, RELTYPE, VALUE + from icalendar.param import ALTREP, GAP, LANGUAGE, ORDER, RELTYPE, VALUE def to_jcal(self, name: str) -> list: """The jCal representation of this property according to :rfc:`7265`.""" diff --git a/src/icalendar/tests/prop/test_order_param.py b/src/icalendar/tests/prop/test_order_param.py new file mode 100644 index 000000000..d3440f7ac --- /dev/null +++ b/src/icalendar/tests/prop/test_order_param.py @@ -0,0 +1,23 @@ +from icalendar import Event, vText + + +def test_order_default_is_none(): + """ORDER is absent by default, meaning 'comes last'.""" + contact = vText("Dev") + assert contact.ORDER is None + + +def test_order_round_trips_as_int(): + """Setting ORDER stores an int and reads back the same int.""" + contact = vText("Dev") + contact.ORDER = 1 + assert contact.ORDER == 1 + assert contact.params["ORDER"] == "1" + + +def test_order_parses_from_ical(): + """A CONTACT with ORDER set in a real .ics round-trips through from_ical.""" + ics = "BEGIN:VEVENT\r\nCONTACT;ORDER=2:Dev\r\nEND:VEVENT\r\n" + event = Event.from_ical(ics) + [contact] = event.contacts + assert contact.ORDER == 2