Пример #1
0
def add_user(request):
    data = {}
    try:
        try:
            # 查询用户名是否存在
            user = User.objects.get(status=1,
                                    username=request.POST.get('username'))
            data['code'] = 404
            data['message'] = "用户名已存在"
        except Exception as e:
            print(e.args)

            user = User()

            user.username = request.POST.get('username')
            user.name = request.POST.get('name')
            user.tel = request.POST.get('tel')
            user.email = request.POST.get('email')
            user.role = request.POST.get('role')
            user.password = make_password(request.POST.get('password'))
            user.superior = 0

            user.save()

            data['code'] = 0
            data['message'] = "新增管理员成功"

    except Exception as e:
        print(e.args)
        data['code'] = 404
        data['message'] = "新增失败"
    # 转化为Json
    response = JsonResponse(data, json_dumps_params={'ensure_ascii': False})
    return response
Пример #2
0
 def get(self, request, **kwargs):
     LoginAuth_jltom = request.COOKIES.get('LoginAuth_jltc')
     if LoginAuth_jltom is None:
         login_auth = "unknown_user"
     else:
         login_auth = request.COOKIES.get('LoginAuth_jltc').split(':')[0]
     if not User.objects.filter(login=login_auth).exists():
         u = User(login=login_auth)
         u.save()
         user_id = u.id
     else:
         u = User.objects.get(login=login_auth)
         user_id = u.id
     return render(request, 'index.html', {
         'user': u,
     })
Пример #3
0
def test_data_refresh(request):
    builds_dir = "/var/lib/jenkins/jobs"
    # builds_dir="C:\\work\\reportdata"
    build_xml = ElementTree()
    rx = re.compile(r'/var/lib/jenkins/jobs/.+?/builds/\d+?/build\.xml')
    # rx = re.compile(r'C:\\work\\reportdata.+?\\builds\\\d+?\\build\.xml')
    logger.info("Refreshing test data")
    for root, dirs, files in os.walk(builds_dir):
        for file in files:
            if re.match(rx, os.path.join(root, file)):
                if os.stat(os.path.join(root, file)).st_size > 0:
                    build_parameters = []
                    display_name = "unknown"
                    description = ""
                    start_time = 0
                    duration = 0
                    build_xml_path = os.path.join(root, "build.xml")
                    if os.path.isfile(build_xml_path):
                        logger.info(
                            "Try to parse Jenkins build XML-file: {0}".format(
                                build_xml_path))
                        with open(build_xml_path, "r") as fixfile:
                            data = fixfile.read()
                        data = data.replace("&#x", "")
                        with open(build_xml_path, "w") as fixfile:
                            fixfile.write(data)
                        build_xml.parse(build_xml_path)
                        build_tag = build_xml.getroot()

                        for params in build_tag:
                            if params.tag == 'actions':
                                parameters = params.find('.//parameters')
                                for parameter in parameters:
                                    name = parameter.find('name')
                                    value = parameter.find('value')
                                    build_parameters.append(
                                        [name.text, value.text])
                                userId = params.find('.//userId')
                                if userId is not None:
                                    started_by = userId.text
                                    if not User.objects.filter(
                                            login=started_by).exists():
                                        u = User(login=started_by)
                                        u.save()
                                        user_id = u.id
                                    else:
                                        u = User.objects.get(login=started_by)
                                        user_id = u.id
                                else:
                                    user_id = 0
                            elif params.tag == 'startTime':
                                start_time = int(params.text)
                            elif params.tag == 'displayName':
                                display_name = params.text
                            elif params.tag == 'duration':
                                duration = int(params.text)
                            elif params.tag == 'description':
                                description = params.text
                        if Test.objects.filter(path=root).exists():
                            test = Test.objects.get(path=root)
                            logger.info("Updating test, id: {0}".format(
                                str(test.id)))
                            test.display_name = display_name
                            test.start_time = start_time
                            test.end_time = start_time + duration
                            test.description = description
                            test.parameters = build_parameters
                            test.started_by_id = user_id
                            test.save()
    response = {
        "message": {
            "text": "Tests information was updated.",
            "type": "info",
            "msg_params": {}
        }
    }

    return JsonResponse(response, safe=False)