예제 #1
0
    def in_messages(self, req):
        #[TODO: should this be PUT?]
        if req.method == 'POST':
            view = self.load_view('ok.json')
            if view:
                ids = req.params.get('ids')
                if ids:
                    ids = ids.split(',')
                    db.mark_messages(req.environ['pysmsd.db.path'], req.environ['pysmsd.client.id'], ids)
                else:
                    return HTTPBadRequestJSON()

                return view.render()
            else:
                return None
        else:
            # GET
            view = self.load_view('messages.json')
            if view:
                include_marked = req.params.get('include_marked', False)
                v = {}
                v['messages'] = []
                messages = db.get_in_messages(req.environ['pysmsd.db.path'], keyword=req.GET.get('keyword'), include_marked=include_marked)
                for row in messages:
                    m = {}
                    for k in row.keys():
                        m[k] = row[k]

                    v['messages'].append(m)

                return view.render(**v)
            else:
                return None
예제 #2
0
    def in_message(self, req):
        #[TODO: should this be PUT?]
        if req.method == 'POST':
            view = self.load_view('ok.json')
            if view:
                db.mark_messages(req.environ['pysmsd.db.path'], req.environ['pysmsd.client.id'], req.urlvars['id'])
                return view.render()
            else:
                return None
        else:
            # GET
            view = self.load_view('message.json')
            if view:
                v = {}
                v['message'] = {}
                message = db.get_in_message(req.environ['pysmsd.db.path'], id=req.urlvars['id'])
                for k in message.keys():
                    v['message'][k] = message[k]

                return view.render(**v)
            else:
                return None