Пример #1
0
 def test_translate_from_vtodo(self):
     DESCRIPTION = Translator.fields[1]
     self.assertEqual(DESCRIPTION.dav_name, 'description')
     todo = self._get_todo(VTODO_GRAND_CHILD)
     self.assertEqual(todo.instance.vtodo.serialize(), VTODO_GRAND_CHILD)
     self.assertEqual(date(2020, 12, 24),
                      todo.instance.vtodo.contents['due'][0].value)
     uid = UID_FIELD.get_dav(todo)
     self.assertTrue(isinstance(uid, str), f"should be str is {uid!r}")
     self.assertEqual(uid, UID_FIELD.get_dav(vtodo=todo.instance.vtodo))
     task = Task(uid, Mock())
     Translator.fill_task(todo, task, NAMESPACE)
     self.assertEqual('date', task.get_due_date().accuracy.value)
     vtodo = Translator.fill_vtodo(task, todo.parent.name, NAMESPACE)
     for field in Translator.fields:
         if field.dav_name in DAV_IGNORE:
             continue
         self.assertTrue(field.is_equal(task, NAMESPACE, todo))
         self.assertTrue(field.is_equal(task, NAMESPACE, vtodo=vtodo.vtodo))
     vtodo.vtodo.contents['description'][0].value = 'changed value'
     self.assertTrue(
         DESCRIPTION.is_equal(task, NAMESPACE, todo), 'same '
         'hashes should prevent changes on vTodo to be noticed')
     task.set_text(task.get_text() + 'more content')
     self.assertFalse(DESCRIPTION.is_equal(task, NAMESPACE, todo))
Пример #2
0
    def _extract_plain_text(self, task: Task) -> str:
        """Will extract plain text from task content, replacing subtask
        referenced in the text by their proper titles"""
        result, content = '', task.get_text()
        for line_no, line in enumerate(content.splitlines()):
            for tag in self.XML_TAGS:
                while tag in line:
                    line = line.replace(tag, '')

            if line_no == 0:  # is first line, striping all tags on first line
                new_line = self.__clean_first_line(line)
                if new_line:
                    result += new_line + '\n'
            elif line.startswith('{!') and line.endswith('!}'):
                subtask = task.req.get_task(line[2:-2].strip())
                if not subtask:
                    continue
                if subtask.get_status() == Task.STA_DONE:
                    result += f"[x] {subtask.get_title()}\n"
                else:
                    result += f"[ ] {subtask.get_title()}\n"
            else:
                result += line.strip() + '\n'
        return result.strip()
Пример #3
0
 def write_gtg(self, task: Task, value, namespace: str = None):
     hash_, text = value
     if hash_ and hash_ == self._get_content_hash(task.get_text()):
         logger.debug('not writing %r from vtodo, hash matches', task)
         return
     return super().write_gtg(task, text)