Exemplo n.º 1
0
    def execute(self, data):

        command = ' '.join(data)
        newitem, tags = extract_tags(command)

        tags = normalise_tags(tags)
        tagstr = tags_as_readable_string(tags)

        if not len(tags):
            return function.response(function.STATE_FAILURE, 'No tag specified')

        if newitem.strip() == '':
            return function.response(function.STATE_FAILURE, 'No item to add')

        l = lstobj(self.function, tags[0])
        itemid = l.add_new(newitem)

        for tag in tags[1:]:
            l.add_tag(itemid, tag)

        return function.redirect(
            self,
            ('list', 'view', tags),
            notification='Added "%s" with tags %s' % (newitem, tagstr),
            context='list item %s' % itemid
        )
Exemplo n.º 2
0
    def execute(self, data):
        timestamp = ' '.join(data[0:2])
        title = ' '.join(data[2:])

        if title.strip() == '':
            return function.response(function.STATE_FAILURE,
                                     'No title supplied')

        # Check timestamp is valid
        try:
            raw = datetime.datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S')
        except ValueError:
            to_fix = [[
                'reminder add %s %s' % (timestamp, title),
                'reminder add %%timestamp{{%s}} %%title{{%s}}' %
                (timestamp, title)
            ]]
            return function.response(
                function.STATE_FAILURE,
                'Invalid format for timestamp (%s)' % timestamp, to_fix)

        e = self.function.create(timestamp, title)

        return function.redirect(
            self, ('reminder', 'list'),
            notification='Added reminder event "%s" with timestamp "%s"' %
            (e.title, e.get_nice_time()))
Exemplo n.º 3
0
    def execute(self, data):
        habitid = data[0]
        date    = data[1]
        status  = data[2]

        current = self.function.state(date, habitid)

        if current == None:
            result = self.function.kernel.call('list', 'add', ['#!habits_%s' % date, '%s|%s' % (habitid, status)])
        else:
            result = self.function.kernel.call('list', 'update', ['#!habits_%s' % date, current['id'], '%s|%s' % (habitid, status)])

        if result.state != function.STATE_SUCCESS:
            note = "Failed to update habit! (%s)" % result.message
            return function.response(function.STATE_FAILURE, note)

        if date == self.function.date_today():
            redirect = ('habit', 'view')
            date = 'today'
        else:
            redirect = ('habit', 'view', [date])

        return function.redirect(
            self,
            redirect,
            notification='Updated habit entry for %s' % date,
            context='list item %s' % habitid
        )
Exemplo n.º 4
0
    def execute(self, data):
        itemid = data[0]
        timestamp = ' '.join(data[1:3])
        title = ' '.join(data[3:])

        if title.strip() == '':
            return function.response(function.STATE_FAILURE,
                                     'No title supplied')

        # Check timestamp is valid
        try:
            raw = datetime.datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S')
        except ValueError:
            to_fix = [[
                'reminder update %s %s %s' % (itemid, timestamp, title),
                'reminder update %s %%Timestamp{{%s}} %%Title{{%s}}' %
                (itemid, timestamp, title)
            ]]
            return function.response(
                function.STATE_FAILURE,
                'Invalid format for timestamp (%s)' % timestamp, to_fix)

        e = self.function.get(itemid)
        e.update({'timestamp': timestamp, 'title': title})

        return function.redirect(
            self, ('reminder', 'list'),
            notification='Updated reminder event "%s" with timestamp "%s"' %
            (e.title, e.get_nice_time()),
            context='reminder item %s' % e.id)
Exemplo n.º 5
0
    def execute(self, data):
        itemid = data[0]
        oldtag = normalise_tag(data[1])
        newtags = data[2:]
        newtags = normalise_tags(newtags)
        newtagstr = tags_as_readable_string(newtags)

        if oldtag.strip() == '':
            return function.response(function.STATE_FAILURE, 'No old tag specified')

        if len(newtags) == 0 or newtags[0].strip() == '':
            return function.response(function.STATE_FAILURE, 'No new tag specified')

        l = lstobj(self.function, oldtag)
        itemdata = l.get(itemid, oldtag)

        if not itemdata:
            return function.response(function.STATE_FAILURE, 'No item to move from tag "%s"' % oldtag)

        l.remove_tag(itemid, oldtag)

        for newtag in newtags:
            l.add_tag(itemid, newtag)

        return function.redirect(
            self,
            ('list', 'view', newtags),
            notification='Moved "%s" from "%s" to %s' % (itemdata['item'], oldtag, newtagstr),
            context='list item %s' % itemid
        )
Exemplo n.º 6
0
    def execute(self, data):
        lstkey = normalise_tag(data[0])
        itemid = data[1]

        l = lstobj(self.function, lstkey)
        itemdata = l.get(itemid, lstkey)

        data = []
        if not itemdata:
            data.append(['View list "%s"' % lstkey, "list view %s" % lstkey])
            resp = function.response(function.STATE_FAILURE, 'No item to delete in list "%s"' % lstkey)
            resp.data = data
            resp.write = 1
            return resp

        tags = l.get_tags(itemid)
        for t in tags:
            l.remove_tag(itemid, t['tag'])
            data.append(['View list "%s"' % t['tag'], "list view %s" % t['tag']])

        resp_text = 'Deleting "%s" from %s' % (itemdata['item'], tags_as_readable_string([tag['tag'] for tag in tags]))

        return function.redirect(
            self,
            ('list', 'view', [lstkey]),
            notification=resp_text
        )
Exemplo n.º 7
0
    def execute(self, data):
        itemid = data[0]
        oldtag = normalise_tag(data[1])
        newtag = normalise_tag(data[2])

        if oldtag.strip() == '':
            return function.response(function.STATE_FAILURE,
                                     'No old tag specified')

        if newtag.strip() == '':
            return function.response(function.STATE_FAILURE,
                                     'No new tag specified')

        l = lstobj(self.function, oldtag)
        itemdata = l.get(itemid, oldtag)

        if not itemdata:
            return function.response(function.STATE_FAILURE,
                                     'No item to move from tag "%s"' % oldtag)

        l.remove_tag(itemid, oldtag)
        l.add_tag(itemid, newtag)

        return function.redirect(
            self, ('list', 'view', [newtag]), 'Moved "%s" from "%s" to "%s"' %
            (itemdata['item'], oldtag, newtag))
Exemplo n.º 8
0
    def execute(self, data):
        habitid = data[0]
        date = data[1]
        status = data[2]

        current = self.function.state(date, habitid)

        if current == None:
            result = self.function.kernel.call(
                'list', 'add',
                ['#!habits_%s' % date,
                 '%s|%s' % (habitid, status)])
        else:
            result = self.function.kernel.call('list', 'update', [
                '#!habits_%s' % date, current['id'],
                '%s|%s' % (habitid, status)
            ])

        if result.state != function.STATE_SUCCESS:
            note = "Failed to update habit! (%s)" % result.message
            return function.response(function.STATE_FAILURE, note)

        if date == self.function.date_today():
            redirect = ('habit', 'view')
            date = 'today'
        else:
            redirect = ('habit', 'view', [date])

        return function.redirect(self,
                                 redirect,
                                 notification='Updated habit entry for %s' %
                                 date,
                                 context='list item %s' % habitid)
Exemplo n.º 9
0
    def execute(self, data):
        description = ' '.join(data)

        if description.strip() == '':
            return function.response(function.STATE_FAILURE,
                                     'No log entry specified')

        l = self.function.add(description)
        item_time = self.function.kernel.inClientTimezone(
            l.entrytime).strftime('%y/%m/%d %I:%M%P')

        return function.redirect(
            self, ('log', 'view'), 'Added log entry "%s" with timestamp "%s"' %
            (l.description, item_time))
Exemplo n.º 10
0
    def execute(self, data):
        contactid = data[0]

        c = self.function.get_model_instance(Contact, contactid)
        if not c:
            return function.response(
                function.STATE_FAILURE,
                'Contact with id "%s" cannot be found' % contactid)

        c.delete()

        return function.redirect(self, ('contact', 'list'),
                                 notification='Deleted contact "%s"' %
                                 (c.name))
Exemplo n.º 11
0
    def execute(self, data):

        name = ' '.join(data).strip()

        if name == '':
            return function.response(function.STATE_FAILURE,
                                     'No name supplied')

        c = Contact(self.function, {'name': name})
        c.create()

        return function.redirect(self, ('contact', 'list'),
                                 notification='Added contact "%s"' % c.name,
                                 context='contact view %s' % c.id)
Exemplo n.º 12
0
    def execute(self, data):
        if not len(data):
            return function.response(function.STATE_FAILURE, 'No log entry ID specified')

        id = int(data[0])
        l = self.function.remove(id)
        if not l:
            return function.response(function.STATE_FAILURE, 'Log ID %d not found' % id)

        return function.redirect(
            self,
            ('log', 'view'),
            notification='Deleted log entry "%s" with timestamp "%s" (ID: %d)' % (l.description, l.entrytime, l.id)
        )
Exemplo n.º 13
0
    def execute(self, data):
        description = ' '.join(data)

        if description.strip() == '':
            return function.response(function.STATE_FAILURE, 'No log entry specified')

        l = self.function.add(description)
        item_time = self.function.kernel.inClientTimezone(l.entrytime).strftime('%y/%m/%d %I:%M%P')

        return function.redirect(
            self,
            ('log', 'view'),
            notification='Added log entry "%s" with timestamp "%s"' % (l.description, item_time)
        )
Exemplo n.º 14
0
    def execute(self, data):
        if not len(data):
            return function.response(function.STATE_FAILURE,
                                     'No log entry ID specified')

        id = int(data[0])
        l = self.function.remove(id)
        if not l:
            return function.response(function.STATE_FAILURE,
                                     'Log ID %d not found' % id)

        return function.redirect(
            self, ('log', 'view'),
            'Deleted log entry "%s" with timestamp "%s" (ID: %d)' %
            (l.description, l.entrytime, l.id))
Exemplo n.º 15
0
    def execute(self, data):
        contactid = data[0]
        name = ' '.join(data[1:]).strip()

        c = self.function.get_model_instance(Contact, contactid)
        if not c:
            return function.response(
                function.STATE_FAILURE,
                'Contact with id "%s" cannot be found' % contactid)

        oldname = c.name
        c.name = name
        c.update()

        return function.redirect(self, ('contact', 'view', [contactid]),
                                 notification='Contact "%s" updated to "%s"' %
                                 (oldname, c.name))
Exemplo n.º 16
0
    def execute(self, data):
        timestamp = ' '.join(data[0:2])
        title = ' '.join(data[2:])

        if title.strip() == '':
            return function.response(function.STATE_FAILURE, 'No title supplied')

        # Check timestamp is valid
        try:
            raw = datetime.datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S')
        except ValueError:
            to_fix = [['reminder add %s %s' % (timestamp, title), 'reminder add %%timestamp{{%s}} %%title{{%s}}' % (timestamp, title)]]
            return function.response(function.STATE_FAILURE, 'Invalid format for timestamp (%s)' % timestamp, to_fix)

        e = self.function.create(timestamp, title)

        return function.redirect(
            self,
            ('reminder', 'list'),
            notification='Added reminder event "%s" with timestamp "%s"' % (e.title, e.get_nice_time())
        )
Exemplo n.º 17
0
    def execute(self, data):
        itemid  = data[0]
        tags    = data[1:]

        tags = normalise_tags(tags)
        tagsstr = tags_as_readable_string(tags)
        added = []

        for tag in tags:
            if tag.strip() == '':
                continue

            l = lstobj(self.function, tag)

            itemdata = l.get(itemid)
            data = []
            data.append(['View list "%s"' % tag, "list view %s" % tag])
            added.append(tag)

            if not itemdata:
                resp = function.response(function.STATE_FAILURE, 'No item to tag "%s"' % tag)
                resp.data = data
                resp.write = 1
                return resp

            l.add_tag(itemid, tag)

        if not added:
            return function.response(function.STATE_FAILURE, 'No tag specified')

        if len(added) > 1:
            message = 'Added tags %s to "%s"' % (tagstr, itemdata['item'])
        else:
            message = 'Added tag "%s" to "%s"' % (added[0], itemdata['item'])
        return function.redirect(
            self,
            ('list', 'view', [added[0]]),
            notification=message,
            context='list item %s' % itemid
        )
Exemplo n.º 18
0
    def execute(self, data):
        tag    = normalise_tag(data[0])
        itemid = data[1]
        item   = ' '.join(data[2:])

        if item.strip() == '':
            return function.response(function.STATE_FAILURE, 'No new item content')

        l = lstobj(self.function, tag)
        itemdata = l.get(itemid, tag)

        if not itemdata or item == itemdata['item']:

            if not itemdata:
                errstr = 'No item to update to "%s" in list "%s"' % (item, tag)
            else:
                errstr = 'No change made to "%s" so not updated' % (itemdata['item'])

            data = [['View list "%s"' % tag, "list view %s" % tag]]
            resp = function.response(function.STATE_FAILURE, errstr)
            resp.data = data
            resp.write = 1
            return resp

        updateditem, newtags = extract_tags(item)
        newtags = normalise_tags(newtags)

        l.update(itemdata, updateditem)

        if len(newtags):
            for newtag in newtags:
                l.add_tag(itemid, newtag)

        return function.redirect(
            self,
            ('list', 'view', [tag]),
            notification='Updated item "%s" to "%s"' % (itemid, item),
            context='list item %s' % itemid
        )
Exemplo n.º 19
0
    def execute(self, data):
        contactid = data[0]
        accountid = data[1]

        c = self.function.get_model_instance(Contact, contactid)
        if not c:
            return function.response(
                function.STATE_FAILURE,
                'Contact with id "%s" cannot be found' % contactid)

        a = self.function.get_model_instance(Account, accountid)
        if not a:
            return function.response(
                function.STATE_FAILURE,
                'Contact with id "%s" cannot be found' % contactid)

        a.delete()

        return function.redirect(
            self, ('contact', 'view', [contactid]),
            notification='Deleted "%s" account from contact "%s"' %
            (a.type, c.name))
Exemplo n.º 20
0
    def execute(self, data):
        contactid = data[0]
        acctype = data[1]
        uid = data[2]

        c = self.function.get_model_instance(Contact, contactid)
        if not c:
            return function.response(
                function.STATE_FAILURE,
                'Contact with id "%s" cannot be found' % contactid)

        a = Account(self.function, {
            'contact_id': contactid,
            'type': acctype,
            'uid': uid
        })
        a.create()

        return function.redirect(
            self, ('contact', 'view', [contactid]),
            notification='Added "%s" account to contact "%s"' %
            (acctype, c.name),
            context='contact account %s' % a.id)
Exemplo n.º 21
0
    def execute(self, data):

        command = ' '.join(data)
        newitem, tags = extract_tags(command)

        tags = [normalise_tag(t) for t in tags]

        if not len(tags):
            return function.response(function.STATE_FAILURE,
                                     'No tag specified')

        if newitem.strip() == '':
            return function.response(function.STATE_FAILURE, 'No item to add')

        l = lstobj(self.function, tags[0])
        itemid = l.add_new(newitem)

        for tag in tags[1:]:
            l.add_tag(itemid, tag)

        return function.redirect(
            self, ('list', 'view', tags),
            'Added "%s" with tags "%s"' % (newitem, '", "'.join(tags)))
Exemplo n.º 22
0
    def execute(self, data):
        itemid = data[0]
        tags = data[1:]

        tags = [normalise_tag(t) for t in tags]
        added = []

        for tag in tags:
            if tag.strip() == '':
                continue

            l = lstobj(self.function, tag)

            itemdata = l.get(itemid)
            data = []
            data.append(['View list "%s"' % tag, "list view %s" % tag])
            added.append(tag)

            if not itemdata:
                resp = function.response(function.STATE_FAILURE,
                                         'No item to tag "%s"' % tag)
                resp.data = data
                resp.write = 1
                return resp

            l.add_tag(itemid, tag)

        if not added:
            return function.response(function.STATE_FAILURE,
                                     'No tag specified')

        if len(added) > 1:
            alltags = '", "'.join(added)
            message = 'Added tags "%s" to "%s"' % (alltags, itemdata['item'])
        else:
            message = 'Added tag "%s" to "%s"' % (added[0], itemdata['item'])
        return function.redirect(self, ('list', 'view', [added[0]]), message)
Exemplo n.º 23
0
    def execute(self, data):
        lstkey = normalise_tag(data[0])
        itemid = data[1]

        l = lstobj(self.function, lstkey)
        itemdata = l.get(itemid, lstkey)

        data = []
        data.append(['View list "%s"' % lstkey, "list view %s" % lstkey])

        if not itemdata:
            resp = function.response(function.STATE_FAILURE, 'No item to remove in list "%s"' % lstkey)
            resp.data = data
            resp.write = 1
            return resp

        l.remove_tag(itemid, lstkey)

        tags = l.get_tags(itemid)
        for t in tags:
            data.append(['View list "%s"' % t['tag'], "list view %s" % t['tag']])

        resp_text = 'Removing "%s" from "%s"' % (itemdata['item'], lstkey)

        if len(tags):
            resp = function.response(function.STATE_SUCCESS, resp_text, lstkey)
            resp.data = data
            resp.write = 1
        else:
            resp = function.redirect(
                self,
                ('list', 'view', [lstkey]),
                notification=resp_text
            )

        return resp
Exemplo n.º 24
0
    def execute(self, data):
        itemid = data[0]
        timestamp = ' '.join(data[1:3])
        title = ' '.join(data[3:])

        if title.strip() == '':
            return function.response(function.STATE_FAILURE, 'No title supplied')

        # Check timestamp is valid
        try:
            raw = datetime.datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S')
        except ValueError:
            to_fix = [['reminder update %s %s %s' % (itemid, timestamp, title), 'reminder update %s %%Timestamp{{%s}} %%Title{{%s}}' % (itemid, timestamp, title)]]
            return function.response(function.STATE_FAILURE, 'Invalid format for timestamp (%s)' % timestamp, to_fix)

        e = self.function.get(itemid)
        e.update({'timestamp': timestamp, 'title': title})

        return function.redirect(
            self,
            ('reminder', 'list'),
            notification='Updated reminder event "%s" with timestamp "%s"' % (e.title, e.get_nice_time()),
            context='reminder item %s' % e.id
        )