From 26b96502fef4adb5dcfd19129d5e300cff3c328e Mon Sep 17 00:00:00 2001 From: Rafikk47 Date: Sun, 11 Dec 2022 22:24:42 +0100 Subject: [PATCH 1/2] attribut CLASS --- khal/controllers.py | 4 ++-- khal/icalendar.py | 8 +++++++- khal/khalendar/event.py | 15 +++++++++++++++ khal/khalendar/khalendar.py | 11 ++++------- khal/ui/__init__.py | 3 +++ khal/ui/editor.py | 14 ++++++++++++++ 6 files changed, 45 insertions(+), 10 deletions(-) diff --git a/khal/controllers.py b/khal/controllers.py index 8054874a3..d1fb03479 100644 --- a/khal/controllers.py +++ b/khal/controllers.py @@ -226,9 +226,9 @@ def get_events_between( def khal_list( collection, daterange: Optional[List[str]]=None, - conf: Optional[dict] = None, + conf: dict = None, agenda_format=None, - day_format: Optional[str]=None, + day_format: str=None, once=False, notstarted: bool = False, width: bool = False, diff --git a/khal/icalendar.py b/khal/icalendar.py index b9d6334aa..da40007b1 100644 --- a/khal/icalendar.py +++ b/khal/icalendar.py @@ -86,6 +86,7 @@ def new_vevent(locale, location: Optional[str]=None, categories: Optional[Union[List[str], str]]=None, repeat: Optional[str]=None, + Class: Optional[str]=None, until=None, alarms: Optional[str]=None, url: Optional[str]=None, @@ -125,9 +126,14 @@ def new_vevent(locale, event.add('categories', categories) if url: event.add('url', icalendar.vUri(url)) + if repeat and repeat != "none": rrule = rrulefstr(repeat, until, locale, getattr(dtstart, 'tzinfo', None)) event.add('rrule', rrule) + + if Class and Class !="none": + event.add('CLASS',Class) + if alarms: for alarm in alarms.split(","): alarm = alarm.strip() @@ -493,7 +499,7 @@ def delete_instance(vevent: icalendar.Event, instance: dt.datetime) -> None: vevent.pop('EXDATE') vevent.add('EXDATE', exdates) if 'RDATE' in vevent: - rdates = [one for one in _get_all_properties(vevent, 'RDATE') if one != instance] + rdates = [one for one in _get_allz_properties(vevent, 'RDATE') if one != instance] vevent.pop('RDATE') if rdates != []: vevent.add('RDATE', rdates) diff --git a/khal/khalendar/event.py b/khal/khalendar/event.py index 8f3a88fc0..d7d58d316 100644 --- a/khal/khalendar/event.py +++ b/khal/khalendar/event.py @@ -343,12 +343,26 @@ def organizer(self) -> str: else: return email + + @property + def Class(self) -> str: + if 'CLASS' not in self._vevents[self.ref]: + return '' + return self._vevents[self.ref]['CLASS'] + + def update_Class(self, Class: str) -> None: + if Class: + self._vevents[self.ref]['CLASS'] = Class + else: + self._vevents[self.ref].pop('CLASS') + @property def url(self) -> str: if 'URL' not in self._vevents[self.ref]: return '' return self._vevents[self.ref]['URL'] + def update_url(self, url: str) -> None: if url: self._vevents[self.ref]['URL'] = url @@ -694,6 +708,7 @@ def format(self, format_string: str, relative_to, env=None, colors: bool=True): attributes["categories"] = self.categories attributes['uid'] = self.uid attributes['url'] = self.url + attributes['CLASS'] = self.Class if "calendars" in env and self.calendar in env["calendars"]: cal = env["calendars"][self.calendar] diff --git a/khal/khalendar/khalendar.py b/khal/khalendar/khalendar.py index 31b50ccb6..7c2806b92 100644 --- a/khal/khalendar/khalendar.py +++ b/khal/khalendar/khalendar.py @@ -191,13 +191,10 @@ def force_update(self, event: Event, collection: Optional[str]=None) -> None: self._backend.update(event.raw, href, etag, calendar=calendar) self._backend.set_ctag(self._local_ctag(calendar), calendar=calendar) - def insert(self, event: Event, collection: Optional[str]=None) -> None: - """Insert a new event to the vdir and the database - - The event will get a new href and etag properties. If ``collection`` is - ``None``, then ``event.calendar`` must be defined. - - :param event: the event to be inserted. + def insert(self, event: Event, collection: Optional[str]=None) -> Event: + """insert a new event to the vdir and the database + :param event: the event that should be inserted, it will get a new href + and etag properties """ # TODO FIXME not all `event`s are actually of type Event, we also uptade # with vdir.Items. Those don't have an .href or .etag property which we diff --git a/khal/ui/__init__.py b/khal/ui/__init__.py index 41b2ca9fe..7e7aaef2e 100644 --- a/khal/ui/__init__.py +++ b/khal/ui/__init__.py @@ -965,6 +965,9 @@ def __init__(self, conf, event, collection=None): if event.url != '': lines.append(urwid.Text('URL: ' + event.url)) + if event.Class != '': + lines.append(urwid.Text('CLASS: ' + event.Class)) + if event.attendees != '': lines.append(urwid.Text('Attendees:')) for attendee in event.attendees.split(', '): diff --git a/khal/ui/editor.py b/khal/ui/editor.py index 3edf3b0ce..12cf435f0 100644 --- a/khal/ui/editor.py +++ b/khal/ui/editor.py @@ -341,6 +341,9 @@ def __init__(self, pane, event, save_callback=None, always_save=False): self.attendees = event.attendees self.categories = event.categories self.url = event.url + + self.Class = event.Class + self.startendeditor = StartEndEditor( event.start_local, event.end_local, self._conf, self.start_datechange, self.end_datechange, @@ -389,6 +392,11 @@ def decorate_choice(c): self.url = urwid.AttrMap(ExtendedEdit( caption=('', 'URL: '), edit_text=self.url), 'edit' ) + + self.Class = urwid.AttrMap(ExtendedEdit( + caption=('', 'CLASS [Private or Public]: '), edit_text=self.Class), 'edit' + ) + self.alarms = AlarmsEditor(self.event) self.pile = NListBox(urwid.SimpleFocusListWalker([ self.summary, @@ -398,6 +406,7 @@ def decorate_choice(c): self.categories, self.description, self.url, + self.Class, divider, self.attendees, divider, @@ -439,6 +448,10 @@ def changed(self): return True if get_wrapped_text(self.url) != self.event.url: return True + + if get_wrapped_text(self.Class) != self.event.Class: + return True + if get_wrapped_text(self.attendees) != self.event.attendees: return True if self.startendeditor.changed or self.calendar_chooser.changed: @@ -456,6 +469,7 @@ def update_vevent(self): self.event.update_attendees(get_wrapped_text(self.attendees).split(',')) self.event.update_categories(get_wrapped_text(self.categories).split(',')) self.event.update_url(get_wrapped_text(self.url)) + self.event.update_Class(get_wrapped_text(self.Class)) if self.startendeditor.changed: self.event.update_start_end( From 1a1c4daf84d703839e6bd3c5146cfddf8f073f44 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 11 Dec 2022 22:46:30 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- khal/khalendar/event.py | 2 +- khal/ui/editor.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/khal/khalendar/event.py b/khal/khalendar/event.py index d7d58d316..a64da473e 100644 --- a/khal/khalendar/event.py +++ b/khal/khalendar/event.py @@ -349,7 +349,7 @@ def Class(self) -> str: if 'CLASS' not in self._vevents[self.ref]: return '' return self._vevents[self.ref]['CLASS'] - + def update_Class(self, Class: str) -> None: if Class: self._vevents[self.ref]['CLASS'] = Class diff --git a/khal/ui/editor.py b/khal/ui/editor.py index 12cf435f0..2e29697d7 100644 --- a/khal/ui/editor.py +++ b/khal/ui/editor.py @@ -341,7 +341,7 @@ def __init__(self, pane, event, save_callback=None, always_save=False): self.attendees = event.attendees self.categories = event.categories self.url = event.url - + self.Class = event.Class self.startendeditor = StartEndEditor( @@ -451,7 +451,7 @@ def changed(self): if get_wrapped_text(self.Class) != self.event.Class: return True - + if get_wrapped_text(self.attendees) != self.event.attendees: return True if self.startendeditor.changed or self.calendar_chooser.changed: