Exemple #1
0
def project_change_version(request):
    status = check_auth(request, "select_project")
    if not status:
        return render_to_response('default/error_auth.html', locals())

    dicts = {
        'project_name': '',
        'project_version': '',
        'state': '',
        'create_time': ''
    }
    try:
        select_version = request.GET.get('select_version')
        project_name = select_version.split('-')[0]
        project_version = select_version.split('-')[1]
    except Exception as e:
        logger.error('%s: Get version string is error.',
                     request.user.first_name)
        raise e
    results = projectServices.list_project_by_version(project_name,
                                                      project_version)
    state = results.state
    create_time = results.create_time

    dicts['project_name'] = project_name
    dicts['project_version'] = project_version
    dicts['state'] = state
    dicts['create_time'] = create_time

    return JsonResponse(dicts)
Exemple #2
0
 def _deco(request, *args, **kwargs):
     status = check_auth(request, auth)
     if status:
         return func(request, *args, **kwargs)
     else:
         logger.error('%s: No permission to list the role',
                      request.user.first_name)
         return render(request, 'default/error_auth.html', locals())
Exemple #3
0
def list_projects(request):
    status = check_auth(request, "select_project")
    if not status:
        logger.error('%s: Do not have enough  power access project list.',
                     request.user.first_name)
        return render_to_response('default/error_auth.html', locals())

    results = []

    # list all the projects
    try:
        project_list = projectDetailServices.list_all_projects(
        )  # 包含多个查询结果queryset对象的列表queryset
        project_count = projectDetailServices.list_all_projects().count()
        count = {'count': project_count}
        for item in project_list:  # 迭代出单个的queryset
            version_list = []
            res = {
                'id': '',
                'version': '',
                'state': '',
                'name': '',
                'create_time': ''
            }

            project_name = item.project_name  # 取出该queryset的单个值
            # list the version queryset
            project_version = projectServices.list_all_versions(
                project_name)  # 根据之前的结果进行查询,结果是多个对象的queryset
            # state和create_time取最小的版本做为默认显示
            if project_version:
                version_state = project_version[0].state
                version_create_time = project_version[0].create_time
            else:
                version_state = ''
                version_create_time = ''
            for i in project_version:
                version_list.append(i.version)  # 取值放入列表
            res['id'] = item.id
            res['name'] = item.project_name
            res['version'] = version_list
            res['state'] = version_state
            res['create_time'] = version_create_time
            results.append(res)
    except Exception as e:
        logger.error('%s: Project_list page Get data from database error: %s ',
                     request.user.first_name, e)
    else:
        result_list, paginator, objects, page_range, current_page, show_first, show_end = pages.listing(
            results, request, 2)
        return render_to_response('web/list_projects.html', locals())
Exemple #4
0
def project_add(request):
    status = check_auth(request, "add_project")
    if not status:
        logger.error('%s: Do not have enough  power add project.',
                     request.user.first_name)
        return render_to_response('default/error_auth.html', locals())

    if request.method == 'POST':
        init = request.GET.get("init", False)
        uf = ProjectForm(request.POST)
        uf.project_name = request.POST['project_name']
        project_version = request.POST['project_version']
        war_path = request.POST['war_path']

        ss = uf.is_valid()
        m = uf.errors
        state = 0
        if uf.is_valid():
            project_name = uf.cleaned_data['project_name']
            if PpProjectDetail.objects.filter(
                    project_name=uf.project_name) and PpProject.objects.filter(
                        version=project_version, project_name=project_name):
                emg = u'添加失败,该项目 %s 已存在!' % project_name
                return render_to_response('web/project_add.html', locals())
            try:
                if not PpProjectDetail.objects.filter(
                        project_name=uf.project_name):
                    uf.save()
                if not PpProject.objects.filter(version=project_version,
                                                project_name=project_name):
                    projectServices.save_project(project_name, war_path,
                                                 project_version, state)
            except Exception as e:
                logger.error('%s: Save project to database error: %s.',
                             request.user.username, e)
                raise e
            logger.info('%s: Add the project %s success',
                        request.user.username, project_name)
            if not init:
                return HttpResponseRedirect('/project/list/')
            else:
                return HttpResponseRedirect('/project/list/')
        else:
            return render_to_response('web/project_add.html', locals())
    else:
        uf = ProjectForm()

        return render_to_response('web/project_add.html', locals())
Exemple #5
0
def project_delete(request, project_id):
    status = check_auth(request, "del_project")
    if not status:
        logger.error('%s: can not run delete project', request.user.first_name)
        return render_to_response('default/error_auth.html', locals())
    try:
        project_name = projectDetailServices.list_project_detail_by_id(
            project_id).project_name
        project_name_str = project_name.encode("utf-8")
        projectDetailServices.delete_logic_by_id(project_id)
        projectServices.delete_logic_by_name(project_name_str)
        logger.error('%s: Delete project %s', request.user.first_name,
                     project_name)
    except Exception as e:
        logger.error('%s: Delete error: %s ', request.user.first_name, e)
    return HttpResponseRedirect('/project/list/')
Exemple #6
0
def check_project(request):
    status = check_auth(request, "add_project")
    if not status:
        logger.error('%s: Do not have enough  power to check_out project',
                     request.user.first_name)
        return render_to_response('default/error_auth.html', locals())

    data = request.POST
    dict1 = {
        'project_version': '',
        'project_name': '',
        'status': '',
        'war_path': ''
    }
    # reckon the md5 of the project
    svn_addr = data['svn_address']
    svn_addr_str = svn_addr.encode("utf-8").strip()
    if svn_addr_str.strip().endswith('/'):
        project_name = svn_addr_str[0:-1].split('/')[-1]
    else:
        project_name = svn_addr_str.split('/')[-1]
    check_path = '/projects/%s' % project_name

    # check out the new repository
    try:
        svn_info = handle.SvnInfo(svn_addr, check_path, 'test1', 123456)
        svn_info.setlocale()
        svn_dir = os.path.exists(svn_info.out_path + '/.svn')
        if not svn_dir:
            os.system('mkdir %s -p' % svn_info.out_path)
            svn_info.checkout_file()
        # get project name,version and return ajax
        check_result = version_operation.VersionOperation()
        version, war_path = check_result.first_get_version(check_path)
        dict1['status'] = 0
        dict1['project_name'] = project_name
        dict1['project_version'] = version
        dict1['war_path'] = war_path
    except Exception as e:
        logger.error('%s: Can not check the project to new repo: %s',
                     request.user.first_name, e)
    else:
        return JsonResponse(dict1)
Exemple #7
0
def project_delete_batch(request):
    status = check_auth(request, "administrator")
    if not status:
        logger.error('%s: Do not have enough  power to delete project batch.',
                     request.user.first_name)
        return render_to_response('default/error_auth.html', locals())

    ids = str(request.POST.get('ids'))
    for id in ids.split(','):
        project_name = projectDetailServices.list_project_detail_by_id(
            id).project_name
        project_name_str = project_name.encode("utf-8")
        try:
            projectDetailServices.delete_logic_by_id(id)
            projectServices.delete_logic_by_name(project_name_str)
            logger.warn('%s: delete project %s success',
                        request.user.first_name, project_name)
        except Exception as e:
            logger.error('%s: Cant delete project batch:%s',
                         request.user.first_name, e)
    return HttpResponseRedirect('/project/list/')
Exemple #8
0
def project_search(request):
    """
    条件搜索项目
    :param request:
    :return: result of condition
    """
    status = check_auth(request, "select_project")
    if not status:
        return render_to_response('default/error_auth.html', locals())

    results = []
    status = request.GET.get('change_status', '')
    keyword = request.GET.get('keyword', '')
    s_url_split = request.get_full_path().split('&')
    s_url_split.pop()
    s_url = '&'.join(s_url_split)

    if status:
        status = int(status)
    else:
        status = ""
    if keyword:
        project_list = projectDetailServices.list_project_by_keyword(keyword)
    else:
        project_list = projectDetailServices.list_all_projects()
    project_count = project_list.count()
    count = {'count': project_count}
    for item in project_list:  # 迭代出单个的queryset
        version_list = []
        res = {
            'id': '',
            'version': '',
            'state': '',
            'name': '',
            'create_time': ''
        }

        project_name = item.project_name  # 取出该queryset的单个值
        # list the version queryset
        try:
            project_version = projectServices.list_all_versions(
                project_name)  # 根据之前的结果进行查询,结果是多个对象的queryset
            # state和create_time取最小的版本做为默认显示
            if project_version:
                version_state = project_version[0].state
                version_create_time = project_version[0].create_time
            else:
                version_state = ''
                version_create_time = ''
            for i in project_version:
                version_list.append(i.version)  # 取值放入列表
            res['id'] = item.id
            res['name'] = item.project_name
            res['version'] = version_list
            res['state'] = version_state
            res['create_time'] = version_create_time
            search = 1
            results.append(res)
            result_list, paginator, objects, page_range, current_page, show_first, show_end = pages.listing(
                results, request, 2)
        except Exception as e:
            logger.log('%s: Can not get version in search: %s',
                       request.user.first_name, e)
    if 'page' in request.get_full_path():
        return render_to_response('web/list_projects.html', locals())
    else:  # restful framework api test
        return render_to_response('web/project_list_search.html', locals())