def show_default_case(request, sys_name,url_path, html_page): page = request.GET.get('page', 1) user_no = request.COOKIES.get('user') case_data_list = db_case_info.handel_query_case(None, **{'sys_name': sys_name}) case_count = len(case_data_list) case_pager = Paginator(case_data_list, 10) try: cur_page = int(page) # 获取当前页码的所有数据 data_list = case_pager.page(cur_page).object_list previous_next_page = case_pager.page(page) for item in data_list: test_res = item['test_res'] if not test_res: item['test_res'] = 'Error' create_time = str(item['create_time'])[0:10] item['create_time'] = create_time update_time = str(item['update_time'])[0:10] item['update_time'] = update_time except PageNotAnInteger: # 如果用户输入的页码不是整数时,显示第1页的内容 data_list = case_pager.page(1).object_list for item in data_list: test_res = item['test_res'] if not test_res: item['test_res'] = 'Error' create_time = str(item['create_time'])[0:10] item['create_time'] = create_time update_time = str(item['update_time'])[0:10] item['update_time'] = update_time except EmptyPage: # 如果用户输入的页数不在系统的页码列表中时,显示最后一页的内容 data_list = case_pager.page(case_pager.num_pages) for item in data_list: test_res = item['test_res'] if not test_res: item['test_res'] = 'Error' create_time = str(item['create_time'])[0:10] item['create_time'] = create_time update_time = str(item['update_time'])[0:10] item['update_time'] = update_time rep_html_page = render(request, html_page, locals()) rsp_html_page = public.update_token(request, user_no, rep_html_page) return rsp_html_page
def index(request): # 获取默认页面和默认状态列表(首页) home_url = '/homePage' path = "/homePage" user_no = request.COOKIES.get('user') home_data_dict = show_home(user_no) if home_data_dict: all_sys_test_case_data_dict = home_data_dict[0] single_sys_test_data_dict = home_data_dict[1] user_sys_dict = home_data_dict[2] #统计单个系统测试用例数 for key, val in single_sys_test_data_dict.items(): single_sys_test_data_dict[key]['passed'] = (len(val['passed'])) single_sys_test_data_dict[key]['failed'] = (len(val['failed'])) single_sys_test_data_dict[key]['error'] = (len(val['error'])) #获取所有菜单名称以及路径 all_sys_menu_dict = {} for key, val in single_sys_test_data_dict.items(): for k, v in val.items(): if k == key: sys_menu_dict = {k: v} all_sys_menu_dict.update(sys_menu_dict) html_page = render(request, 'layout.html', locals()) print('all_sys_test_case_data_dict:',all_sys_test_case_data_dict) print('single_sys_test_data_dict:', single_sys_test_data_dict) print('user_sys_dict:', user_sys_dict) print('all_sys_menu_dict:', all_sys_menu_dict) # statistics_sys_data_dict = copy.deepcopy(single_sys_test_data_dict) # for key, val in statistics_sys_data_dict.items(): # statistics_sys_data_dict[key]['passed'] = (len(val['passed'])) # statistics_sys_data_dict[key]['failed'] = (len(val['failed'])) # statistics_sys_data_dict[key]['error'] = (len(val['error'])) html_page = render(request, 'layout.html',locals()) response_html = public.update_token(request, user_no, html_page) return html_page
def sys_manage(request): user_no = request.COOKIES.get('user') path = "/sysManage" page = request.GET.get('page', 1) get_sys_list = db_sys_info.handel_query_sys() pending_pager = Paginator(get_sys_list, 10) try: currentPage = int(page) # 获取当前页码的所有数据 data_list = pending_pager.page(currentPage).object_list previous_next_page = pending_pager.page(page) for item in data_list: create_time = str(item['create_time'])[0:10] item['create_time'] = create_time except PageNotAnInteger: # 如果用户输入的页码不是整数时,显示第1页的内容 data_list = pending_pager.page(1).object_list for item in data_list: create_time = str(item['create_time'])[0:10] item['create_time'] = create_time except EmptyPage: # 如果用户输入的页数不在系统的页码列表中时,显示最后一页的内容 data_list = pending_pager.page(pending_pager.num_pages) for item in data_list: create_time = str(item['create_time'])[0:10] item['create_time'] = create_time print('data_list:',data_list) req_page = render(request, 'sys_manage.html', locals()) response = public.update_token(request, user_no, req_page) return response
def home(request): home_url = '/homePage' path = "/homePage" user_no = request.COOKIES.get('user') #获取首页数据 home_data_dict = show_home(user_no) if home_data_dict: #获取所有系统测试数据 all_sys_test_case_data_dict = home_data_dict[0] #获取单个系统的测试数据 single_sys_test_data_dict = home_data_dict[1] #用户锁拥有的系统编号 user_sys_dict = home_data_dict[2] # 统计单个系统测试用例数 for key, val in single_sys_test_data_dict.items(): single_sys_test_data_dict[key]['passed'] = (len(val['passed'])) single_sys_test_data_dict[key]['failed'] = (len(val['failed'])) single_sys_test_data_dict[key]['error'] = (len(val['error'])) # 获取所有菜单名称以及路径 all_sys_menu_dict = {} for key, val in single_sys_test_data_dict.items(): for k, v in val.items(): if k == key: sys_menu_dict = {k: v} all_sys_menu_dict.update(sys_menu_dict) # statistics_sys_data_dict = copy.deepcopy(single_sys_test_data_dict) html_page = render(request, 'layout.html', locals()) response_html = public.update_token(request, user_no, html_page) return html_page
def user_manage(request): user = request.COOKIES.get('user') path = '/userManagePage' user_data_list = db_user_info.handel_query_user_info() user_pager = Paginator(user_data_list, 10) try: page = request.GET.get('page', 1) currentPage = int(page) # 获取当前页码的所有数据 data_list = user_pager.page(currentPage).object_list previous_next_page = user_pager.page(page) for item in data_list: create_time = str(item['create_time'])[0:10] item['create_time'] = create_time status = item['status'] for k, v in config.user_status.items(): if k == str(status): item['status'] = v none_vale_set = set() for i in range(len(data_list)): for k, v in data_list[i].items(): if v is None: none_vale_set.add(k) none_vale_list = list(none_vale_set) for none_vale in none_vale_list: for item in data_list: if item[none_vale] is None: del item[none_vale] except PageNotAnInteger: # 如果用户输入的页码不是整数时,显示第1页的内容 data_list = user_pager.page(1).object_list for item in data_list: create_time = str(item['create_time'])[0:10] item['create_time'] = create_time status = item['status'] for k, v in config.user_status.items(): if k == str(status): item['status'] = v none_vale_set = set() for i in range(len(data_list)): for k, v in data_list[i].items(): if v is None: none_vale_set.add(k) none_vale_list = list(none_vale_set) for none_vale in none_vale_list: for item in data_list: if item[none_vale] is None: del item[none_vale] except EmptyPage: # 如果用户输入的页数不在系统的页码列表中时,显示最后一页的内容 data_list = user_pager.page(user_pager.num_pages) for item in data_list: create_time = str(item['create_time'])[0:10] item['create_time'] = create_time status = item['status'] for k, v in config.user_status.items(): if k == str(status): item['status'] = v none_vale_set = set() for i in range(len(data_list)): for k, v in data_list[i].items(): if v is None: none_vale_set.add(k) none_vale_list = list(none_vale_set) for none_vale in none_vale_list: for item in data_list: if item[none_vale] is None: del item[none_vale] req_page = render(request, 'user_manage.html', locals()) response = public.update_token(request, user, req_page) return response
def query_case_info(request, sys_name, url_path, html_page): ''' :param request: 前端的查询请求对象 :param sys_name: 系统名称 :param url_path: url路由 :param html_page: 对象系统的html :return: html对象和用例查询结果 ''' #获取前端的查询数据 query_req_data = dict(request.GET) query_data = {} for k, v in query_req_data.items(): query_data[k] = v[0].strip().lower() user_no = request.COOKIES.get('user') query_id = user_no + sys_name try: #code表示是带有查询条件的查询,非默认展示(code:search) search_value = query_data['code'] del query_data['code'] mc.set(query_id, query_data) except Exception: #此处为查询后翻页的分支,翻页时,获取上一次查询记录 #根据上一次的查询条件再次 查询 query_data = mc.get(query_id) print('异常查询query_data:', query_data) #获取哪些条件是没有查询条件值 null_value_list = [] for k, v in query_data.items(): if v is None: null_value_list.append(k) #删除没有查询条件值得查询条件 for key in null_value_list: del query_data[key] result_data_list = db_case_info.handel_query_case(None, **query_data) case_count = len(result_data_list) case_pager = Paginator(result_data_list, 10) page = request.GET.get('page', 1) try: cur_page = int(page) # 获取当前页码的所有数据 data_list = case_pager.page(cur_page).object_list previous_next_page = case_pager.page(page) for item in data_list: test_res = item['test_res'] if not test_res: item['test_res'] = 'Error' create_time = str(item['create_time'])[0:10] item['create_time'] = create_time update_time = str(item['update_time'])[0:10] item['update_time'] = update_time except PageNotAnInteger: # 如果用户输入的页码不是整数时,显示第1页的内容 data_list = case_pager.page(1).object_list for item in data_list: test_res = item['test_res'] if not test_res: item['test_res'] = 'Error' create_time = str(item['create_time'])[0:10] item['create_time'] = create_time update_time = str(item['update_time'])[0:10] item['update_time'] = update_time except EmptyPage: # 如果用户输入的页数不在系统的页码列表中时,显示最后一页的内容 data_list = case_pager.page(case_pager.num_pages) for item in data_list: test_res = item['test_res'] if not test_res: item['test_res'] = 'Error' create_time = str(item['create_time'])[0:10] item['create_time'] = create_time update_time = str(item['update_time'])[0:10] item['update_time'] = update_time rep_html_page = render(request, html_page, locals()) rsp_html_page = public.update_token(request, user_no, rep_html_page) return rsp_html_page