def verify_is_admin(self): try: user = sqlsession.query(User).filter_by(userid=self.userid,password=self.password).one() return sqlsession.query(UserRoleMapping).filter_by(userid=self.userid,roleid=Role.ADMIN.id).count()>0 except: print "No such user" return False
def __init__(self,name,password): self.password=password self.userid = name try: self.lastname=sqlsession.query(User).filter_by(userid=self.userid).one().lastname self.firstname=sqlsession.query(User).filter_by(userid=self.userid).one().firstname except: self.lastname=self.userid self.firstname=''
def __init__(self, user, name, parentname, displayname, type): daos = sqlsession.query(TileModel.DAO).filter_by(user=user, display=displayname, parent=parentname, name=name).all() if len(daos)>0: self.dao=daos[0] self.dao.type=type else: self.dao = TileModel.DAO(name=name, user=user, parentname=parentname, displayname=displayname, type=type) monitors=sqlsession.query(MonitorView.DAO).filter_by \ (display=displayname, parent=name).order_by(MonitorView.DAO.index).all() self.monitors=[] for mon in monitors: try: self.monitors.append(MonitorView(name=mon.name, user=user, parentname=self.get_name(), displayname=displayname)) except: del mon
def __init__(self, user, name, displayname): daos= sqlsession.query(TelemetryWindowModel.DAO).filter_by(user=user,display=displayname, name=name).all() if len(daos)>0: self.dao = daos[0] else: self.dao = TelemetryWindowModel.DAO(user=user,name=name, displayname=displayname) index=0
def __init__(self,id,name): self.id = id self.name = name try: if (sqlsession.query(Role).filter_by(id=self.id).count() == 0): sqlsession.add(self) except: sqlsession.add(self)
def get_properties(user, parent, display): daos= sqlsession.query(DisplayPropertyItem.DAO).filter_by( user=user, display=display.get_name(), parent=parent.get_name()).all() params={} for dao in daos: tag=dao.name if tag != "name": params[tag]=dao.value return DisplayProperties(name=parent, user=user, parent=parent, display=display, **params)
def __init__(self, user, name, format): daos = sqlsession.query(DisplayModel.DAO).filter_by(user=user, name=name).all() if len(daos) > 0: self.dao = daos[0] else: if format == None: self.dao = DisplayModel.DAO(name=name, format=Format.DEFAULT_FORMAT.get_name(), user=user) else: self.dao = DisplayModel.DAO(name=name, format=format, user=user)
def __init__(self, user, name, parentname, tilename, displayname): if not(isinstance(parentname,basestring)): raise Exception("Type Mismatch") daos=sqlsession.query(MonitorFilter.DAO).filter_by \ (user=user, display=displayname, parent=parentname, tile=tilename, name=name).all() if len(daos)>0: self.dao = daos[0] else: self.dao=MonitorFilter.DAO(name=name,user=user, displayname=displayname, tilename=tilename, parentname=parentname)
def __init__(self, user,role): self.userid=user.userid try: self.id=sqlsession.query(UserRoleMapping).filter_by(userid=user.userid, roleid=role.id).first().id except: self.roleid=role.id UserRoleMapping.id = UserRoleMapping.id+1 self.id = UserRoleMapping.id sqlsession.add(self)
def __init__(self, name, user, owner, displayname, value, type): self.name=name self.owner=owner daos= sqlsession.query(DisplayPropertyItem.DAO).filter_by(name=name, user=user, display=displayname, parent=owner.get_name()).all() if len(daos)>0: self.dao =daos[0] self.dao.type=type else: if (name=='col_span' or name=='row_span') and value==None: value=1 elif value==None: value=0 self.dao=DisplayPropertyItem.DAO(name=name, user=user, ownername=owner.get_name(), displayname=displayname, value=value, type=type)
def __init__(self,name): """ Load a format from the database given a name for the format """ if (name.startswith('<')): raise Exception("invalid type") self.name=name self.monitors=sqlsession.query(Monitor).filter_by(format=name).all() self.monitortable={} for monitor in self.monitors: self.monitortable[monitor.name]=monitor Format.everything[monitor.name]=monitor Format.formats[name]=self
def __init__(self, name, user, parentname, displayname,format=None): if not(isinstance(parentname,basestring)): raise Exception("Type Mismatch") daos=sqlsession.query(MonitorView.DAO).filter_by \ (user=user, display=displayname, parent=parentname, name=name).all() if len(daos)>0: self.dao = sqlsession.query(MonitorView.DAO).filter_by \ (user=user, display=displayname, parent=parentname, name=name).one() else: self.dao=MonitorView.DAO(name=name, user=user, displayname=displayname, parentname=parentname) self._monitor=Monitor(name,format) self.format=format filtermodels=sqlsession.query(MonitorFilter.DAO).filter_by \ (user=user, display=displayname, parent=name, tile=parentname).all() self.filtermodels=[] for filter in filtermodels: self.filtermodels.append(MonitorFilter(user=user, name=filter.name, parentname=filter.parent, tilename=filter.tile, displayname=filter.display)) self.filteredattrs=None if len(self.filtermodels)>0: self.filteredattrs=[] for attr in self.filtermodels: self.filteredattrs.append(attr.get_name())
def copy_to(self, newname): olddisplay = self oldname = self.dao.name if newname == oldname: return daos = sqlsession.query(DisplayModel.DAO).filter_by(user=self.dao.user, name=newname).all() if len(daos) > 0: raise Exception("Name already exists") sqlsession.commit() format = self.dao.format user = self.dao.user self.dao = None self.dao = DisplayModel(user=user, name=newname, format=format).dao sqlsession.add(self.dao) sqlsession.commit() if oldname == "unnamed": olddisplay.delete()
def get_models(display, user): daos= sqlsession.query(TelemetryWindowModel.DAO).filter_by(user=user, display=display.get_name()).all() models=[] for dao in daos: models.append(TelemetryWindowModel(user=user, name=dao.name, displayname=display.get_name())) return models
def verify(self): return sqlsession.query(User).filter_by(userid=self.userid,password=self.password).count()>0
def get_models(user, displayname, parentname): daos= sqlsession.query(TileModel.DAO).filter_by(user = user, display=displayname, parent=parentname).all() models=[] for dao in daos: models.append(TileModel(name=dao.name, user=user, displayname=displayname, parentname=parentname, type=dao.type)) return models
UserRoleMapping.table=sqlalchemy.Table('userroles',metadata, Column('id',Integer,primary_key=True), Column('userid',String(80), nullable=False), Column('roleid',Integer, nullable=False), useexisting=True) """map tables to database""" sqlalchemy.orm.mapper(User, User.table) sqlalchemy.orm.mapper(Role, Role.table) sqlalchemy.orm.mapper(UserRoleMapping, UserRoleMapping.table) """Setup user and user roles for basic admin""" import hashlib try: User.ROOT = sqlsession.query(User).filter_by(userid="admin").one() User.ROOT.password=hashlib.md5("admin").hexdigest() sqlsession.commit() except: User.ROOT= User("admin", hashlib.md5("admin").hexdigest()) sqlsession.add(User.ROOT) sqlsession.commit() Role.ADMIN = Role(1,"admin") Role.DEVELOPER = Role(2,"developer") Role.PRODCUT_MANAGER=Role(3,"product_manager") UserRoleMapping.ROOT = UserRoleMapping(User.ROOT,Role.ADMIN)
def __init__(self, project_name, contract_id, project_type): daos=sqlsession.query(Project.DAO).filter_by(project_name=project_name).all() if (len(daos)>0): self.dao=daos[0] else: self.dao=Project.DAO(project_name, contract_id, project_type=project_type)
def query_workbooks(): daos=sqlsession.query(Workbook.DAO).all() workbooks={} for dao in daos: workbooks[dao.project_name + "." + dao.workbook_name] = Workbook(dao.project_name, dao.workbook_name) return workbooks
def __init__(self, project_name, workbook_name): daos=sqlsession.query(Workbook.DAO).filter_by(project_name=project_name,workbook_name=workbook_name).all() if (len(daos)>0): self.dao=daos[0] else: self.dao=Workbook.DAO(project_name, workbook_name)
def query_projects(): daos=sqlsession.query(Project.DAO).all() projects={} for dao in daos: projects[dao.project_name] = Project(dao.project_name, dao.contract_id, dao.project_type) return projects