def search(request): try: wd = request.GET["wd"] product_code = request.GET["product_code"] except Exception as e: return JsonResponse({"status": 40004, "msg": u"请求参数错误."}) if "status" in request.GET: status = request.GET["status"] else: status = 0 try: data = TestCase.objects.\ filter(Q(product_code=product_code) & Q(status=status) & Q(isDelete=0) & ( Q(title__icontains=wd) | Q(id__icontains=wd)) ).\ annotate( creator=F("creator_id__realname") ).\ values("id","case_id","product_code","status","title","priority", "isChange","isReview","creator","creator_id","create_time") except Exception as e: print(e) return JsonResponse({"status": 20004, "msg": u"查询异常错误,请联系管理员."}) else: if len(data) == 0: return JsonResponse({"status": 20001, "msg": "根据搜索条件,没有查到数据"}) else: return HttpResponse(get_listing(request.GET, data))
def testcase_list(request): q1 = Q() q1.connector = "AND" try: product_code = request.GET["product_code"] q1.children.append(Q(**{"product_code": product_code})) except Exception as e: return JsonResponse({"status": 40004, "msg": "缺少必要的请求值"}) if "m1_id" in request.GET: m1_id = request.GET["m1_id"] q1.children.append(Q(**{"m1_id": m1_id})) if "m2_id" in request.GET: m2_id = request.GET["m2_id"] q1.children.append(Q(**{"m2_id": m2_id})) if "status" in request.GET: status = request.GET["status"] q1.children.append(Q(**{"status": status})) try: data = TestCase.objects.\ filter(q1).\ annotate( creator=F("creator_id__realname") ).\ values("id","case_id","product_code","status","title","priority", "isChange","isReview","creator","creator_id","create_time").\ order_by("-create_time") except Exception as e: return JsonResponse({"status": 20004, "msg": u"查询发生异常错误,请联系管理员."}) else: return HttpResponse(get_listing(request.GET, data))
def testcase_valid_list(request): q1 = Q() q1.connector = "AND" try: print() product_code = request.GET["product_code"] q1.children.append(Q(**{"product_code": product_code})) except Exception as e: print(e) return JsonResponse({"status": 40004, "msg": "缺少必要的请求值"}) if "m2_id" in request.GET: m2_id = request.GET["m2_id"] q1.children.append(Q(**{"m2_id": m2_id})) if "m1_id" in request.GET: m1_id = request.GET["m1_id"] q1.children.append(Q(**{"m1_id": m1_id})) try: q1.children.append(Q(**{"isDelete": 0})) q1.children.append(Q(**{"status": 0})) data = TestCase.objects.\ filter(q1).\ values("id","case_id","title").order_by("id") except Exception as e: print(e) return JsonResponse({"status": 20004, "msg": u"查询异常错误,请联系管理员."}) else: return HttpResponse(get_listing(request.GET, data))
def testsuite_list(request): user_id = get_uid(request) query_data = ProductMembers.objects.filter(Q(member_id=user_id) & Q(status=0)).\ annotate(product_name=F('product_code__product_name'),create_time=F('product_code__create_time')).\ values_list('product_code').order_by('-create_time') product_list = list(query_data) print(product_list) try: suite_data = TestSuite.objects.filter(product_code__in=product_list).\ values("id","product_code","suite_id","suite_name").order_by("-create_time") tmp = [] for i in suite_data: i["bug_num"] = Bug.objects.filter( Q(cell_id__suite_id=i["suite_id"])).count() i["total"] = TestSuiteCell.objects.filter( Q(suite_id=i["suite_id"])).count() i["executed"] = TestSuiteCell.objects.filter( Q(suite_id=i["suite_id"]) & ~Q(result="0")).count() i["not_execution"] = TestSuiteCell.objects.filter( Q(suite_id=i["suite_id"]) & Q(result="0")).count() i["success"] = TestSuiteCell.objects.filter( Q(suite_id=i["suite_id"]) & Q(result="1")).count() i["fail"] = TestSuiteCell.objects.filter( Q(suite_id=i["suite_id"]) & Q(result="-1")).count() tmp.append(i) except Exception as e: print(e) return JsonResponse({"status": 40001, "msg": "服务器开小差了"}) else: return HttpResponse(get_listing(request.GET, tmp))
def cell_brief_list(request): try: suite_id = request.GET["suite_id"] except Exception as e: return JsonResponse({"status": 40001, "msg": "suite_id不能为空"}) try: data = TestSuiteCell.objects.filter(Q(suite_id=suite_id)).\ annotate( title=F("case_id__title") ).\ values("title","case_id","id") except Exception as e: return JsonResponse({"status": 20004, "msg": "查询出错,请联系管理员"}) else: return HttpResponse(get_listing(request.GET, data))
def testsutie_cell_list(request): try: suite_id = request.GET["suite_id"] except Exception as e: return JsonResponse({"status": 40001, "msg": "suite_id不能为空"}) try: data = [] suite_data = TestSuiteCell.objects.filter(Q(suite_id=suite_id)).\ annotate( title=F("case_id__title"), runner=F("runner_id__realname") ).\ values("id","title","case_id","result","run_time","runner","cell_id") for i in suite_data: cid = i['cell_id'] tmp = Bug.objects.filter(Q(cell_id=cid)).values('bug_id') i['bug_id'] = list(tmp) data.append(i) except Exception as e: print(e) return JsonResponse({"status": 20004, "msg": "查询出错,请联系管理员"}) else: return HttpResponse(get_listing(request.GET, data))
def search(request): query = Q() q1 = Q() q1.connector = "AND" try: req = json.loads(request.body) product_code = req["product_code"] Operators = req["Operators"] SearchType = req["SearchType"] q1.children.append(Q(**{"product_code":product_code})) productObject = Product.objects.get(product_code=product_code) except Exception as e: return JsonResponse({"status": 40001, "msg": u"请求缺少必要的值."}) if "release" in req: try: release = req["release"] if release == "all": del req["release"] else: release_query = Release.objects.filter(Q(product_code=product_code) & Q(version=release)).values('id') if len(release_query) == 0: return JsonResponse({"status":40004,"msg":"版本号错误"}) else: q1.children.append(Q(**{"version_id":list(release_query)[0]['id']})) except Exception as e: return JsonResponse({"status":40004,"msg":"产品名称或版本号错误"}) if "status" in req: if req["status"] == "all": del req["status"] elif req["status"] == "notClosed": q1.children.append(~Q(**{"status":"Closed"})) else: status = req["status"] q1.children.append(Q(**{"status":status})) q1.children.append(Q(**{"isDelete":0})) try: query.add(q1, "AND") query.add(handle_search(req), "AND") data = Bug.objects.filter(query). \ annotate( creator_user=F("creator_id__realname"), assignedTo_user=F("assignedTo_id__realname"), severity_name=F("severity__name"), priority_name=F("priority__name"), status_name = F("status__name"), solution_name=F("solution__name") ).\ order_by("-create_time").\ values("id","bug_id","title","status","status_name","solution_name",\ "priority","priority_name","severity","severity_name","solution",\ "creator_id","creator_user","create_time",\ "assignedTo_user","assignedTo_time","fixed_id","fixed_time","closed_id","closed_time") except Exception as e: print(e) return JsonResponse({"status": 40004, "msg": u"异常错误,请联系管理员."}) else: if len(data) == 0: return JsonResponse({"status": 20004, "msg": "没有查到该条数据"}) else: return HttpResponse(get_listing(req,data))
def bug_list(request): # query builder conditions = Q() q1 = Q() q1.connector = "AND" # set data order order = "-create_time" try: req = request.GET.dict() product_code = req["product_code"] except Exception as e: return JsonResponse({"status":40001,"msg":"请求缺少必要的值"}) if "release" in req: try: release = req["release"] if release == "all": del req["release"] else: release_query = Release.objects.filter(Q(product_code=product_code) & Q(version=release)).values('id') if len(release_query) == 0: return JsonResponse({"status":40004,"msg":"版本号错误"}) else: q1.children.append(Q(**{"version_id":list(release_query)[0]['id']})) except Exception as e: return JsonResponse({"status":40004,"msg":"产品名称或版本号错误"}) if "status" in req: if req["status"] == "all": del req["status"] elif req["status"] == "notClosed": q1.children.append(~Q(**{"status":"Closed"})) else: status = req["status"] q1.children.append(Q(**{"status":status})) if "m1_id" in request.GET: m1_id = request.GET["m1_id"] q1.children.append(Q(**{"m1_id":m1_id})) if "m2_id" in request.GET: m2_id = request.GET["m2_id"] q1.children.append(Q(**{"m2_id":m2_id})) if "severity" in req: if req["severity"] == "all": del req["severity"] if "priority" in req: if req["priority"] == "all": del req["priority"] for data in req.items(): if "product_code" in data or "priority" in data or "severity" in data: q1.children.append(Q(**{data[0]: data[1]})) if "operate" in req: operate = req["operate"] if operate == "AssignedByMe": conditions.children.append(Q(**{"assignedTo_id":get_uid(request)})) if operate == "ResolvedByMe": conditions.children.append(Q(**{"fixed_id":get_uid(request)})) if operate == "ClosedByMe": conditions.children.append(Q(**{"closed_id":get_uid(request)})) if operate == "CreatedByMe": conditions.children.append(Q(**{"creator_id":get_uid(request)})) if operate == "notClosed": q1.children.append(~Q(**{"status":"Closed"})) if operate == "WaitPending": my_group = get_user_group(request) print("+++++",my_group) if my_group == 'test': q2 = Q() q2.connector = "AND" q2.children.append(Q(**{"assignedTo_id":get_uid(request)})) q2.children.append(~Q(**{"status":"closed"})) conditions.add(q2, "AND") else: q2 = Q() q2.connector = "AND" q2.children.append(Q(**{"assignedTo_id":get_uid(request)})) temp_q2_1 = Q() temp_q2_1.connector = "OR" temp_q2_1.children.append(Q(**{"status":"Open"})) temp_q2_1.children.append(Q(**{"status":"Reopen"})) temp_q2_1.children.append(Q(**{"status":"Hang-up"})) q2.add(temp_q2_1, "AND") conditions.add(q2, "AND") if operate == "NotResolved": q2 = Q() q2.connector = "OR" q2.children.append(Q(**{"status":"New"})) q2.children.append(Q(**{"status":"Open"})) q2.children.append(Q(**{"status":"Reopen"})) q2.children.append(Q(**{"status":"Hang-up"})) conditions.add(q2, "AND") if operate == "HighPriority": order = "priority" conditions.add(q1, "AND") try: data = Bug.objects.filter(conditions).\ annotate( creator_user=F("creator_id__realname"), assignedTo_user=F("assignedTo_id__realname"), severity_name=F("severity__name"), priority_name=F("priority__name"), status_name = F("status__name"), solution_name=F("solution__name") ).\ order_by(order).\ values("id","product_code","bug_id","title","status","status_name","solution_name",\ "priority","priority_name","severity","severity_name","solution",\ "creator_id","creator_user","create_time",\ "assignedTo_user","assignedTo_time","fixed_id","fixed_time","closed_id","closed_time") except Exception as e: print(e) return JsonResponse({"status":40004,"msg":"异常错误,请联系管理员"}) else: return HttpResponse(get_listing(request.GET, data))