Exemplo n.º 1
0
Arquivo: note.py Projeto: rgs1/notes
    def __str__(self, colors_on=True, show_date=True):
        if colors_on:
            title = colors.GREEN_STR % ('title:')
            tags = colors.RED_STR % ('tags:')
            created_on = colors.YELLOW_STR % ('created on:')
            state = colors.PURPLE_STR % ('state:')
            prio = colors.BLUE_STR % ('priority:')
            due_on = colors.CYAN_STR % ('due on:')
        else:
            title = 'title:'
            tags = 'tags:'
            created_on = 'created on:'
            state = 'state:'
            prio = 'priority:'
            due_on = 'due on:'

        s = ""
        if self.title and self.title != "":
            s += "%s: %s\n" % (title, self.title)

        if self.body and self.body != "":
            s += "%s\n" % (self.body)

        if self.tags and len(self.tags) > 0:
            s += "%s: %s\n" % (tags, self.tags_as_str())

        s += "%s: %s\n" % (state, self.state)

        s += "%s: %s\n" % (prio, self.priority)

        s += "%s: %s\n" % (due_on, timestamp_to_human(self.due_on))

        if show_date:
            s += "%s: %s\n" % (created_on, timestamp_to_human(self.created_on))

        return s
Exemplo n.º 2
0
    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()
Exemplo n.º 3
0
 def get_due_on_dates(self):
     tstamps = list(set(map(lambda n: n.due_on, self.backend.list())))
     tstamps.sort()
     return map(lambda tstamp: timestamp_to_human(tstamp), tstamps)