Commit 4380d872 authored by Jacek Sowiński's avatar Jacek Sowiński

AddCommand refactoring

1. Move _preprocess_input_todo adn _postprocess_input_todo inside
_add_todo.
2. Remove self.todo
parent 9adafb91
......@@ -36,7 +36,6 @@ class AddCommand(Command):
super(AddCommand, self).__init__(
p_args, p_todolist, p_out, p_err, p_prompt)
self.text = ' '.join(p_args)
self.todo = None
self.from_file = None
def _process_flags(self):
......@@ -48,7 +47,19 @@ class AddCommand(Command):
self.args = args
def _preprocess_input_todo(self, p_todo_text):
def get_todos_from_file(self):
if self.from_file == '-':
f = stdin
else:
f = codecs.open(self.from_file, 'r', encoding='utf-8')
todos = f.read().splitlines()
return todos
def _add_todo(self, p_todo_text):
def _preprocess_input_todo(p_todo_text):
"""
Preprocesses user input when adding a task.
......@@ -58,7 +69,7 @@ class AddCommand(Command):
return todo_text
def _postprocess_input_todo(self):
def _postprocess_input_todo(p_todo):
"""
Post-processes a parsed todo when adding it to the list.
......@@ -68,26 +79,26 @@ class AddCommand(Command):
after: tags
"""
def convert_date(p_tag):
value = self.todo.tag_value(p_tag)
value = p_todo.tag_value(p_tag)
if value:
dateobj = relative_date_to_date(value)
if dateobj:
self.todo.set_tag(p_tag, dateobj.isoformat())
p_todo.set_tag(p_tag, dateobj.isoformat())
def add_dependencies(p_tag):
for value in self.todo.tag_values(p_tag):
for value in p_todo.tag_values(p_tag):
try:
dep = self.todolist.todo(value)
if p_tag == 'after':
self.todolist.add_dependency(self.todo, dep)
self.todolist.add_dependency(p_todo, dep)
elif p_tag == 'before' or p_tag == 'partof':
self.todolist.add_dependency(dep, self.todo)
self.todolist.add_dependency(dep, p_todo)
except InvalidTodoException:
pass
self.todo.remove_tag(p_tag, value)
p_todo.remove_tag(p_tag, value)
convert_date(config().tag_start())
convert_date(config().tag_due())
......@@ -96,24 +107,13 @@ class AddCommand(Command):
add_dependencies('before')
add_dependencies('after')
self.todo.set_creation_date(date.today())
p_todo.set_creation_date(date.today())
def get_todos_from_file(self):
if self.from_file == '-':
f = stdin
else:
f = codecs.open(self.from_file, 'r', encoding='utf-8')
todos = f.read().splitlines()
return todos
def _add_todo(self, p_todo_text):
todo_text = self._preprocess_input_todo(p_todo_text)
self.todo = self.todolist.add(todo_text)
self._postprocess_input_todo()
todo_text = _preprocess_input_todo(p_todo_text)
todo = self.todolist.add(todo_text)
_postprocess_input_todo(todo)
self.out(self.printer.print_todo(self.todo))
self.out(self.printer.print_todo(todo))
def execute(self):
""" 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