def edit(self, id=None): m=Model() try: print(" .. GET Edit Data (ID): " + id) res = m.find_by_id(id) self.success(message="employees, edit id: " + str(id), data=res) except Exception as e: self.error(message="employees, edit id: " + str(id) + "msg: " + str(e) , data=None)
def create(self): try: data_json = self.request.body m=Model() m.init_from_json(data_json, simple_conversion=True) m.upsert() self.success(message="employees, successfully created " + str(m.id), data=m, format="json") except Exception as e: self.error(message="employees, error updating " + str(m.id) + "msg: " + str(e), data=m, format="json")
def destroy(self, id=None): try: data_json = self.request.body print(" .. DELETE Data: ID:" + str(data_json)) m=Model() m.init_from_json(data_json) res = m.find_by_id(m.id) res.delete() self.success(message="employees, destroy id: " + str(m.id)) except Exception as e: self.error(message="employees, destroy id: " + str(e))
def update(self, id=None): data_json = self.request.body m=Model() res = m.find_by_id(id) res.init_from_json(data_json, simple_conversion=True) try: #res.tags= res.tags.split(",") res.upsert() self.success(message="employees, successfully updated " + str(res.id), data=res, format="json") except Exception as e: self.error(message="employees, error updating: " + str(m.id) + "msg: " + str(e), data=data_json, format="json")
def page(self, page=0): m=Model() res=m.page(page=int(page), page_size=myapp["page_size"]) self.success(message="employees page: #" +str(page), data=res )
def list(self): m=Model() res = m.get_all() self.success(message="employees, index", data=res)
def show(self, id=None): m=Model() res=m.find_by_id(id) self.success(message="employees show", data=res)