How to use the todoman.model.Todo function in todoman

To help you get started, we’ve selected a few todoman 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 / todoman / tests / test_cli.py View on Github external
def test_sorting_fields(tmpdir, runner, default_database):
    tasks = []
    for i in range(1, 10):
        days = datetime.timedelta(days=i)

        todo = Todo(new=True)
        todo.list = next(default_database.lists())
        todo.due = datetime.datetime.now() + days
        todo.created_at = datetime.datetime.now() - days
        todo.summary = 'harhar{}'.format(i)
        tasks.append(todo)

        default_database.save(todo)

    fields = (
        'id',
        'uid',
        'summary',
        'due',
        'priority',
        'created_at',
        'completed_at',
github pimutils / todoman / tests / test_backend.py View on Github external
def test_supported_fields_are_serializeable():
    supported_fields = set(Todo.ALL_SUPPORTED_FIELDS)
    serialized_fields = set(VtodoWritter.FIELD_MAP.keys())

    assert supported_fields == serialized_fields
github pimutils / todoman / tests / test_filtering.py View on Github external
def test_due_aware(tmpdir, runner, create, now_for_tz):
    db = Database([tmpdir.join('default')], tmpdir.join('cache.sqlite'))
    list_ = next(db.lists())

    for tz in ['CET', 'HST']:
        for i in [1, 23, 25, 48]:
            todo = Todo(new=True)
            todo.due = now_for_tz(tz) + timedelta(hours=i)
            todo.summary = '{}'.format(i)

            todo.list = list_
            db.save(todo)

    todos = list(db.todos(due=24))

    assert len(todos) == 4
    assert todos[0].summary == "23"
    assert todos[1].summary == "23"
    assert todos[2].summary == "1"
    assert todos[3].summary == "1"
github pimutils / todoman / todoman / model.py View on Github external
def serialize_field(self, name, value):
        if name in Todo.DATETIME_FIELDS:
            return self.normalize_datetime(value)
        if name in Todo.LIST_FIELDS:
            return ','.join(value)
        if name in Todo.INT_FIELDS:
            return int(value)
        if name in Todo.STRING_FIELDS:
            return value

        raise Exception('Unknown field {} serialized.'.format(name))
github pimutils / todoman / todoman / model.py View on Github external
def clone(self):
        """
        Returns a clone of this todo

        Returns a copy of this todo, which is almost identical, except that is
        has a different UUID and filename.
        """
        todo = Todo(new=True, list=self.list)

        fields = (
            Todo.STRING_FIELDS +
            Todo.INT_FIELDS +
            Todo.LIST_FIELDS +
            Todo.DATETIME_FIELDS
        )
        fields.remove('uid')

        for field in fields:
            setattr(todo, field, getattr(self, field))

        return todo
github pimutils / todoman / todoman / interactive.py View on Github external
def __init__(self, todo, database, labelmaker):
        '''
        Create a TodomanItem instance based on a todo and the associated
        Database that was provided.

        :param todoman.model.Todo todo: The todo this entry will represent.
        :param todoman.model.Database: The database from which persists tihs
            todo.
        :param func labelmake: A function that will create the string
            representation for this item.
        '''
        self.database = database
        if todo:
            self.todo = todo
        else:
            self.todo = Todo()  # A new todo is created
            self.filename = self.todo.filename
        # If the done status changes, save to database
        urwid.connect_signal(self, 'change', self.save)
        super().__init__(labelmaker(self), self.is_completed)
github pimutils / todoman / todoman / model.py View on Github external
def _todo_from_db(self, row):
        todo = Todo()
        todo.id = row['id']
        todo.uid = row['uid']
        todo.summary = row['summary']
        todo.due = self._dt_from_db(row['due'])
        todo.start = self._dt_from_db(row['start'])
        todo.priority = row['priority']
        todo.created_at = self._dt_from_db(row['created_at'])
        todo.completed_at = self._dt_from_db(row['completed_at'])
        todo.dtstamp = self._dt_from_db(row['dtstamp'])
        todo.percent_complete = row['percent_complete']
        todo.status = row['status']
        todo.description = row['description']
        todo.location = row['location']
        todo.list = self.lists_map[row['list_name']]
        todo.filename = os.path.basename(row['path'])
        return todo
github pimutils / todoman / todoman / main.py View on Github external
def get_task_sort_function(fields):
    if not fields:
        fields = [
            'is_completed',
            '-priority',
            'due',
            '-created_at',
        ]

    for field in fields:
        if not hasattr(model.Todo, field.lstrip('-')):
            raise click.UsageError('Unknown task field: {}'.format(field))

    def sort_func(args):
        """
        Auxiliary function used to sort todos.

        We put the most important items on the bottom of the list because the
        terminal scrolls with the output.

        Items with an immediate due date are considered more important that
        those for which we have more time.
        """
        db, todo = args
        rv = []
        for field in fields:
            field = field.lower()