Example #1
0
def host(request):

    # #首先获取cookie上的值
    # v = request.COOKIES.get('username1')
    # #如果cookie不存在,直接跳转到login登陆页面,如果cookie存在,即跳转到host页面
    # if not v:
    # 	return redirect('/login/')

    #session中获取数据
    #直接用request.session['is_login']时,当去不到值时,host刷新会报错,所以要用request.session.get('is_login')
    # 如果is_login不存在则返回登陆页面
    if not request.session.get('is_login'):
        return redirect('/login/')
    # 如果is_login存在继续
    elif request.session.get('is_login'):
        if request.method == 'GET':
            #对象
            v1 = models.Host.objects.all()
            b_list = models.Business.objects.all()
            #分页
            t = models.Host.objects.all().count()
            LIST = []
            for i in range(1, int(t) + 1):
                LIST.append(i)
            current_page = request.GET.get('p', 1)
            current_page = int(current_page)
            val = request.COOKIES.get('per_page_count')
            if not val:
                page_obj = pagination.Page(current_page, len(LIST))
            else:
                val = int(val)
                page_obj = pagination.Page(current_page, len(LIST), val)

            data = v1[page_obj.start:page_obj.end]
            page_str = page_obj.page_str('/host/')
            # return render(request,'host.html',{'current_user': v,'page_str':page_str,'data':data,'b_list':b_list})
            return render(request, 'host.html', {
                'page_str': page_str,
                'data': data,
                'b_list': b_list
            })

        elif request.method == 'POST':
            h = request.POST.get('hostname')
            i = request.POST.get('ip')
            p = request.POST.get('port')
            b = request.POST.get('b_id')
            models.Host.objects.create(
                hostname=h,
                ip=i,
                port=p,
                b_id=b,
            )
            # return render(request, 'host.html', {'current_user': v})
            return redirect('/host/')
Example #2
0
def users(request):
    """查询所有用户信息"""
    # user_list = UserInfo.objects.all()
    # return render(request, 'rbac/users.html', {'user_list': user_list})
    page = request.GET.get('page')
    current_page = 1
    if page:
        current_page = int(page)
    search_fl = request.GET.get('fl')
    search_fn = request.GET.get('fn')
    if search_fl:
        search_fl = search_fl
    else:
        search_fl = ''
    if search_fn:
        search_fn = search_fn
    else:
        search_fn = ''
    try:
        if search_fl!='':
            user_info = models.UserInfo.objects.filter(username__startswith=search_fl.lower()).order_by('id')[::-1]
            page_obj = pagination.Page(current_page, len(user_info), 10, 9)
            data = user_info[page_obj.start:page_obj.end]
            page_str = page_obj.page_str("/rbac/users/?fl=%s&page=" % search_fl.lower())
        elif search_fn!='':
            user_info = models.UserInfo.objects.filter(username__contains=search_fn).all()
            page_obj = pagination.Page(current_page, len(user_info), 10, 9)
            data = user_info[page_obj.start:page_obj.end]
            page_str = page_obj.page_str("/rbac/users/?fn=%s&page=" % search_fn)
        else:
            user_info = models.UserInfo.objects.all().order_by('id')[::-1]
            page_obj = pagination.Page(current_page, len(user_info), 10, 9)
            data = user_info[page_obj.start:page_obj.end]
            page_str = page_obj.page_str("/rbac/users/?page=")
        first_letter=list()
        user_name_info = models.UserInfo.objects.all().order_by('id')[::-1]
        for item in user_name_info:
            if item.username[0].upper() not in first_letter:
                first_letter.append(item.username[0].upper())
        first_letter=sorted(first_letter)

        none_limit=list()
        for user_role in user_name_info:
            if user_role.roles.all().count()==0:
                none_limit.append(user_role.username)

    except Exception as e:
        print(e)
        pass
    return render(request, 'rbac/user_control.html', {'li': data, 'page_str': page_str,'first_letter':first_letter,'none_limit_num':len(none_limit),'none_limit':none_limit})
Example #3
0
def lizhiResDetail_bak(request, task_id):
    qf_sg_ft_sg, qf_sg_ft_bd, qf_bd_ft_sg, qf_bd_ft_bd, sg_count, bd_count = get_static_summary(task_id)

    allResult = models.ResultDetail.objects.filter(task_id=task_id)

    # 适用于结果筛选异步post刷新
    # return render(request, 'lizhi/lizhi_res_detail_bak.html',
    #               {'qf_sg_ft_sg': qf_sg_ft_sg, 'qf_sg_ft_bd': qf_sg_ft_bd,
    #                'qf_bd_ft_sg': qf_bd_ft_sg, 'qf_bd_ft_bd': qf_bd_ft_bd,
    #                'sg_count':sg_count , 'bd_count':bd_count, 'all_res':allResult})


    if request.method == 'GET':
        page_id = request.GET.get('page', '')
        if page_id == '':
            current_page = 1
        else:
            current_page = int(page_id)

        page_obj = pagination.Page(current_page, len(allResult), 50, 10)
        data = allResult[page_obj.start:page_obj.end]
        page_str = page_obj.page_str("/lizhi/result/result_detail_" + task_id + ".html?page=")

        return render(request, 'lizhi/lizhi_res_detail_bak2.html',
                      {'qf_sg_ft_sg': qf_sg_ft_sg, 'qf_sg_ft_bd': qf_sg_ft_bd,
                       'qf_bd_ft_sg': qf_bd_ft_sg, 'qf_bd_ft_bd': qf_bd_ft_bd,
                       'sg_count': sg_count, 'bd_count': bd_count, 'all_res': data,
                       'page_str': page_str})
Example #4
0
def article(request):
    """
    博主个人文章管理
    :param request:
    :return:
    """

    if request.method == "GET":
        article_objs = models.Article.objects.filter(
            blog_id=request.session.get("blog_id")).order_by("-nid")
        #分页
        current_page = request.GET.get('p', 1)
        current_page = int(current_page)
        val = request.COOKIES.get('per_page_count', 10)
        val = int(val)
        page_obj = pagination.Page(current_page=current_page,
                                   data_count=len(article_objs),
                                   per_page_count=val)
        data = article_objs[page_obj.start:page_obj.end]
        page_str = page_obj.page_str(reverse("article"))
        article_type_objs = models.Article.type_choices
        tag_objs = models.Tag.objects.filter(
            blog_id=request.session.get("blog_id"))
        category_objs = models.Category.objects.filter(
            blog_id=request.session.get("blog_id"))
        article_dict = {"article_type": 0, "category_id": 0, "tags_id": 0}
        return render(
            request, 'backend_article.html', {
                "article_objs": data,
                "page_str": page_str,
                "tag_objs": tag_objs,
                "category_objs": category_objs,
                "article_type_objs": article_type_objs,
                "article_dict": article_dict,
            })
Example #5
0
def host(request):
    if request.method == "GET":
        current_page = int(request.GET.get('p', 1))
        val = int(request.COOKIES.get('per_page_count', 10))
        v4 = models.Host.objects.filter(nid__gt=0)
        page_obj = pagination.Page(current_page, len(v4), val)
        data = v4[page_obj.start:page_obj.end]
        page_str = page_obj.page_str("/novel/host/")
        # v1 = models.Host.objects.filter(nid__gt=0).values('ip','port','bi__caption')
        # print(v1)
        # for row in v1:
        #     print(row.nid,row.hostname,row.ip,row.port,row.bi_id,row.bi.caption)
        # print(row['ip'],row['port'],row['bi__caption'])
        v2 = models.ChapterCopy.objects.using('dbnovel').filter(novelid__lt=2)
        v3 = models.Bussiness.objects.all()
        return render(request, 'novel/host.html', {
            "v1": data,
            "v2": v2,
            "v3": v3,
            'page_str': page_str
        })

    elif request.method == "POST":
        hostname = request.POST.get("hostname")
        ipname = request.POST.get("ipname")
        portname = request.POST.get("portname")
        bu_id = request.POST.get("bu_id")
        models.Host.objects.create(hostname=hostname,
                                   ip=ipname,
                                   port=portname,
                                   bi_id=bu_id)
        return redirect('/novel/host')
Example #6
0
def fy_autodiff(request):
    # user_id = 'zhangjingjun'
    user_id = request.COOKIES.get('uid')
    page = request.GET.get('page')
    current_page=1
    if page:
        current_page = int(page)

    try:
        task_list = models.FyDiff.objects.order_by('id')[::-1]
        page_obj = pagination.Page(current_page, len(task_list), 16, 9)
        data = task_list[page_obj.start:page_obj.end]
        page_str = page_obj.page_str("/fy_autodiff?page=")

        business_lst = models.Business.objects.all()
        app_lst = models.Application.objects.all()
        user_app_lst = models.UserToApp.objects.filter(user_name_id=user_id)
        app_id_lst = list()
        for appid in user_app_lst:
            app_id_lst.append(appid.app_id_id)
    except Exception as e:
        print(e)
        pass
    if 17 in app_id_lst:
        return render(request, 'fy_autodiff.html',
                      {'business_lst': business_lst, 'user_id': user_id, 'user_app_lst': user_app_lst,
                       'app_lst': app_lst, 'businame': 'Translate', 'app_name': "翻译效果对比",'li': data,
                       'page_str': page_str})
    else:
        return render(request, 'no_limit.html',
                      {'business_lst': business_lst, 'user_id': user_id, 'user_app_lst': user_app_lst,
                       'app_lst': app_lst, 'businame': 'Translate', 'app_name': "翻译效果对比"})
Example #7
0
def auto_detail(request, task_id):
    # user_id = "gongyanli"
    user_id = request.COOKIES.get('uid')
    task_detail = models.Qps.objects.filter(id=task_id)
    diff_detail = models.Diff.objects.filter(diff_fk_id=task_id)

    testitem = models.Qps.objects.filter(id=task_id).values('testitem')

    page = request.GET.get('page')
    current_page = 1
    if page:
        current_page = int(page)

    if testitem.first()['testitem'] == 1:

        return render(request, 'webqo/auto_detail.html', {
            'user_id': user_id,
            'task_detail': task_detail
        })
    elif testitem.first()['testitem'] == 0:
        page_obj = pagination.Page(current_page, len(diff_detail), 3, 9)
        data = diff_detail[page_obj.start:page_obj.end]
        page_str = page_obj.page_str('auto_detail_' + task_id + '.html?page=')

        return render(
            request, 'webqo/diff_detail.html', {
                'user_id': user_id,
                'task_detail': task_detail,
                'diff_detail': diff_detail,
                'li': data,
                'page_str': page_str
            })
Example #8
0
def mine(request):
    current_page = request.GET.get('p', 1)
    current_page = int(current_page)
    page_obj = pagination.Page(current_page, len(LIST))
    data = LIST[page_obj.start:page_obj.end]
    page_str = page_obj.page_str('/mine.html')
    return render(request, 'mine.html', {'data': data, 'page_str': page_str})
Example #9
0
def serverhost_list(request):
    if request.method == "GET":
        user_id = request.session.get("user_id")
        user_obj = models.User.objects.filter(id=user_id).first()
        host_list = user_obj.serverhost_set.all()
        host_num = host_list.count()
        """
        反向查询:xxxx_set  xxxx:表名
		 v = models.UserGroup.objects.filter(uid=1).first()
        for user in v.userinfo_set.all():
            print(user.username)
       """
    elif request.method == "POST":
        host_list = []
        host_num = []
        project = request.POST.get("project")
        try:
            project_obj = models.Project.objects.get(name=project)
            host_list = project_obj.serverhost_set.all()
            host_num = host_list.count()
        except Exception as e:
            print(e)

    current_page = int(request.GET.get("Page", 1))  # 获取用户get请求的页码数
    select_current_page = int(request.COOKIES.get("per_page_count", 13))  # 获取当前页面cookie记录的显示条数,默认是10
    # select_current_page=10
    page_obj = pagination.Page(current_page, len(host_list),select_current_page)  # 创建page_obj对象  per_page_count=10,page_num=7是变量,可改动
    host_list = host_list[page_obj.start_count:page_obj.end_count]  # 每页显示数据条数列表
    page_list = page_obj.page_str("super_cmdb/serverhost_list/")  # 分页的所有内容

    return render(request, 'super_cmdb/serverhost_list.html',{"host_list":host_list,"page_list":page_list,"host_num":host_num})
Example #10
0
def test(request):
    current_page = request.GET.get('p', 1)
    current_page = int(current_page)
    page_obj = pagination.Page(current_page, len(li))
    data = li[0:3]
    page_str = page_obj.page_str('/cmdb/index/')
    return render(request, "test.html", {'page_str': page_str})
Example #11
0
def modelbox(request):
    v = request.COOKIES.get('username_cookie')
    if not v:
        return redirect('/cmdb/login/')
    else:
        current_page = request.GET.get('p', 1)
        current_page = int(current_page)
        val = request.COOKIES.get('per_page_count', 10)
        val = int(val)

        db = pymysql.connect("192.168.100.198", "django", "123456", "django")
        # cursor = db.cursor()
        cursor = db.cursor(pymysql.cursors.DictCursor)
        cursor.execute("SELECT COUNT(*) FROM user")
        data_count = cursor.fetchone()
        count = data_count['COUNT(*)']

        page_obj = pagination.Page(current_page, count, val)


        cursor.execute("select * from user limit %s, %s" %(page_obj.start, page_obj.end))
        print(page_obj.start,page_obj.end)

        data = cursor.fetchall()

        page_str = page_obj.page_str("/cmdb/modelbox/")

        cursor.close()
        db.close()
    return render(request, 'modelbox.html',{'data_list': data, 'page_str': page_str})
Example #12
0
def man_eval_detail(request):
    # user_id="zhangjingjun"
    user_id = request.COOKIES.get('uid')
    task_id = request.GET.get('tasknum')
    page = request.GET.get('page')
    current_page = 1
    if page:
        current_page = int(page)
    task_detail = models.ManEval.objects.filter(id=task_id).first()
    task_diff_detail = models.ManEvalDiff.objects.filter(
        diff_task_id=task_id).order_by('id')[::-1]
    page_obj = pagination.Page(current_page, len(task_diff_detail), 4, 9)
    data = task_diff_detail[page_obj.start:page_obj.end]
    page_str = page_obj.page_str("/man_eval/detail/?tasknum=" + task_id +
                                 '&page=')
    hubsvn = str_unix2br(task_detail.hubsvn)
    sersvn = str_unix2br(task_detail.sersvn)
    loginfo = str_unix2br(task_detail.errorlog)
    return render(
        request, 'fanyi/man_eval_detail.html', {
            'user_id': user_id,
            'task_detail': task_detail,
            'hubsvn': hubsvn,
            'sersvn': sersvn,
            'loginfo': loginfo,
            'li': data,
            'page_str': page_str
        })
Example #13
0
def nvidia_smi(request,task_id='',page_id=1):
    # user_id = 'zhangjingjun'
    user_id = request.COOKIES.get('uid')
    if page_id == '':
        page_id=1
    try:
        business_lst = models.Business.objects.all()
        app_lst = models.Application.objects.all()
        req_lst = models.ReqInfo.objects.filter(user_fk_id=user_id)
        user_app_lst = models.UserToApp.objects.filter(user_name_id=user_id)
        if task_id=='':
            gpu_info = models.FyMonitor.objects.all().values('id','create_time', 'end_time', 'monitorip', 'user', 'status').order_by('id')[::-1]
        else:
            gpu_info = models.FyMonitor.objects.filter(h_id=task_id).values('id', 'create_time', 'end_time', 'monitorip', 'user',
                                                             'status').order_by('id')[::-1]
        current_page = page_id
        current_page = int(current_page)
        page_obj = pagination.Page(current_page, len(gpu_info), 15, 9)
        data = gpu_info[page_obj.start:page_obj.end]
        page_str = page_obj.page_str("/nvidia_smi_%s_" % task_id)
        host_list = models.Host.objects.all()

        app_id_lst = list()
        for appid in user_app_lst:
            app_id_lst.append(appid.app_id_id)
    except Exception as e:
        print(e)
    if 11 in app_id_lst:
        return render(request, 'fy_nvi_smi.html',
                      {'business_lst': business_lst, 'user_id': user_id, 'user_app_lst': user_app_lst,
                       'req_lst': req_lst, 'app_lst': app_lst, 'businame': 'Translate', 'app_name': "翻译比比看",'gpu_info':gpu_info,'host_list':host_list,'li':data,'page_str':page_str})
    else:
        return render(request, 'no_limit.html',
                      {'business_lst': business_lst, 'user_id': user_id, 'user_app_lst': user_app_lst,
                       'req_lst': req_lst, 'app_lst': app_lst, 'businame': 'Translate', 'app_name': "翻译比比看"})
Example #14
0
    def get(self, request, *args, **kwargs):
        # data = models.Asset.objects.all()
        # data_status = models.Asset.device_status_choices
        # print(data_status)
        data = models.VirtualMachines.objects.all().order_by('-id')
        host = models.HostMachines.objects.all()
        machine_type = models.MachineType.objects.all()

        # data_total = models.Asset.objects.all().count()
        data_total = models.VirtualMachines.objects.all().count()
        current_page = request.GET.get('p', 1)
        current_page = int(current_page)
        # print(current_page)

        val = request.COOKIES.get('per_page_count', 1000)
        page_init = {}
        page_init['per_page_count'] = val
        # print(val)
        val = int(val)

        page_obj = pagination.Page(current_page, data_total, val)
        data = data[page_obj.start:page_obj.end]
        page_str = page_obj.page_str('virtual_list.html')

        return render(
            request, 'virtual_list.html', {
                'data': data,
                'host_list': host,
                'machine_type': machine_type,
                'page_str': page_str,
                'page_init': page_init
            })
Example #15
0
def blog(request):  # 所有博客
    username = request.session.get('username')
    wd = request.GET.get('wd')  # 搜索框

    # blog_set = Blog.objects.all().order_by('-create_data')
    current_page = request.GET.get("p", 1)
    current_page = int(current_page)
    # val = request.COOKIES.get('per_page_count') # 获取每页显示的个数
    val = 9
    li = Blog.objects.all().count()
    page_obj = pagination.Page(current_page, int(li), val)
    if wd:
        data = Blog.objects.filter(title__icontains=wd).order_by(
            '-views')[page_obj.start:page_obj.end]
    else:
        data = Blog.objects.all().order_by(
            '-views')[page_obj.start:page_obj.end]

    page_str = page_obj.page_str("/blog/blog/")
    tag_list = Tag.objects.all()[:7]
    return render(
        request, "blog/blog.html", {
            "blog_set": data,
            "page_str": page_str,
            'tag_list': tag_list,
            'username': username
        })
Example #16
0
def user_list(request):
    current_page = request.GET.get('p',1)
    current_page = int(current_page)
    page_obj = pagination.Page(current_page,len(LIST))
    data = LIST[page_obj.start:page_obj.end]
    page_str = page_obj.page_str('/user_list/')
    return render(request,"user_list.html",{'page_str':page_str,'li':data})
Example #17
0
def user_list(request):
    current_page = request.GET.get('p', 1)
    current_page = int(current_page)
    # 生成对象 @property 把函数变成属性,调用不用加()
    page_obj = pagination.Page(current_page, len(LIST))
    data = LIST[page_obj.start+1:page_obj.end+1]
    page_str = page_obj.page_str('/text/user_list/')
    return render(request, 'user_list.html', {'li': data, 'page_str': page_str})
Example #18
0
def host(request):
    '''主机展示表和添加主机'''
    HOSTS = models.Host.objects.all()  # 全局变量
    if request.method == "GET":
        current_page = request.GET.get(
            'p', 1)  # 如果p不存在,看第1页。每一页显示10个数据 [0-10],[10-20],[20-30]
        current_page = int(current_page)  # GET获取到的都是字符串

        val = request.COOKIES.get('per_page_count',
                                  10)  # 从Cookies中拿到当前用户要求一页显示多少数据,默认是10
        val = int(val)
        page_obj = pagination.Page(current_page, len(HOSTS), val)

        data = HOSTS[page_obj.start:page_obj.end]  # 取数据
        data_length = len(data)
        page_str = page_obj.page_str("/host/")

        b_list = models.Business.objects.all()  # 拿到业务线
        e_list = models.EngineRoom.objects.all()  # 拿到机房
        return render(
            request, "host.html", {
                "hosts": data,
                "data_length": data_length,
                "page_str": page_str,
                "b_list": b_list,
                "e_list": e_list,
                'current_user': request.session['username']
            })
    elif request.method == "POST":
        result = {'status': True, 'error': None, 'data': None}
        try:  # 因为这里面的代码有可能出错
            h = request.POST.get('hostname')
            i = request.POST.get('ip')
            b = request.POST.get('b_id')
            e = request.POST.get('e_id')
            print(h)
            print(i)
            if h:
                pass
                if i and is_valid_ipv4_address(i):
                    # new_host = models.Host(hostname=h,ip=i,b_id=b,e_id=e)
                    # new_host.save() #这两句和下面那句等效
                    models.Host.objects.create(hostname=h,
                                               ip=i,
                                               b_id=b,
                                               e_id=e)
                else:
                    result['status'] = False
                    result['error'] = "IP地址格式有误"
            else:
                result['status'] = False
                result['error'] = "请输入主机名"
        except Exception as e:
            result['status'] = False
            result['error'] = '请求错误'

        return HttpResponse(
            json.dumps(result))  # ajax请求返回就写HttpResponse,HttpResponse()里面是字符串
Example #19
0
def interface(request):
    # user_id = 'zhangjingjun'
    user_id = request.COOKIES.get('uid')
    if request.method == 'GET':
        page = request.GET.get('page')
        current_page = 1
        if page:
            current_page = int(page)
        try:
            task_list = models.InterfaceEval.objects.order_by('id')[::-1]
            page_obj = pagination.Page(current_page, len(task_list), 16, 9)
            data = task_list[page_obj.start:page_obj.end]
            page_str = page_obj.page_str("/fanyi/interface?page=")
        except Exception as e:
            print(e)
            pass
        return render(request, 'fanyi/interface.html', {
            'user_id': user_id,
            'li': data,
            'page_str': page_str
        })
    elif request.method == 'POST':
        ret = {'status': True, 'errro': None, 'data': None}
        test_url = str_dos2unix(request.POST.get('test_url'))
        base_url = str_dos2unix(request.POST.get('base_url'))
        reqtype = str_dos2unix(request.POST.get('reqtype'))
        queryip = str_dos2unix(request.POST.get('query_data_ip'))
        queryuser = str_dos2unix(request.POST.get('query_data_user'))
        querypassw = str_dos2unix(request.POST.get('query_data_pass'))
        querypath = str_dos2unix(request.POST.get('query_data_path'))
        testtag = str_dos2unix(request.POST.get('testtag'))

        try:
            a = models.InterfaceEval.objects.create(start_time=get_now_time(),
                                                    user=user_id,
                                                    test_url=test_url,
                                                    base_url=base_url,
                                                    queryip=queryip,
                                                    reqtype=reqtype,
                                                    queryuser=queryuser,
                                                    querypassw=querypassw,
                                                    querypath=querypath,
                                                    testtag=testtag)
            os.system(
                '/root/anaconda3/bin/python3 /search/odin/pypro/webqa/utils/getdiff_byxml.py %d &'
                % a.id)
            #r = get_fanyi_result(a.id)
            #if r != 0:
            #    ret['status'] = False
            #    ret['error'] = 'error:执行失败'
            #    models.InterfaceEval.objects.filter(id=a.id).update(status=3, errlog='start failed')
        except Exception as e:
            traceback.print_exc()
            ret['error'] = 'error:' + str(e)
            ret['status'] = False
        return HttpResponse(json.dumps(ret))
Example #20
0
def project_page(request):
    """项目视图"""
    current_page = request.GET.get("p", 1)
    current_page = int(current_page)
    project_obj_count = models.Project.objects.all().count()
    project_obj_list = models.Project.objects.all()
    page_obj = pagination.Page(current_page, project_obj_count)
    data = project_obj_list[page_obj.start:page_obj.end]
    page_str = page_obj.pager('project.html')
    return render(request, 'project.html', {'data': data, 'page_str': page_str})
Example #21
0
def user_list(request):
    current_page = int(request.GET.get('p', 1))
    page_obj = pagination.Page(current_page, len(LIST))
    data = LIST[page_obj.start:page_obj.end]
    page_str = page_obj.page_str("/user_list/")

    return render(request, 'user_list.html', {
        'li': data,
        'page_str': page_str
    })
Example #22
0
def user_page(request):
    """用户视图"""
    current_page = request.GET.get("p", 1)
    current_page = int(current_page)
    user_obj_count = models.UserProfile.objects.all().count()
    user_obj_list = models.UserProfile.objects.all()
    page_obj = pagination.Page(current_page, user_obj_count)
    data = user_obj_list[page_obj.start:page_obj.end]
    page_str = page_obj.pager('user.html')
    return render(request, 'user.html', {'data': data, 'page_str': page_str})
Example #23
0
def fenye(request):
    current_page = request.GET.get('p', 1)
    current_page = int(current_page)
    page_obj = pagination.Page(current_page, len(LIST))
    data = LIST[page_obj.start:page_obj.end]
    page_str = page_obj.pag_str('/app03/fenye/')
    return render(request, 'app03/fenye.html', {
        'li': data,
        'page_str': page_str
    })
Example #24
0
def index(request):
    current_page = request.GET.get('p', 1)
    current_page = int(current_page)
    page_obj = pagination.Page(current_page, len(li))
    data = li[0:3]
    page_str = page_obj.page_str('/cmdb/index/')
    return render(request, "index.html", {
        'u': user,
        'page_str': page_str,
        'v': data
    })
Example #25
0
def user_list(request):
    current_page=request.GET.get('p',1)
    current_page=int(current_page)

    a=request.COOKIES.get('per_page_count',10)
    a=int(a)
    page_obj=pagination.Page(current_page,len(USER_LIST),a)
    start=page_obj.start
    end=page_obj.end
    data = USER_LIST[start:end]
    count=page_obj.all_count
    page_str=page_obj.page_str('user_list')
    return render(request,'user_list.html',{'user_list':data,'page_str':page_str})
Example #26
0
def auto(request, page_id):
    user_id = "zhangjingjun"
    # user_id = request.COOKIES.get('uid')
    if page_id == '':
        page_id = 1
    task_list = models.Qps.objects.order_by('id')[::-1]
    current_page = page_id
    current_page = int(current_page)
    page_obj = pagination.Page(current_page, len(task_list), 16, 9)
    data = task_list[page_obj.start:page_obj.end]
    page_str = page_obj.page_str("lizhi/auto")

    return render(request, 'lizhi/auto.html',{'user_id': user_id, 'req_lst': data, 'page_str': page_str})
Example #27
0
def page_list(request):
    val = request.COOKIES.get('k1')
    val = int(val)
    print(val)
    current_page = int(request.GET.get('p', 1))
    page_obj = pagination.Page(current_page, len(LIST), val)
    data = LIST[page_obj.start:page_obj.end]
    page_str = page_obj.page_str('page_list')

    return render(request, 'page_list.html', {
        'data': data,
        'page_str': page_str
    })
Example #28
0
def application_page(request):
    """应用视图"""
    current_page = request.GET.get("p", 1)
    current_page = int(current_page)
    application_obj_count = models.Application.objects.all().count()
    application_obj_list = models.Application.objects.all()
    page_obj = pagination.Page(current_page, application_obj_count)
    data = application_obj_list[page_obj.start:page_obj.end]
    page_str = page_obj.pager('application.html')
    return render(request, 'application.html', {
        'data': data,
        'page_str': page_str
    })
Example #29
0
def index(request):
    v = request.COOKIES.get('username111')
    uid = request.COOKIES.get('uid')
    print(v)
    # if v:
    if request.method == 'GET':
        obj = models.UserInfo.objects.filter(username=v).first()
        group_host_list = []
        host_obj = obj.h.all()
        group_obj = obj.g.all()
        for i in host_obj:
            group_host_list.append(i)

        for i in group_obj:
            group_id = i.gid
            obj2 = models.Host.objects.filter(hostgroup_id=group_id)
            for i in obj2:
                group_host_list.append(i)
        LIST = group_host_list
        current_page = request.GET.get('p', 1)  # 1是干嘛的 ==> 第一次请求的时候默认看第一页
        current_page = int(current_page)
        page_obj = pagination.Page(current_page, len(LIST), 5)
        data = LIST[page_obj.start:page_obj.end]
        page_str = page_obj.page_str("/index/")

        return render(
            request, 'index.html', {
                'page_str': page_str,
                'current_user': v,
                'group_host_list': data,
                'group_obj': group_obj
            })

    elif request.method == 'POST':
        gid = request.POST.get('gid')
        hid = request.POST.get('hid')

        try:
            # obj.g.remove(gid)
            obj = models.Host.objects.filter(hid=hid)
            print(obj)  # <QuerySet [<Host: Host object>]>
            obj.update(hostgroup_id=None)
        except Exception as e:
            print('123')
        else:
            obj = models.UserInfo.objects.get(
                id=uid)  # get和filter出来的对象还不一样 666
            print(obj)  # UserInfo object
            obj.h.remove(hid)
        return HttpResponse(123)
Example #30
0
def user_list(request):
    current_page = request.GET.get('p', 1)
    current_page = int(current_page)

    val = request.COOKIES.get('per_page_count')
    val = int(val)
    page_obj = pagination.Page(current_page, len(LIST), val)
    data = LIST[page_obj.start:page_obj.end]

    page_str = page_obj.page_str("/app02/user_list")
    return render(request, 'app02/user_list.html', {
        "li": data,
        "page_str": page_str
    })