Ejemplo n.º 1
0
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))
Ejemplo n.º 2
0
def userinfo(request):
    data = User.objects.filter(user_id=get_uid(request)).values(
        'user_id', 'realname', 'group')
    config = SystemConfig.objects.all().values("code", "code_value")
    return JsonResponse({
        "status": 20000,
        "data": data[0],
        "config": list(config)
    })
Ejemplo n.º 3
0
def my_product_list(request):
    user_id = get_uid(request)
    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('product_code','product_name').order_by('-create_time')
    if len(data) == 0:
        return JsonResponse({"status":20004,"msg":"检测到您不在任何项目列表中,请联系管理员添加!"})
    else:
        return JsonResponse({"status":20000,"data":list(data)})
Ejemplo n.º 4
0
def set_passwd(request):

    try:
        req_info = json.loads(request.body)
        old_passwd = req_info["oldPassword"]
        new_passwd = req_info["newPassword"]
    except Exception as e:
        return JsonResponse({"status": 40004, "msg": "缺少必要的请求值."})

    try:
        userinfo = User.objects.filter(user_id=get_uid(request)).values_list(
            'password', 'email')
        # 旧密码加密后的字符串
        old_passwd_encrypted = p_encrypt(str(old_passwd), userinfo[0][1])
    except Exception as e:
        return JsonResponse({"status": 40004, "msg": "系统异常错误."})
    else:
        # 旧密码校验
        if old_passwd_encrypted != userinfo[0][0]:
            return JsonResponse({"status": 20004, "msg": "旧密码输入错误"})

    if len(new_passwd) < 8:
        return JsonResponse({"status": 20004, "msg": "新密码长度太短"})
    else:
        # 密码加密
        encrypt_passwd = p_encrypt(str(new_passwd), userinfo[0][1])
        try:
            pd = User.objects.get(user_id=get_uid(request))
            pd.password = encrypt_passwd
            pd.save()
        except Exception as e:
            return JsonResponse({"status": 20004, "mgs": "密码修改失败"})
        # token
        try:
            tk = Authentication.objects.get(uid=get_uid(request))
            tk.token = generate_token()
            tk.save()
        except Exception as e:
            return JsonResponse({"status": 40004, "mgs": "密码修改失败"})
        else:
            return JsonResponse({"status": 20000, "mgs": "您已成功修改密码,请牢记。"})
Ejemplo n.º 5
0
def product_release(request):
    
    user_id = get_uid(request)
    product = 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('product_code','product_name').order_by('-create_time')
    if len(product) == 0:
        return JsonResponse({"status":20004,"msg":"检测到您不在任何项目列表中,请联系管理员添加!"})
    else:
        data = []
        for i in product:
            data.append({
                'product_code':i['product_code'],
                'product_name':i['product_name'],
                'data':list(Release.objects.filter(product_code=i['product_code']).values('version').order_by('-create_time'))
                })
        return JsonResponse({"status":20000,"data":data})
Ejemplo n.º 6
0
def banned(request):
    # 封禁权限检测
    uid = get_uid(request)
    is_check_admin = User.objects.filter(Q(user_id=uid) & Q(user_status='1'))
    if len(is_check_admin) == 0:
        return JsonResponse({"status": 14444, "msg": "您不是管理员,不能进行此项操作"})

    try:
        req_info = json.loads(request.body)
        user_id = req_info["user_id"]
        code = req_info["code"]
    except Exception as e:
        return JsonResponse({"status": 40001, "msg": "请求缺少必要的值."})

    # 用户检测
    is_check_banned = User.objects.filter(
        Q(user_id=user_id)).values_list('user_status')
    if len(is_check_banned) == 1:
        pass
        banned_user_status = is_check_banned[0][0]
    else:
        return JsonResponse({"status": 10005, "msg": "用户不存在"})

    if code == "2":
        try:
            bd = User.objects.get(user_id=user_id)
            bd.user_status = 2
            bd.save()
        except Exception as e:
            return JsonResponse({"status": 10061, "msg": "封禁失败"})
        else:
            return JsonResponse({"status": 10060, "msg": "封禁成功"})
    elif code == '1':
        try:
            bd = User.objects.get(user_id=user_id)
            bd.user_status = 1
            bd.save()
        except Exception as e:
            return JsonResponse({"status": 10061, "msg": "解封失败"})
        else:
            return JsonResponse({"status": 10060, "msg": "解封成功"})
    else:
        return JsonResponse({"status": 40004, "msg": "异常错误"})
Ejemplo n.º 7
0
def data_statistics(request):
    uid = get_uid(request)
    try:
        product_code = request.GET['product_code']
    except Exception as e:
        return JsonResponse({"status":40001,"msg":"产品不能为空哦"})

    data = {
        "WaitPending": "",
        "Fixed":"",
        "NotFixed":"",
        "CreatedByMe":"",
        "ClosedByMe":"",
        "Resolved":""
    }
    # 分派给我(需要我处理的)
    try:
        my_group = get_user_group(request,product_id)
        if my_group == 'test':
            WaitPending = Bug.objects.\
                filter(
                    Q(assignedTo_id=uid) & 
                    Q(product_code=product_code) & 
                    ~Q(status='closed')
                ).count()
        else:
            WaitPending = Bug.objects.\
                filter(
                    Q(assignedTo_id=uid) & 
                    Q(product_code=product_code) & 
                    (
                        Q(status='Open') | 
                        Q(status='Hang-up') |
                        Q(status='Reopen')
                    )
                ).count()
    except Exception as e:
        WaitPending = 0
    finally:
        data['WaitPending']= WaitPending

    # 我解决的
    try:
        data_resolvedByMe = Bug.objects.filter(Q(product_code=product_code) & Q(fixed_id=uid)).count()
    except Exception as e:
        data_resolvedByMe = 0
    finally:
        data['ResolvedByMe']= data_resolvedByMe

    # 所有未解决的
    try:
        data_not_Fixed = Bug.objects.\
            filter(
                Q(product_code=product_code) & 
                ( 
                    Q(status='Open') | 
                    Q(status='Hang-up') |
                    Q(status='Reopen')
                )
            ).count()
    except Exception as e:
        data_not_Fixed = 0
    finally:
        data['NotFixed']= data_not_Fixed

    # 我创建的
    try:
        data_createdByMe = Bug.objects.filter(Q(product_code=product_code) & Q(creator_id=uid)).count()
    except Exception as e:
        data_createdByMe = 0
    finally:
        data['CreatedByMe']= data_createdByMe

    # 我关闭的
    try:
        data_closedByMe = Bug.objects.filter(Q(product_code=product_code) & Q(closed_id=uid)).count()
    except Exception as e:
        data_ClosedByMe = 0
    finally:
        data['ClosedByMe']= data_closedByMe

    # 所有已解决待关闭
    try:
        data_Fixed = Bug.objects.filter(Q(product_code=product_code) & Q(status='Fixed')).count()
    except Exception as e:
        data_Fixed = 0
    finally:
        data['Fixed']= data_Fixed

    return JsonResponse({"status":20000,"data":data})
Ejemplo n.º 8
0
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))