Commit 788029c5 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Fixes for setting priority and completion.

When setting a priority, a task may not be completed.
When a todo is completed, set priority to None.
parent 894c8c79
......@@ -107,7 +107,9 @@ class TodoBase(object):
Priority remains unchanged when an invalid priority is given.
"""
if p_priority == None or re.match('^[A-Z]$', p_priority):
if not self.is_completed() and \
(p_priority == None or re.match('^[A-Z]$', p_priority)):
self.fields['priority'] = p_priority
priority_str = '' if p_priority == None else '(' + p_priority + ') '
......@@ -152,7 +154,9 @@ class TodoBase(object):
Marks the todo as complete.
Sets the completed flag and sets the completion date to today.
"""
if not self.fields['completed']:
if not self.is_completed():
self.set_priority(None)
self.fields['completed'] = True
today = datetime.date.today()
self.fields['completionDate'] = today
......
......@@ -109,6 +109,14 @@ class TodoBaseTester(unittest.TestCase):
self.assertEquals(todo.priority(), None)
self.assertTrue(re.match(r'^Foo$', todo.src))
def test_set_priority6(self):
""" Do not set priorities on completed tasks. """
todo = TodoBase.TodoBase("x 2014-06-13 Foo")
todo.set_priority('A')
self.assertFalse(todo.priority())
self.assertEquals(todo.src, "x 2014-06-13 Foo")
def test_project1(self):
todo = TodoBase.TodoBase("(C) Foo +Bar +Baz")
......@@ -152,6 +160,7 @@ class TodoBaseTester(unittest.TestCase):
today = datetime.date.today()
today_str = today.isoformat()
self.assertFalse(todo.priority())
self.assertEquals(todo.fields['completionDate'], today)
self.assertTrue(re.match('^x ' + today_str + ' Foo', todo.src))
......
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