def flowSearch(): """ 查询工作流 :return: """ test_group = request.args.get('test_group') # 项目组名称 test_domain = request.args.get('test_domain') # 项目组名称 if test_group == 'None' and test_domain == 'None': # 当项目为空、接口名为空、状态为 全部 datas = Run_Suite.query.all() elif test_group != 'None' and test_domain == 'None': datas = Run_Suite.query.filter(Run_Suite.test_group==test_group).all() elif test_group != 'None' and test_domain != 'None': datas = Run_Suite.query.filter(Run_Suite.test_group == test_group ).filter( func.find_in_set(test_domain,Run_Suite.domain)).order_by( Run_Suite.RunOrderId).all() else: datas = Run_Suite.query.filter( func.find_in_set(test_domain,Run_Suite.domain) ).order_by(Run_Suite.RunOrderId).all() suiteList = [] for singleDatas in datas: suiteDatas = {"id":singleDatas.id, "RunOrderId":singleDatas.RunOrderId, "domain":singleDatas.domain, "name":singleDatas.suiteName, "desc":singleDatas.description, "statu": "启用" if singleDatas.statu else "停用", "test_group":singleDatas.test_group} suiteList.append(suiteDatas) resp = {"status": 200, "datas": suiteList} msg_resp = make_response(jsonify(resp)) return msg_resp
def get_group_sensor_map(group_ids: str): ok = False sensor_id_group_mapping = {} conn = None try: conn = engine.connect() _query = conn.execute( select([ TabSensorGroup.name, t_tab_sensor_group_relation.c.sensor_id ]).where( and_( func.find_in_set(t_tab_sensor_group_relation.c.group_id, group_ids), TabSensorGroup.id == t_tab_sensor_group_relation.c.group_id))).fetchall() for row in _query: sensor_id_group_mapping[row[1]] = row[0] ok = True except Exception as e: print(e) finally: if conn: conn.close() return ok, sensor_id_group_mapping
def create_filter(query, parameter, request, sql_object, sql_parent, rule, like, set, fk=None): if parameter in request: if len(request[parameter]) is not 0: split = request[parameter].split(';') if len(split) > 1: if set: if request[rule] == 'AND': for s in split: query = query.filter(func.find_in_set(s, getattr(sql_parent, sql_object))) else: query = query.filter( or_(*[func.find_in_set(s, getattr(sql_parent, sql_object)) for s in split])) elif request[rule] == "AND": for s in range(0, len(split)): if s == 0: if like: query = query.filter(getattr(sql_parent, sql_object).like(split[s])) else: query = query.filter(getattr(sql_parent, sql_object) == split[s]) else: a_alias = aliased(sql_parent) if fk is not None: query = query.join(a_alias, fk) if like: query = query.filter(getattr(a_alias, sql_object).like(split[s])) else: query = query.filter(getattr(a_alias, sql_object) == split[s]) # TODO: add second search to result (e.g. second Protein) else: query = query.filter(or_(*[(getattr(sql_parent, sql_object).like(split[s])) for s in split])) else: if set: query = query.filter(func.find_in_set(split[0], getattr(sql_parent, sql_object))) elif rule == ">" or rule == "<": if rule == ">": query = query.filter(getattr(sql_parent, sql_object) > split[0]) else: query = query.filter(getattr(sql_parent, sql_object) < split[0]) else: if like: query = query.filter(getattr(sql_parent, sql_object).like(split[0])) else: query = query.filter(getattr(sql_parent, sql_object) == split[0]) return query
def scheduleSuite(): """工作流调度接口,传入domain(业务域),env_num,env_flag""" domain = request.args.get("domain") env_num = request.args.get("env_num") env_flag = request.args.get("env_flag") developer = request.args.get("developer") cookies = """{"env_flag":"%s","env_num":"%s"}""" % (env_flag, env_num) t = time.strftime("%m%d%H%M", time.localtime(time.time())) redis.set("scheduleSuite_developer", "{'developer':'%s-%s'}" % (developer, t)) if domain: domainList = domain.strip().split(",") if len(domainList) == 1: suite = Run_Suite.query.filter( func.find_in_set( domainList[0], Run_Suite.domain)).filter(Run_Suite.statu == 1).order_by( Run_Suite.RunOrderId).order_by(Run_Suite.id) if suite.all() == []: msg = "业务域不存在" resp_msg = {"datas": msg, "code": "400", "total": "0"} return make_response(jsonify(resp_msg)) else: # sqlStr = """Run_Suite.query.filter(func.find_in_set("%s",Run_Suite.domain))""" sqlStr = """Run_Suite.query.filter(func.find_in_set("%s",Run_Suite.domain)).order_by(Run_Suite.RunOrderId).order_by(Run_Suite.id)""" conditionList = [] for i in range(1, len(domainList)): unionStr = """union(%s)""" % (sqlStr % (domainList[i])) conditionList.append(unionStr) suite = eval(sqlStr % (domainList[0]) + "." + ".".join(conditionList)).filter( Run_Suite.statu == 1) #+".all()") # print suite_all.statement.compile(compile_kwargs={"literal_binds": True}) # run_suite_api.apply_async( args=[suite.count(), suite.all(), cookies, domain, developer], countdown=int(1)) # run_suite_api(suite.count(),suite.all(),cookies,domain,developer) resp_msg = { "datas": "功能域接口调度成功", "code": "200", "total": suite.count() } else: msg = "未传入业务域" resp_msg = {"datas": msg, "code": "400", "total": "0"} return make_response(jsonify(resp_msg))
def get_id_of_users_without_ignore_hashtags(self, media=enumerates.Media. TELEGRAM, tags=None): if tags is None: tags = list() tags_strings = [i.name for i in tags] filter_expression = not_( or_(*[ func.find_in_set(s, self.users.ignored_tags) for s in tags_strings ])) users = self.session.query(self.users).filter(filter_expression).all() res = list() for i in users: res.append(i.__dict__.get(media.name.lower() + '_id')) return res
def filter_query(cls, mid=None): pid = request.args.get('project_id') title = request.args.get('title') priority = request.args.get('priority') ctype = request.args.get('ctype') user_ids = request.args.get('user_ids') start_time = request.args.get('start_time') end_time = request.args.get('end_time') module_data = request.args.get('module_data') ret = cls._query() if module_data: module_data = module_data.split(',') ret = ret.filter(Case.module_id.in_(module_data)) if priority: priority = priority.split(',') ret = ret.filter(Case.priority.in_(priority)) if ctype: ret = ret.filter(func.find_in_set(ctype, Case.ctype)) if user_ids: user_ids = user_ids.split(',') ret = ret.filter(Case.creator.in_(user_ids)) if title: ret = ret.filter( or_(Case.title.like('%{}%'.format(title)), Case.cnumber.like('%{}%'.format(title)))) if start_time and end_time: ret = ret.filter( Case.creation_time.between(start_time, end_time + " 23:59:59")) if mid: ret = ret.filter(Case.module_id == mid) pid = None if pid: ret = ret.filter( Case.status == Case.ACTIVE, Case.module_id.in_([ module_lists[0] for module_lists in db.session.query(Module.id).filter( Module.project_id == pid, Module.status == Module.ACTIVE).all() ])).order_by(desc(Case.id)) else: ret = ret.filter(Case.status == Case.ACTIVE).order_by(desc( Case.id)) return ret
def http_select(intBool): """API测试首页""" loginProjects_tuple = Login_Base_Project.query.filter_by( status=1).all() #封装登录提供方法 loginProjects = [m.project for m in loginProjects_tuple] isAdmin = session.get("isAdmin") deptNameSession = session.get("deptName") if isAdmin: #判断管理员 Api_project = Project.query.distinct().all() #提取所有测试项目,传入页面中 tester_user = User.query.distinct().all() style = "" selfApi_project = Api_project else: if intBool == "1": #当前项目组查看 Api_project = Project.query.filter( func.find_in_set(deptNameSession, Project.test_group)).distinct().all() dept = DeptName.query.filter( DeptName.deptName == deptNameSession).first() tester_user = User.query.filter_by(status=1, deptId=dept.deptId).all() style = "" selfApi_project = Api_project else: Api_project = Project.query.filter( Project.test_group != deptNameSession).distinct().all() dept = DeptName.query.filter( DeptName.deptName == deptNameSession).first() deptId = dept.deptId tester_user = User.query.filter( and_(User.status == 1, User.deptId != deptId)).all() style = 'style=display:none' selfApi_project = Project.query.filter( Project.test_group == deptNameSession).distinct().all() users = [singleUser.userName for singleUser in tester_user] return render_template("/api_test/case_http_edit.html", style=style, selfApi_project=selfApi_project, api_project=Api_project, tester=users, intBool=intBool, loginProjects=loginProjects)
def get(self, id=None): parser = RequestParser(trim=True) parser.add_argument('page', type=int, default=DEFAULT_PAGE) parser.add_argument('levels', type=int) parser.add_argument('status', type=int) parser.add_argument('type', type=int) parser.add_argument('pageSize', type=int, default=DEFAULT_PAGE_SIZE) args = parser.parse_args(strict=True) pagination = None criterion = set() if id is not None: criterion.add(SystemBankAccount.id == id) criterion.add(SystemBankAccount.isDelete == 0) # pagination = paginate(SystemBankAccount.query.filter(SystemBankAccount.id == id ,SystemBankAccount.isDelete == 0), page=args['page'], per_page=args['pageSize']) else: if args['status'] == 1 or args['status'] == 0: criterion.add(SystemBankAccount.status == args['status']) criterion.add(SystemBankAccount.isDelete == 0) # pagination = paginate(SystemBankAccount.query.filter(SystemBankAccount.status == args['status'],SystemBankAccount.isDelete == 0), page=args['page'], per_page=args['pageSize']) elif args['levels']: criterion.add( func.find_in_set(args['levels'], SystemBankAccount.levels, SystemBankAccount.isDelete == 0)) # criterion.add(func.find_in_set(args['levels'])) # criterion.add(SystemBankAccount.isDelete == 0) # pagination = paginate(SystemBankAccount.query.filter(func.find_in_set(args['levels'], SystemBankAccount.levels,SystemBankAccount.isDelete == 0))) else: criterion.add(SystemBankAccount.isDelete == 0) # pagination = paginate(SystemBankAccount.query.filter(SystemBankAccount.isDelete == 0), page=args['page'], per_page=args['pageSize']) if args['type'] is not None: criterion.add(SystemBankAccount.type == args['type']) # pagination = paginate(SystemBankAccount.query.filter(SystemBankAccount.type == args['type']), page=args['page'], per_page=args['pageSize']) pagination = paginate(SystemBankAccount.query.filter(*criterion), page=args['page'], per_page=args['pageSize']) return make_response_from_pagination(pagination)
def get(self, id=None): m_args = sysadminBank_parsers.parse_args(strict=True) criterion = set() if id: criterion.add(SysadminOnline.id == id) if m_args['pay_type']: criterion.add(SysadminOnline.pay_type == m_args['pay_type']) if m_args['enable'] == 1 or m_args['enable'] == 0: criterion.add(SysadminOnline.enable == m_args['enable']) if m_args['gradeList']: criterion.add( func.find_in_set(m_args['gradeList'], SysadminOnline.gradeList, SysadminOnline.isDelete == 0)) m_rom = SysadminOnline() page = m_rom.getData(criterion, m_args['page'], m_args['pageSize']) if page is None: return {'data': []} return { 'data': page.items, 'pages': page.pages, 'pageNum': page.page, 'pageSize': len(page.items) }