Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/656.feature.1
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions src/icalendar/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -853,6 +868,7 @@ def _del_GAP(prop): # noqa: N802
"LANGUAGE",
"LINKREL",
"MEMBER",
"ORDER",
"PARTSTAT",
"RANGE",
"RELATED",
Expand Down
2 changes: 1 addition & 1 deletion src/icalendar/prop/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this just imported?


def to_jcal(self, name: str) -> list:
"""The jCal representation of this property according to :rfc:`7265`."""
Expand Down
23 changes: 23 additions & 0 deletions src/icalendar/tests/prop/test_order_param.py
Original file line number Diff line number Diff line change
@@ -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
Loading