def tab_get(*args): """ Get tabs for applications List Arguments @param args[0]: calling tab (int, string, sqa object) @param args[1]: search mode (load, session) @param args[2:]: search parameters Descriptions @note: search mode -load : load data matching search parameters, remove inapplicable tabs @note: search mode - session: load data in sessions, keep all tabs """ tabParent, mode, params = tab_parse_args(*args) appParent = tabParent.app appThis = cherrypy.request.db.query(ModelCore.AppsCatalog).filter(ModelCore.AppsCatalog.name=='Diagram').first() if mode == 'load': user = cherrypy.session['user'] if len(params) == 0: equation = getattr(cherrypy.session.get('equation', None), 'instance', None) else: equation = params[0] if isinstance(equation, int): equation = MathHertz.Equation(user, equation) elif isinstance(equation, ModelCloudMath.EquationStorage): equation = MathHertz.Equation(user, equation.id) elif isinstance(equation, MathHertz.Equation): equation = equation else: SyntaxError('Unable to find equation %s'%equation) cherrypy.session['equation'] = equation elif mode == 'session': equation = cherrypy.session.get('equation', None) tabRegs = dict() idx = 0 if equation != None: circuit = cherrypy.request.db.query(ModelDiagram.DiagramCircuit).filter(ModelDiagram.DiagramCircuit.equation_id == equation.instance.id).first() if mode == 'session' and circuit == None: if user_check('Permission', 'AppExecute'): tab = appThis.tabs[0] regId = tab_get_reg_id('highest') + 1 tabRegs[tab.id] = {'regId': regId, 'tabId':tab.id, 'tabName':tab.name, 'appId' : appThis.id, 'appName' : appThis.name} elif circuit != None: cherrypy.session['circuit'] = circuit #load other app tabs only when there data available for tab in appThis.tabs: if user_check('Permission', 'AppExecute'): tabRegs[tab.id] = {'regId': idx, 'tabId':tab.id, 'tabName':tab.name, 'appId' : tab.app.id, 'appName' : tab.app.name} #check tabs in other apps if tabParent.name == 'Circuit': tabExts = tab_get_core(tabParent, 'load', equation.id) for tabIdExt, tabExt in tabExts.items(): tabExt['regId'] += idx tabRegs = dict(tabRegs.items() + tabExts.items()) return tabRegs
def session_new(*args): cherrypy.log.error('New Session', 'DIAGRAM', logging.DEBUG) actions = list() tab, mode, params = tab_parse_args(*args) if len(params) > 1: if isinstance(params[1], int): equationId = params[1] else: equationId = None if user_check('Permission', 'AppExecute'): if equationId != None: dbCircuit = cherrypy.request.db.query(ModelDiagram.DiagramCircuit).filter(ModelDiagram.DiagramCircuit.equation_id == equationId).first() cherrypy.session['circuit'] = dbCircuit respDict = session_resume() actions+=respDict['actions'] else: dbEquation = cherrypy.session['equation'] dbCircuit = ModelDiagram.DiagramCircuit('', dbEquation.instance) cherrypy.session['circuit'] = dbCircuit return {'actions':actions}
def session_new(*args): print 'Mechanical.session_new, args = %s' % str(args) actions = list() tab, mode, params = tab_parse_args(*args) if len(params) > 1: if isinstance(params[1], int): equationId = params[1] else: equationId = None if user_check('Permission', 'AppExecute'): if equationId: mechDesign = cherrypy.request.db.query( ModelMechanical.MechanicalDesign).filter( ModelMechanical.MechanicalDesign.equation_id == equationId).first() cherrypy.session['mechDesign'] = mechDesign respDict = session_resume() actions += respDict['actions'] else: print 'Mechanical.new_session, creating new sessions equation' return {'actions': actions}
def tab_get(*args): """ Get tabs for applications List Arguments @param args[0]: calling tab (int, string, sqa object) @param args[1]: search mode (load, session) @param args[2:]: search parameters Descriptions @note: search mode -load : load data matching search parameters, remove inapplicable tabs @note: search mode - session: load data in sessions, keep all tabs """ print 'Mechanical.tab_get tab_get, args = %s' % str(args) tabParent, mode, params = tab_parse_args(*args) appParent = tabParent.app appThis = cherrypy.request.db.query(ModelCore.AppsCatalog).filter( ModelCore.AppsCatalog.name == 'Mechanical').first() if mode == 'load': user = cherrypy.session['user'] if len(params) == 0: equation = getattr(cherrypy.session.get('equation', None), 'instance', None) else: equation = params[0] if isinstance(equation, int): equation = MathHertz.Equation(user, equation) elif isinstance(equation, ModelCloudMath.EquationStorage): equation = MathHertz.Equation(user, equation.id) elif isinstance(equation, MathHertz.Equation): equation = equation else: SyntaxError('Unable to find equation %s' % equation) cherrypy.session['equation'] = equation elif mode == 'session': equation = cherrypy.session.get('equation', None) tabRegs = dict() idx = 0 if equation != None: mechDesign = cherrypy.request.db.query( ModelMechanical.MechanicalDesign).filter( ModelMechanical.MechanicalDesign.equationStorageId == equation.instance.id).first() if mode == 'session' and mechDesign == None: if user_check('Permission', 'AppExecute'): tab = appThis.tabs[0] regId = tab_get_reg_id('highest') + 1 tabRegs[tab.id] = { 'regId': regId, 'tabId': tab.id, 'tabName': tab.name, 'appId': appThis.id, 'appName': appThis.name } elif mechDesign != None: cherrypy.session['mechDesign'] = mechDesign cherrypy.session['mechOptions'] = dict() for drawing in mechDesign.drawings: if drawing.initUnit == None: drawing.initUnit = 100000 #default to meters cherrypy.session['mechOptions'][drawing.id] = { 'checkOptions': [False, True], 'ratio': '1:1', 'size': 'none', 'unit': drawing.initUnit } #load other app tabs only when there data available for tab in appThis.tabs: if user_check('Permission', 'AppExecute'): tabRegs[tab.id] = { 'regId': idx, 'tabId': tab.id, 'tabName': tab.name, 'appId': tab.app.id, 'appName': tab.app.name } #check tabs in other apps if tabParent.name == 'Mechanical': tabExts = tab_get_core(tabParent, 'load', equation.id) for tabIdExt, tabExt in tabExts.items(): tabExt['regId'] += idx tabRegs = dict(tabRegs.items() + tabExts.items()) return tabRegs