def suite_list(request, id): if request.session.get('login_status'): account = request.session["now_account"] if request.is_ajax(): suite_info = json.loads(request.body.decode('utf-8')) if suite_info.get('mode') == 'del': msg = del_suite_data(suite_info.pop('id')) elif suite_info.get('mode') == 'copy': msg = copy_suite_data( suite_info.get('data').pop('index'), suite_info.get('data').pop('name')) return HttpResponse(get_ajax_msg(msg, 'ok')) else: filter_query = set_filter_session(request) pro_list = get_pager_info(TestSuite, filter_query, '/api/suite_list/', id) manage_info = { 'account': account, 'suite': pro_list[1], 'page_list': pro_list[0], 'info': filter_query, 'sum': pro_list[2], 'env': EnvInfo.objects.all().order_by('-create_time') } return render_to_response('suite_list.html', manage_info) else: return HttpResponseRedirect("/api/login/")
def report_list(request, id): """ 报告列表 :param request: :param id: str or int:当前页 :return: """ if request.session.get('login_status'): if request.is_ajax(): report_info = json.loads(request.body.decode('utf-8')) if report_info.get('mode') == 'del': msg = del_report_data(report_info.pop('id')) return HttpResponse(get_ajax_msg(msg, 'ok')) else: filter_query = set_filter_session(request) report_list = get_pager_info(TestReports, filter_query, '/api/report_list/', id) manage_info = { 'account': request.session["now_account"], 'report': report_list[1], 'page_list': report_list[0], 'info': filter_query } return render_to_response('report_list.html', manage_info) else: return HttpResponseRedirect("/api/login/")
def periodictask(request, id): """ 定时任务列表 :param request: :param id: str or int:当前页 :return: """ if request.session.get('login_status'): account = request.session["now_account"] if request.is_ajax(): kwargs = json.loads(request.body.decode('utf-8')) mode = kwargs.pop('mode') id = kwargs.pop('id') msg = delete_task(id) if mode == 'del' else change_task_status( id, mode) return HttpResponse(get_ajax_msg(msg, 'ok')) else: filter_query = set_filter_session(request) task_list = get_pager_info(PeriodicTask, filter_query, '/api/periodictask/', id) manage_info = { 'account': account, 'task': task_list[1], 'page_list': task_list[0], 'info': filter_query } return render_to_response('periodictask_list.html', manage_info) else: return HttpResponseRedirect("/api/login/")
def edit_config(request, id=None): """ 编辑配置 :param request: :param id: :return: """ if request.session.get('login_status'): account = request.session["now_account"] if request.is_ajax(): testconfig_lists = json.loads(request.body.decode('utf-8')) msg = config_info_logic(type=False, **testconfig_lists) return HttpResponse(get_ajax_msg(msg, '/api/config_list/1/')) config_info = TestCaseInfo.objects.get_case_by_id(id) request = eval(config_info[0].request) manage_info = { 'account': account, 'info': config_info[0], 'request': request['config'], 'project': ProjectInfo.objects.all().values('project_name').order_by( '-create_time') } return render_to_response('edit_config.html', manage_info) else: return HttpResponseRedirect("/api/login/")
def config_list(request, id): """ 配置列表 :param request: :param id: str or int:当前页 :return: """ if request.session.get('login_status'): account = request.session["now_account"] if request.is_ajax(): test_info = json.loads(request.body.decode('utf-8')) if test_info.get('mode') == 'del': msg = del_test_data(test_info.pop('id')) elif test_info.get('mode') == 'copy': msg = copy_test_data( test_info.get('data').pop('index'), test_info.get('data').pop('name')) return HttpResponse(get_ajax_msg(msg, 'ok')) else: filter_query = set_filter_session(request) test_list = get_pager_info(TestCaseInfo, filter_query, '/api/config_list/', id) manage_info = { 'account': account, 'test': test_list[1], 'page_list': test_list[0], 'info': filter_query } return render_to_response('config_list.html', manage_info) else: return HttpResponseRedirect("/api/login/")
def module_list(request, id): """ 模块列表 :param request: :param id: str or int:当前页 :return: """ if request.session.get('login_status'): account = request.session["now_account"] if request.is_ajax(): module_info = json.loads(request.body.decode('utf-8')) if 'mode' in module_info.keys(): # del module msg = del_module_data(module_info.pop('id')) else: msg = module_info_logic(type=False, **module_info) return HttpResponse(get_ajax_msg(msg, 'ok')) else: filter_query = set_filter_session(request) module_list = get_pager_info(ModuleInfo, filter_query, '/api/module_list/', id) manage_info = { 'account': account, 'module': module_list[1], 'page_list': module_list[0], 'info': filter_query, 'sum': module_list[2], 'env': EnvInfo.objects.all().order_by('-create_time') } return render_to_response('module_list.html', manage_info) else: return HttpResponseRedirect("/api/login/")
def register(request): """ 注册 :param request: :return: """ if request.is_ajax(): user_info = json.loads(request.body.decode('utf-8')) msg = register_info_logic(**user_info) return HttpResponse(get_ajax_msg(msg, '恭喜您,账号已成功注册')) elif request.method == 'GET': return render_to_response("register.html")
def env_set(request): """ 环境设置 :param request: :return: """ if request.session.get('login_status'): account = request.session["now_account"] if request.is_ajax(): env_lists = json.loads(request.body.decode('utf-8')) msg = env_data_logic(**env_lists) return HttpResponse(get_ajax_msg(msg, 'ok')) elif request.method == 'GET': return render_to_response('env_list.html', {'account': account}) else: return HttpResponseRedirect("/api/login/")
def add_suite(request): if request.session.get('login_status'): account = request.session["now_account"] if request.is_ajax(): kwargs = json.loads(request.body.decode('utf-8')) msg = add_suite_data(**kwargs) return HttpResponse(get_ajax_msg(msg, '/api/suite_list/1/')) elif request.method == 'GET': manage_info = { 'account': account, 'project': ProjectInfo.objects.all().values('project_name').order_by( '-create_time') } return render_to_response('add_suite.html', manage_info) else: return HttpResponseRedirect("/api/login/")
def add_module(request): """ 新增模块 :param request: :return: """ if request.session.get('login_status'): account = request.session["now_account"] if request.is_ajax(): module_info = json.loads(request.body.decode('utf-8')) msg = module_info_logic(**module_info) return HttpResponse(get_ajax_msg(msg, '/api/module_list/1/')) elif request.method == 'GET': manage_info = { 'account': account, 'data': ProjectInfo.objects.all().values('project_name') } return render_to_response('add_module.html', manage_info) else: return HttpResponseRedirect("/api/login/")
def add_style(request): """ 新增项目 :param request: :return: """ if request.session.get('login_status'): account = request.session["now_account"] # 当在添加工程界面上面点击了提交按钮,那么就会调用AJAX请求,就会进行保存什么的。 if request.is_ajax(): project_info = json.loads(request.body.decode('utf-8')) print(project_info) msg = project_info_logic(**project_info) return HttpResponse(get_ajax_msg(msg, '/api/project_list/1/')) #每次新建项目都会走这个分支,因为是新建,所以manage_info只有一个key值 elif request.method == 'GET': manage_info = {'account': account} return render_to_response('add_style.html', manage_info) else: return HttpResponseRedirect("/api/login/")
def add_task(request): """ 添加任务 :param request: :return: """ if request.session.get('login_status'): account = request.session["now_account"] if request.is_ajax(): kwargs = json.loads(request.body.decode('utf-8')) print("Add Tast is {}".format(kwargs)) print("Add Tast is {}".format(**kwargs)) msg = task_logic(**kwargs) return HttpResponse(get_ajax_msg(msg, '/api/periodictask/1/')) elif request.method == 'GET': info = { 'account': account, 'env': EnvInfo.objects.all().order_by('-create_time'), 'project': ProjectInfo.objects.all().order_by('-create_time') } return render_to_response('add_task.html', info) else: return HttpResponseRedirect("/api/login/")
def add_config(request): """ 新增配置 :param request: :return: """ if request.session.get('login_status'): account = request.session["now_account"] if request.is_ajax(): testconfig_info = json.loads(request.body.decode('utf-8')) msg = config_info_logic(**testconfig_info) return HttpResponse(get_ajax_msg(msg, '/api/config_list/1/')) elif request.method == 'GET': manage_info = { 'account': account, 'project': ProjectInfo.objects.all().values('project_name').order_by( '-create_time') } return render_to_response('add_config.html', manage_info) else: return HttpResponseRedirect("/api/login/")