def __init__(self, title, body='', tags=[], priority='low', state='pending', due_on='1 week', created_on=time.time()): self.title = title self.body = body self.tags = tags self.priority = priority self.state = state if type(due_on) == str: due_on = human_to_timestamp(due_on) self.due_on = due_on self.created_on = created_on
def search(self, **kwargs): attrib='title' needle = kwargs['needle'] if ':' in needle: attrib, needle = needle.split(':', 1) if attrib == 'due_on': # extract operator and value m = re.match("(<|<=|==|>|>=)\s*(.+)", needle) if m: operator = m.group(1) needle = m.group(2) else: operator = '==' needle = human_to_timestamp(needle) self._search_by_date(operator, needle, attrib) else: self._search_needle(needle, attrib)
def update(self, **kwargs): attrib='title' needle = kwargs['needle'] if ':' in needle: attrib, needle = needle.split(':') for note in self._do_search(needle, attrib): sys.stdout.write("%s\n" % (str(note))) if self._confirm("Edit?"): # title modified = self._rlinput("title> ", note.title) if modified != note.title: note.title = modified # body new_body = [] modified = self._rlinput("body> ", note.body) new_body.append(modified) while True: modified = self._rlinput("", "") if modified == '': break new_body.append(modified) modified = '\n'.join(new_body) if modified != note.body: note.body = modified # edit priority self._edit(note, 'priority', priority.VALID_PRIORITIES) # edit state self._edit(note, 'state', state.VALID_STATES) # edit due date cur_due_on = timestamp_to_human(note.due_on) modified = self._rlinput('due on> ', cur_due_on) modified = human_to_timestamp(modified) if modified != note.due_on: note.due_on = modified # edit existing tags new_tags = [] for t in note.tags: modified = self._rlinput("tag> ", t) if modified == '': continue new_tags.append(modified) # add new tags while True: t = self._rlinput("tag> ", "") if t == '': break new_tags.append(t) note.tags = new_tags if self._confirm("Save?"): self.backend.sync()