def _get_todo_and_calendar(self, task: Task): """For a given task, try to get the todo out of the cache and figures out its calendar if one is linked to it""" todo, calendar = self._cache.get_todo(UID_FIELD.get_gtg(task)), None # lookup by task for __, calendar in self._cache.calendars: if CATEGORIES.has_calendar_tag(task, calendar): logger.debug('Found from task tag %r and %r', todo, calendar) return todo, calendar cname = task.get_attribute('calendar_name', namespace=self.namespace) curl = task.get_attribute("calendar_url", namespace=self.namespace) if curl or cname: calendar = self._cache.get_calendar(name=cname, url=curl) if calendar: logger.debug('Found from task attr %r and %r', todo, calendar) return todo, calendar if todo and getattr(todo, 'parent', None): logger.debug('Found from todo %r and %r', todo, todo.parent) return todo, todo.parent return None, None
def get_gtg(self, task: Task, namespace: str = None) -> str: return task.get_attribute(self.dav_name, namespace=namespace)