Skip to content

Commit

Permalink
accept multiple addresses per calendar account
Browse files Browse the repository at this point in the history
  • Loading branch information
geier committed Nov 15, 2023
1 parent df8259d commit 2d37e0c
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ not released yet
tentative)
* NEW event format option `partstat-symbol` which represents the participation
status of an event with a symbol (e.g. `` for accepted, `` for declined,
`?` for tentative); partication status is shown for the email address
`?` for tentative); partication status is shown for the email addresses
configured for the event's calendar

0.11.2
Expand Down
2 changes: 1 addition & 1 deletion khal/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def build_collection(conf, selection):
'color': cal['color'],
'priority': cal['priority'],
'ctype': cal['type'],
'address': cal['address'],
'addresses': cal['addresses'],
}
collection = khalendar.CalendarCollection(
calendars=props,
Expand Down
2 changes: 1 addition & 1 deletion khal/custom_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CalendarConfiguration(TypedDict):
color: str
priority: int
ctype: str
address: str
addresses: str


class LocaleConfiguration(TypedDict):
Expand Down
11 changes: 6 additions & 5 deletions khal/khalendar/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self,
color: Optional[str] = None,
start: Optional[dt.datetime] = None,
end: Optional[dt.datetime] = None,
address: str = '',
addresses: Optional[List[str]] =None,
):
"""
:param start: start datetime of this event instance
Expand All @@ -88,7 +88,7 @@ def __init__(self,
self.color = color
self._start: dt.datetime
self._end: dt.datetime
self.address = address
self.addresses = addresses if addresses else []

if start is None:
self._start = self._vevents[self.ref]['DTSTART'].dt
Expand Down Expand Up @@ -808,9 +808,10 @@ def status(self) -> str:
@property
def partstat(self) -> Optional[str]:
for attendee in self._vevents[self.ref].get('ATTENDEE', []):
print(attendee)
if attendee == 'mailto:' + self.address:
return attendee.params.get('PARTSTAT', '')
for address in self.addresses:
if attendee == 'mailto:' + address:
return attendee.params.get('PARTSTAT', '')
return None


class DatetimeEvent(Event):
Expand Down
2 changes: 1 addition & 1 deletion khal/khalendar/khalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def _construct_event(self,
ref=ref,
color=self._calendars[calendar]['color'],
readonly=self._calendars[calendar]['readonly'],
address=self._calendars[calendar]['address'],
addresses=self._calendars[calendar]['addresses'],
)
return event

Expand Down
7 changes: 4 additions & 3 deletions khal/settings/khal.spec
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ readonly = boolean(default=False)
# *calendars* subsection will be used.
type = option('calendar', 'birthdays', 'discover', default='calendar')

# The email address associated with this account. For now it is only used to
# check what participation status ("PARTSTAT") belongs to the user.
address = string(default='')
# All email addresses associated with this account, separated by commas.
# For now it is only used to check what participation status ("PARTSTAT")
# belongs to the user.
addresses = force_list(default='')

[sqlite]
# khal stores its internal caching database here, by default this will be in the *$XDG_DATA_HOME/khal/khal.db* (this will most likely be *~/.local/share/khal/khal.db*).
Expand Down
2 changes: 1 addition & 1 deletion tests/configs/small.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
[[work]]
path = ~/.calendars/work/
readonly = True
address = [email protected]
addresses = [email protected]
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def coll_vdirs(tmpdir) -> CollVdirType:
color='dark blue',
priority=10,
ctype='calendar',
address='[email protected]',
addresses='[email protected]',
)
vdirs[name] = Vdir(path, '.ics')
coll = CalendarCollection(calendars=calendars, dbpath=':memory:', locale=LOCALE_BERLIN)
Expand All @@ -73,7 +73,7 @@ def coll_vdirs_birthday(tmpdir):
readonly = True if name == 'a_calendar' else False
calendars[name] = {'name': name, 'path': path, 'color': 'dark blue',
'readonly': readonly, 'unicode_symbols': True, 'ctype': 'birthdays',
'address': '[email protected]'}
'addresses': '[email protected]'}
vdirs[name] = Vdir(path, '.vcf')
coll = CalendarCollection(calendars=calendars, dbpath=':memory:', locale=LOCALE_BERLIN)
coll.default_calendar_name = cal1
Expand Down
14 changes: 7 additions & 7 deletions tests/event_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ def test_status_confirmed():
FORMAT_CALENDAR = ('{calendar-color}{status-symbol}{start-end-time-style} ({calendar}) '
'{title} [{location}]{repeat-symbol}')

assert event.format(FORMAT_CALENDAR, dt.date(2014, 4, 9)) == \
' ✔09:30-10:30 (foobar) An Event []\x1b[0m'
assert human_formatter(FORMAT_CALENDAR)(event.attributes(dt.date(2014, 4, 9))) == \
'✔09:30-10:30 (foobar) An Event []\x1b[0m'

def test_event_d_long():
event_d_long = _get_text('event_d_long')
Expand Down Expand Up @@ -703,29 +703,29 @@ def test_partstat():
)

event = Event.fromString(
_get_text('event_dt_partstat'), address='[email protected]', **EVENT_KWARGS)
_get_text('event_dt_partstat'), addresses=['[email protected]'], **EVENT_KWARGS)
assert event.partstat == 'ACCEPTED'
assert human_formatter(FORMAT_CALENDAR)(event.attributes(dt.date(2014, 4, 9))) == \
'✔09:30-10:30 (foobar) An Event []\x1b[0m'

event = Event.fromString(
_get_text('event_dt_partstat'), address='[email protected]', **EVENT_KWARGS)
_get_text('event_dt_partstat'), addresses=['[email protected]'], **EVENT_KWARGS)
assert event.partstat == 'DECLINED'
assert human_formatter(FORMAT_CALENDAR)(event.attributes(dt.date(2014, 4, 9))) == \
'❌09:30-10:30 (foobar) An Event []\x1b[0m'

event = Event.fromString(
_get_text('event_dt_partstat'), address='[email protected]', **EVENT_KWARGS)
_get_text('event_dt_partstat'), addresses=['[email protected]'], **EVENT_KWARGS)
assert event.partstat == 'ACCEPTED'
assert human_formatter(FORMAT_CALENDAR)(event.attributes(dt.date(2014, 4, 9))) == \
'✔09:30-10:30 (foobar) An Event []\x1b[0m'

@pytest.mark.xfail
def test_partstat_deligated():
event = Event.fromString(
_get_text('event_dt_partstat'), address='[email protected]', **EVENT_KWARGS)
_get_text('event_dt_partstat'), addresses=['[email protected]'], **EVENT_KWARGS)
assert event.partstat == 'ACCEPTED'

event = Event.fromString(
_get_text('event_dt_partstat'), address='[email protected]', **EVENT_KWARGS)
_get_text('event_dt_partstat'), addresses=['[email protected]'], **EVENT_KWARGS)
assert event.partstat == 'ACCEPTED'
8 changes: 4 additions & 4 deletions tests/settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ def test_simple_config(self):
'calendars': {
'home': {
'path': os.path.expanduser('~/.calendars/home/'), 'readonly': False,
'color': None, 'priority': 10, 'type': 'calendar', 'address': '',
'color': None, 'priority': 10, 'type': 'calendar', 'addresses': [''],
},
'work': {
'path': os.path.expanduser('~/.calendars/work/'), 'readonly': False,
'color': None, 'priority': 10, 'type': 'calendar', 'address': '',
'color': None, 'priority': 10, 'type': 'calendar', 'addresses': [''],
},
},
'sqlite': {'path': os.path.expanduser('~/.local/share/khal/khal.db')},
Expand Down Expand Up @@ -85,10 +85,10 @@ def test_small(self):
'calendars': {
'home': {'path': os.path.expanduser('~/.calendars/home/'),
'color': 'dark green', 'readonly': False, 'priority': 20,
'type': 'calendar', 'address': ''},
'type': 'calendar', 'addresses': ['']},
'work': {'path': os.path.expanduser('~/.calendars/work/'),
'readonly': True, 'color': None, 'priority': 10,
'type': 'calendar', 'address': '[email protected]'}},
'type': 'calendar', 'addresses': ['[email protected]']}},
'sqlite': {'path': os.path.expanduser('~/.local/share/khal/khal.db')},
'locale': {
'local_timezone': get_localzone(),
Expand Down

0 comments on commit 2d37e0c

Please sign in to comment.