How to use the khal.khalendar.event.Event function in khal

To help you get started, we’ve selected a few khal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pimutils / khal / khal / ui / __init__.py View on Github external
self.pane.calendar.original_widget.set_focus_date(new_start)
            self.pane.eventscolumn.original_widget.set_focus_date(new_start)

        if self.editor:
            self.pane.window.backtrack()

        assert not self.editor
        if external_edit:
            self.pane.window.loop.screen.stop()
            text = click.edit(event.raw)
            self.pane.window.loop.screen.start()
            if text is None:
                return
            # KeyErrors can occurr here when we destroy DTSTART,
            # otherwise, even broken .ics files seem to be no problem
            new_event = Event.fromString(
                text,
                locale=self._conf['locale'],
                href=event.href,
                calendar=event.calendar,
                etag=event.etag,
            )
            self.pane.collection.update(new_event)
            update_colors(
                new_event.start_local,
                new_event.end_local,
                (event.recurring or new_event.recurring)
            )
        else:
            self.editor = True
            editor = EventEditor(self.pane, event, update_colors, always_save=always_save)
github pimutils / khal / khal / ui / __init__.py View on Github external
self.pane.calendar.original_widget.set_focus_date(new_start)
            self.pane.eventscolumn.original_widget.set_focus_date(new_start)

        if self.editor:
            self.pane.window.backtrack()

        assert not self.editor
        if external_edit:
            self.pane.window.loop.screen.stop()
            text = click.edit(event.raw)
            self.pane.window.loop.screen.start()
            if text is None:
                return
            # KeyErrors can occurr here when we destroy DTSTART,
            # otherwise, even broken .ics files seem to be no problem
            new_event = Event.fromString(
                text,
                locale=self._conf['locale'],
                href=event.href,
                calendar=event.calendar,
                etag=event.etag,
            )
            self.pane.collection.update(new_event)
            update_colors(
                new_event.start_local,
                new_event.end_local,
                (event.recurring or new_event.recurring)
            )
        else:
            self.editor = True
            editor = EventEditor(self.pane, event, update_colors, always_save=always_save)
github pimutils / khal / khal / controllers.py View on Github external
def new_from_args(collection, calendar_name, conf, dtstart=None, dtend=None,
                  summary=None, description=None, allday=None, location=None,
                  categories=None, repeat=None, until=None, alarms=None,
                  timezone=None, format=None, env=None):
    """Create a new event from arguments and add to vdirs"""
    if isinstance(categories, str):
        categories = list([category.strip() for category in categories.split(',')])
    try:
        event = new_vevent(
            locale=conf['locale'], location=location, categories=categories,
            repeat=repeat, until=until, alarms=alarms, dtstart=dtstart,
            dtend=dtend, summary=summary, description=description, timezone=timezone,
        )
    except ValueError as error:
        raise FatalError(error)
    event = Event.fromVEvents(
        [event], calendar=calendar_name, locale=conf['locale'])

    try:
        collection.new(event)
    except ReadOnlyCalendarError:
        raise FatalError(
            'ERROR: Cannot modify calendar "{}" as it is read-only'.format(calendar_name)
        )

    if conf['default']['print_new'] == 'event':
        if format is None:
            format = conf['view']['event_format']
        echo(event.format(format, dt.datetime.now(), env=env))
    elif conf['default']['print_new'] == 'path':
        path = os.path.join(
            collection._calendars[event.calendar]['path'],
github pimutils / khal / khal / khalendar / khalendar.py View on Github external
def _construct_event(self,
                         item: str,
                         href: str,
                         start: dt.datetime = None,
                         end: dt.datetime = None,
                         ref: str='PROTO',
                         etag: str=None,
                         calendar: str=None,
                         ) -> Event:
        event = Event.fromString(
            item,
            locale=self._locale,
            href=href,
            calendar=calendar,
            etag=etag,
            start=start,
            end=end,
            ref=ref,
            color=self._calendars[calendar]['color'],
            readonly=self._calendars[calendar]['readonly'],
        )
        return event
github pimutils / khal / khal / khalendar / khalendar.py View on Github external
def new_event(self, ical: str, collection: str):
        """creates and returns (but does not insert) new event from ical
        string"""
        calendar = collection or self.writable_names[0]
        return Event.fromString(ical, locale=self._locale, calendar=calendar)
github pimutils / khal / khal / khalendar / backend.py View on Github external
def get_vevent_from_db(self, href, account, start=None, end=None,
                           readonly=False, color=lambda x: x,
                           unicode_symbols=True):
        """returns the Event matching href, if start and end are given, a
        specific Event from a Recursion set is returned, the Event as saved in
        the db

        All other parameters given to this function are handed over to the
        Event.
        """
        self._check_account(account)
        sql_s = 'SELECT vevent, etag FROM {0} WHERE href=(?)'.format(
            account + '_m')
        result = self.sql_ex(sql_s, (href, ))
        return Event(result[0][0],
                     local_tz=self.local_tz,
                     default_tz=self.default_tz,
                     start=start,
                     end=end,
                     color=color,
                     uid=href,
                     account=account,
                     readonly=readonly,
                     etag=result[0][1],
                     unicode_symbols=unicode_symbols)
github pimutils / khal / khal / khalendar / event.py View on Github external
class FloatingEvent(DatetimeEvent):
    """
    """
    allday = False

    @property
    def start_local(self):
        return self._locale['local_timezone'].localize(self.start)

    @property
    def end_local(self):
        return self._locale['local_timezone'].localize(self.end)


class AllDayEvent(Event):
    allday = True

    @property
    def end(self):
        end = super(AllDayEvent, self).end
        if end == self.start:
            # https://github.com/pimutils/khal/issues/129
            logger.warning('{} ("{}"): The event\'s end date property '
                           'contains the same value as the start date, '
                           'which is invalid as per RFC 5545. Khal will '
                           'assume this is meant to be single-day event '
                           'on {}'.format(self.href, self.summary, self.start))
            end += dt.timedelta(days=1)
        return end - dt.timedelta(days=1)

    @property
github pimutils / khal / khal / khalendar / event.py View on Github external
if key == 'PROTO':
                continue
            try:
                if self._vevents[key].get('RECURRENCE-ID').dt == instance:
                    to_pop.append(key)
            except TypeError:  # localized/floating datetime mismatch
                continue
        for key in to_pop:
            self._vevents.pop(key)

    @property
    def status(self):
        return self._vevents[self.ref].get('STATUS', '')


class DatetimeEvent(Event):
    pass


class LocalizedEvent(DatetimeEvent):
    """
    see parent
    """
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        try:
            starttz = getattr(self._vevents[self.ref]['DTSTART'].dt, 'tzinfo', None)
        except KeyError:
            msg = (
                "Cannot understand event {} from "
                "calendar {}, you might want to file an issue at "
                "https://github.com/pimutils/khal/issues"