def get_query(self): ''' Returns query with all the objects :return: ''' if len(self.sidxArray) == 1: if not self.query: if self.sord == "asc": self.query = DBSession.query(self.model_class).order_by( asc(self.sidx)) else: self.query = DBSession.query(self.model_class).order_by( desc(self.sidx)) else: if not self.query: if self.sord == "asc": self.query = DBSession.query(self.model_class).order_by( asc(self.sidxArray[0])).order_by(asc( self.sidxArray[1])) else: self.query = DBSession.query(self.model_class).order_by( desc(self.sidxArray[0])).order_by( asc(self.sidxArray[1])) #self.query = self.session.query(self.model_class) return self.query
def delete(cls,user_id): handler = DBSession.query(cls).filter_by(user_id=user_id).first() if handler == None: return "Username doesn't exist" if handler != None: DBSession.delete(handler) DBSession.flush() return "ok"
def update(cls,user_id,user_name,email_address,display_name,password): handler = DBSession.query(cls).filter_by(user_id=user_id).first() if handler == None: return "Username doesn't exist" handler.user_name = user_name handler.email_address = email_address handler.display_name = display_name if password != "": handler.password = password print("FLUSHABLE") DBSession.flush() return "ok"
def open(self, **kw): kw['id'] = "dataBase" if kw['user_id'] == "0": kw['user'] = User() else: kw['user'] = DBSession.query(User).filter_by( user_id=kw['user_id']).first() dialogtemplate = render_template(kw, "mako", 'jqgrid.templates.jqgrid.user_form') return dict(dialogtemplate=dialogtemplate)
def loadGrid(self, **kw): rows = [] users = DBSession.query(User).all() for user in users: rows.append({ 'user_id': user.user_id, 'user_name': user.user_name, 'email_address': user.email_address, 'display_name': user.display_name, 'created': user.created }) return dict(rows=rows)
def add(cls,user_name,email_address,display_name,password): try: handler = cls() handler.user_name = user_name handler.email_address = email_address handler.display_name = display_name handler.password = password DBSession.add(handler) DBSession.flush() return "ok" except exc.SQLAlchemyError: DBSession.rollback() handler = DBSession.query(cls).filter_by(user_name = user_name).all() if str(handler) != "[]": return "Username already used" handler = DBSession.query(cls).filter_by(email_address=email_address).all() if str(handler) != "[]": return "Email already used" return "not ok"
def setUp(self): """Setup test fixture for each model test method.""" try: new_attrs = {} new_attrs.update(self.attrs) new_attrs.update(self.do_get_dependencies()) self.obj = self.klass(**new_attrs) DBSession.add(self.obj) DBSession.flush() return self.obj except: DBSession.rollback() raise
def by_user_name(cls, username): """Return the loadingData object whose loadingData name is ``username``.""" return DBSession.query(cls).filter_by(user_name=username).first()
def by_email_address(cls, email): """Return the loadingData object whose email address is ``email``.""" return DBSession.query(cls).filter_by(email_address=email).first()
def updateGrid(self): if self.kw['oper'] == "edit": 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: 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] setattr(item, column.name, newvalue) DBSession.flush() if self.kw['oper'] == "add": item = self.model() for column in item.__table__.columns: if column.name in self.kw: 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 test_query_obj(self): """Model objects can be queried""" obj = DBSession.query(self.klass).one() for key, value in self.attrs.items(): eq_(getattr(obj, key), value)
def tearDown(self): """Tear down test fixture for each model test method.""" DBSession.rollback()