Commit 78dd77a9 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Add views based on a todo list.

A view is a subset of the todo list where sorters and filters may be
applied.
parent 0079d622
......@@ -10,3 +10,5 @@ COMPLETED_FILENAME = 'done.txt'
TAG_START = 't'
TAG_DUE = 'due'
TAG_STAR = 'star'
SORT_STRING = 'desc:importance,due,desc:priority'
......@@ -5,6 +5,8 @@ import re
import sys
import Config
import Filter
import Sorter
import TodoFile
import TodoList
......@@ -73,9 +75,15 @@ class Application(object):
else:
error("Invalid priority given.")
def list(self):
print self.todolist
# TODO: sort + filter
def list(self, p_expression=None):
sorter = Sorter.Sorter(Config.SORT_STRING)
filters = [Filter.RelevanceFilter()]
if p_expression:
filters.append(Filter.GrepFilter(p_expression))
print self.todolist.view(sorter, filters)
def run(self):
""" Main entry function. """
......
......@@ -5,6 +5,7 @@ A list of todo items.
import re
import Todo
import View
class TodoList(object):
"""
......@@ -87,7 +88,7 @@ class TodoList(object):
return result
def view(self, p_sorter, p_filter):
def view(self, p_sorter, p_filters):
"""
Constructs a view of the todo list.
......@@ -95,8 +96,7 @@ class TodoList(object):
defined by the end user. Todos is this list should not be modified,
modifications should occur through this class.
"""
# TODO: perhaps change list such that values are immutable?
return p_filter.filter(p_sorter.sort(self._todos))
return View.View(p_sorter, p_filters, self._todos)
def __str__(self):
return '\n'.join([str(x) for x in self._todos])
......
class View:
def __init__(self, p_sorter, p_filters, p_todos):
self._todos = p_todos
self._viewdata = []
self._sorter = p_sorter
self._filters = p_filters
self.update()
def update(self):
"""
Updates the view data. Should be called when the backing todo list
has changed.
"""
self._viewdata = self._sorter.sort(self._todos)
for _filter in self._filters:
self._viewdata = _filter.filter(self._viewdata)
def __str__(self):
return '\n'.join([str(x) for x in self._viewdata])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment