def post_delete(self, record): print("DELETE Id: {} ".format(record)) query = DBSession.query(Pets).filter_by(id=int(record)).first() if query is not None: DBSession.delete(query) DBSession.flush() return dict(id=record)
def updateGrid(self): if "oper" in self.kw: if self.kw['oper'] == "edit": print("edit") # print("id:{}".format(self.kw['id'])) # for key, value in self.kw.iteritems(): # print "%s = %s" % (key, value) my_filters = {self.indexkey: self.kw['id']} query = DBSession.query(self.model) for attr, value in my_filters.items(): query = query.filter(getattr(self.model, attr) == value) item = query.first() if item is not None: #print("None Edit") for column in item.__table__.columns: if column.name != self.indexkey: if column.name in self.kw: if str(column.type) == "BOOLEAN": newvalue = True if self.kw[ column.name] == "True" else False else: newvalue = self.kw[column.name] #print("updating: {} to {} type:{}".format(column.name, self.kw[column.name],str(column.type))) setattr(item, column.name, newvalue) DBSession.flush() if self.kw['oper'] == "add": item = self.model() #print("add") for column in item.__table__.columns: if column.name in self.kw: #print("{}={}".format(str(column.name),str(self.kw[column.name]))) if (self.indexkey == column.name): pass else: setattr(item, column.name, self.kw[column.name]) DBSession.add(item) DBSession.flush() if self.kw['oper'] == "del": my_filters = {self.indexkey: self.kw['id']} query = DBSession.query(self.model) for attr, value in my_filters.items(): query = query.filter(getattr(self.model, attr) == value) item = query.first() if item is not None: DBSession.delete(item) DBSession.flush() return dict(error="")
def release_license(self, **kw): error = {"Error": "none"} print("Release License") if not ('imei' in kw and 'account' in kw): error = {"Error": "Parametros faltantes"} else: item = DBSession.query(Smartphones).filter_by( account=kw['account'], imei=kw['imei']).first() if item is not None: DBSession.delete(item) DBSession.flush() Message.post("Smartphonesfrom", 'RELOAD' + "|") print(error) return error