Commit 924c2d04 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Refactor _postprocess_input_todo.

parent 02247fef
...@@ -18,7 +18,7 @@ class AddCommand(Command.Command): ...@@ -18,7 +18,7 @@ class AddCommand(Command.Command):
""" """
self.text = re.sub(r'^(.+) (\([A-Z]\))(.*)$', r'\2 \1\3', self.text) self.text = re.sub(r'^(.+) (\([A-Z]\))(.*)$', r'\2 \1\3', self.text)
def _postprocess_input_todo(self): # TODO: split function def _postprocess_input_todo(self):
""" """
Post-processes a parsed todo when adding it to the list. Post-processes a parsed todo when adding it to the list.
...@@ -26,29 +26,35 @@ class AddCommand(Command.Command): ...@@ -26,29 +26,35 @@ class AddCommand(Command.Command):
* Automatically inserts a creation date if not present. * Automatically inserts a creation date if not present.
* Handles more user-friendly dependencies with before: and after: tags * Handles more user-friendly dependencies with before: and after: tags
""" """
for tag in [Config.TAG_START, Config.TAG_DUE]: def convert_date(p_tag):
value = self.todo.tag_value(tag) value = self.todo.tag_value(p_tag)
if value: if value:
dateobj = relative_date_to_date(value) dateobj = relative_date_to_date(value)
if dateobj: if dateobj:
self.todo.set_tag(tag, dateobj.isoformat()) self.todo.set_tag(p_tag, dateobj.isoformat())
self.todo.set_creation_date(date.today()) def add_dependencies(p_tag):
for raw_value in self.todo.tag_values(p_tag):
for tag in ['before', 'after']:
for raw_value in self.todo.tag_values(tag):
try: try:
value = int(raw_value) value = int(raw_value)
except ValueError: except ValueError:
continue continue
if tag == 'after': if p_tag == 'after':
self.todolist.add_dependency(self.todo.attributes['number'], value) self.todolist.add_dependency(self.todo.attributes['number'], value)
elif tag == 'before': elif p_tag == 'before':
self.todolist.add_dependency(value, self.todo.attributes['number']) self.todolist.add_dependency(value, self.todo.attributes['number'])
self.todo.remove_tag(tag, raw_value) self.todo.remove_tag(p_tag, raw_value)
convert_date(Config.TAG_START)
convert_date(Config.TAG_DUE)
add_dependencies('before')
add_dependencies('after')
self.todo.set_creation_date(date.today())
def execute(self): def execute(self):
""" Adds a todo item to the list. """ """ Adds a todo item to the list. """
......
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