コード例 #1
0
ファイル: Programa.py プロジェクト: Bgeninatti/ConFin
class ProgramaHandler(BaseHandler):

    def initialize(self):
        self._model = Programa(self.application.db)

    def get(self, id=None):
        data = self._get_data(inspect.currentframe())
        try:
            query = self._model.get(data)
            self.write(escape.json_encode(query))
            self.set_header("Content-Type", "application/json")
        except ValueError:
            self.send_error(400)

    def post(self, id=None):
        data = self._post_put_data(self._json_args)
        try:
            query = self._model.save(data)
            self.write(escape.json_encode(query))
            self.set_header("Content-Type", "application/json")
        except ValueError:
            self.send_error(400)

    def put(self, id):
        if id == str(self._json_args['id']):
            try:
                data = self._post_put_data(self._json_args)
                query = self._model.update(data)
                self.write(escape.json_encode(query))
                self.set_header("Content-Type", "application/json")
            except ValueError:
                self.send_error(400)
        else:
            self.send_error(400)

    def delete(self, id):
        try:
            data = self._get_data(inspect.currentframe())
            self._model.fake_delete(data)
        except ValueError:
            self.send_error(400)
コード例 #2
0
ファイル: EstadoActual.py プロジェクト: Bgeninatti/ConFin
class EstadoActualHandler(RequestHandler):

    def initialize(self):
        self.hist = HistorialPrograma(self.application.db)
        self.progs = Programa(self.application.db)

    def get(self):
        last_hist = self.hist.getmax()
        if last_hist is not None:
            prog = self.progs.get({'id': str(last_hist['programa_id'])})
            data = {
                'titulo': prog['titulo'],
                'desde': last_hist['created'],
            }
        else:
            data = {
                'titulo': False,
                'desde': False,
            }
        self.write(escape.json_encode(data))
        self.set_header("Content-Type", "application/json")
コード例 #3
0
ファイル: Programa.py プロジェクト: Bgeninatti/ConFin
 def initialize(self):
     self._model = Programa(self.application.db)
コード例 #4
0
ファイル: EstadoActual.py プロジェクト: Bgeninatti/ConFin
 def initialize(self):
     self.hist = HistorialPrograma(self.application.db)
     self.progs = Programa(self.application.db)