Exemplo n.º 1
0
def get_filter_objs(request, admin_class):
    filter_conditions = {}
    query = ""
    for k, v in request.GET.items():
        if k == '_page':
            continue
        if k == '_query':
            query = v
            continue
        if k not in admin_class.list_filter:
            continue
        if v:
            filter_conditions[k] = v

    # 搜索处理模块
    search_fields = admin_class.search_fields
    q1 = Q()
    q1.connector = "OR"
    for field in search_fields:
        para = "%s__icontains" % field
        q1.children.append((para, query))

    # 分页时携带get参数处理
    filter_conditions_str = ""
    for k, v in filter_conditions.items():
        filter_conditions_str += "&%s=%s" % (k, v)
    filter_conditions_str += "&_query=%s" % query

    all_count = admin_class.model.objects.filter(q1, **filter_conditions).count()
    page_info = PageInfo(request.GET.get('_page'), 3, all_count, request.path_info, page_range=7, filter_conditions_str=filter_conditions_str)
    query_sets = admin_class.model.objects.filter(q1, **filter_conditions)[page_info.start():page_info.end()]

    return query_sets, filter_conditions, page_info, query
Exemplo n.º 2
0
 def post(self, request, shebei_type, page):
     seacher_text = request.POST.get('search_text')
     v = B_Taizhang.objects.filter(
         Q(device_name__contains=seacher_text)
         | Q(device_model__contains=seacher_text)
         | Q(device_range__contains=seacher_text)
         | Q(device_precision__contains=seacher_text)
         | Q(manufacturer__contains=seacher_text)
         | Q(Commissioning_date__contains=seacher_text)
         | Q(device_number__contains=seacher_text)
         | Q(device_factory_number__contains=seacher_text)
         | Q(calibration_department__contains=seacher_text)
         | Q(calibration_cycle__contains=seacher_text)
         | Q(calibration_time__contains=seacher_text)
         | Q(expire_time__contains=seacher_text)
         | Q(device_type__contains=seacher_text)
         | Q(device_user_department__contains=seacher_text)
         | Q(node__contains=seacher_text))
     page_info = PageInfo(page, v.count(), 12, '/equipment_parameter/', 11)
     class_list = v[page_info.start():page_info.end()]
     return render(
         request, 'shebei_guanli/shebei_index.html', {
             'dates': class_list,
             'page_info': page_info,
             'ig': 1,
             'seacher_text': seacher_text
         })
Exemplo n.º 3
0
def index(request,*args,**kwargs):#取url中的typeid
    if request.method=='GET':
        type_id = int(kwargs.get('type_id')) if kwargs.get('type_id') else None
        #后台都是get传参
        if type_id:
            # article_list = models.Article.objects.filter(article_type_id=type_id).values('blog__user__username','title','summary','read_count','comment_count','create_time')
            article_list = models.Article.objects.filter(article_type_id=type_id).extra(select={'c': "strftime('%%Y-%%m',create_time)"})
        else:
            article_list = models.Article.objects.all().extra(select={'c': "strftime('%%Y-%%m',create_time)"})
        type_choice_list = models.Article.type_choices#分类的
        # print(type_choice_list)#[(1, 'Python'), (2, 'Linux'), (3, 'OpenStack'), (4, 'GoLang')]
        count=article_list.count()#分页
        from utils.page import PageInfo
        # 获取当前URL
        # print(request.path_info)
        page_info = PageInfo(request.GET.get('page'), count, 5, request.path_info, 11)
        rel_article_list=article_list[page_info.start():page_info.end()]
        return render(request,'index.html',{'type_choice_list':type_choice_list,'type_id':type_id,'article_list':rel_article_list,
                                            'page_info':page_info})
    else:
        import json
        ret = {'status': True}
        try:
            del request.session['username']
        except:
            ret['status']=False
        return HttpResponse(json.dumps(ret))
Exemplo n.º 4
0
def news(request):
    all_count = models.News.objects.all().count()
    page_info = PageInfo(request.GET.get("p"), 3, all_count, request.path_info)
    news_list = models.News.objects.all()[page_info.start():page_info.end()]
    return render(request, "news.html", {
        "news_list": news_list,
        "page_info": page_info
    })
Exemplo n.º 5
0
def users2(request):
    all_count = models.UserInfo.objects.all().count()

    page_info = PageInfo(request.GET.get('p'),10,all_count,request.path_info)

    user_list = models.UserInfo.objects.all()[page_info.start():page_info.end()]


    return render(request,'users2.html',{'user_list':user_list,'page_info': page_info})
Exemplo n.º 6
0
def users(request):
    v = request.session.get('user')
    if v:
        all_count = models.HostList.objects.all().count()
        page_info = PageInfo(request.GET.get('p'),10,all_count,request.path_info)
        host_list = models.HostList.objects.all()[page_info.start():page_info.end()]
        return render(request,"users2.html",{"host_list":host_list,"page_info":page_info})
    else:
        return redirect("/login/")
Exemplo n.º 7
0
 def get(self,request,*args,**kwargs):
     all_count=models.HostInfo.objects.all().count()
     # 设置显示6页
     page_info=PageInfo(request.GET.get("p"),6,all_count,request.path_info)
     all_host_list = models.HostInfo.objects.all()[page_info.start():page_info.end()]
     all_bus_list = models.BusinessInfo.objects.all()
     return render(request,'hosts.html',{'all_host_list':all_host_list,
                                         "page_info":page_info,
                                         'all_bus_list':all_bus_list})
Exemplo n.º 8
0
def chouti(request):
    v = request.session.get('user')
    if v:
        all_count = models.News.objects.all().count()
        page_info = PageInfo(request.GET.get('p'), 10, all_count,
                             request.path_info)
        all_list = models.News.objects.all()[page_info.start():page_info.end()]
        return render(request, "chouti.html", {
            "all_list": all_list,
            "page_info": page_info
        })
    else:
        return redirect("/login/")
Exemplo n.º 9
0
def users2(request):
    all_count = models.UserInfo.objects.all().count()

    page_info = PageInfo(request.GET.get('p'), 10, all_count,
                         request.path_info)

    # 主动进行跨表查询
    user_list = models.UserInfo.objects.all().select_related('ut').order_by(
        '-id')[page_info.start():page_info.end()]
    # [obj,obj]

    return render(request, 'users2.html', {
        'user_list': user_list,
        'page_info': page_info
    })
Exemplo n.º 10
0
def index(request, u):
    user_obj = User_msg.objects.get(username=u)
    # order_by 排序   , FK查询时使用select_related,连表查询
    host_obj = user_obj.u_h.all().select_related('lob').order_by('id')
    all_count = host_obj.count()
    page_info = PageInfo(request.GET.get('p'), 10, all_count,
                         request.path_info)

    host_list = host_obj[page_info.start():page_info.end()]
    # print(host_l)
    return render(request, 'index.html', {
        'username': u,
        'host_l': host_list,
        'page_info': page_info,
    })
Exemplo n.º 11
0
def app(request):
    page_info = PageInfo(request.GET.get('p'),
                         6,
                         100,
                         request.path_info,
                         page_range=7)
    return render(request, 'index.html', locals())
Exemplo n.º 12
0
def obj_list(request, app_name, model_name):
    if request.GET.get("page_num"):
        request.session['page_num'] = int(request.GET.get("page_num"))
    elif request.session.get("page_num"):
        pass
    else:
        request.session['page_num'] = 1

    if app_name in site.registered_admins:                  # 是否有 repository应用
        if model_name in site.registered_admins[app_name]:  # 是否有 course models
            admin_class = site.registered_admins[app_name][model_name]  # 获取 具体models的实例
            querysets,filter_condtions,page_filter = get_filter_objs(request,admin_class)

            # 字段排序
            order = request.GET.get("order")
            if order:
                querysets = querysets.order_by(order)
            current_page = request.GET.get("page")

            print("page_filter=======",page_filter)
            page_info = PageInfo(current_page,
                                 request.session['page_num'],
                                 len(querysets),
                                 request.path,
                                 filter=page_filter)
            querysets = querysets[page_info.start:page_info.end]

            return render(request, "crm_admin/obj_list.html", locals())
Exemplo n.º 13
0
def lob(request, u):
    add_form_obj = AddForm()
    edit_form_obj = EditForm()
    user_obj = User_msg.objects.get(username=u)
    host_obj = user_obj.u_h.all().select_related('lob').order_by('id')
    all_count = host_obj.count()
    page_info = PageInfo(request.GET.get('p'), 10, all_count,
                         request.path_info)
    host_list = host_obj[page_info.start():page_info.end()]
    return render(
        request, 'lob.html', {
            'lob_l': host_list,
            'page_info': page_info,
            'add_form_obj': add_form_obj,
            'edit_form_obj': edit_form_obj,
        })
Exemplo n.º 14
0
 def page(self):
     """分页"""
     obj_list,filter_condtions = self.filter()
     current_page = self.request.GET.get("p")
     base_url = self.request.path_info
     print("====>>>>", base_url)
     page_info = PageInfo(current_page, 5, len(obj_list), base_url, filter=filter_condtions)
     obj_list = obj_list[page_info.start:page_info.end]
Exemplo n.º 15
0
 def get(self, request, shebei_type, page):
     page_info = PageInfo(page,
                          B_Taizhang.objects.all().count(), 12,
                          '/equipment_parameter/', 11)
     if shebei_type == 'A':
         class_list = A_Taizhang.objects.all()[page_info.start():page_info.
                                               end()]
     elif shebei_type == 'B':
         class_list = B_Taizhang.objects.all()[page_info.start():page_info.
                                               end()]
     elif shebei_type == 'C':
         class_list = C_Taizhang.objects.all()[page_info.start():page_info.
                                               end()]
     return render(
         request, 'shebei_guanli/shebei_index.html', {
             'dates': class_list,
             'page_info': page_info,
             'shebei_type': shebei_type
         })
Exemplo n.º 16
0
def index(request):
    try:
        if request.session['user_info']:
            avatar = UserInfo.objects.filter(
                username=request.session['user_info']['user_name']).values(
                    'img')[0]
    except KeyError as e:
        pass

    all_count = News.objects.all().count()
    page_info = PageInfo(request.GET.get('p'),
                         6,
                         all_count,
                         request.path_info,
                         page_range=3)
    objs = News.objects.filter().order_by('-nid').prefetch_related(
        'user_info', 'news_type')[page_info.start():page_info.end()]

    return render(request, 'index.html', locals())
Exemplo n.º 17
0
def model_detail(request, app_name, model_name):
    if app_name in site.registered_admins:  # 是否有 repository应用
        if model_name in site.registered_admins[app_name]:  # 是否有 course models
            admin_class = site.registered_admins[app_name][
                model_name]  # 获取 具体models的实例
            querysets, filter_condtions, page_filter = get_filter_objs(
                request, admin_class)
            current_page = request.GET.get("page")
            print("page_filter=======", page_filter)
            page_info = PageInfo(current_page,
                                 5,
                                 len(querysets),
                                 request.path,
                                 filter=page_filter)
            querysets = querysets[page_info.start:page_info.end]
            return render(request, "repository/obj_list.html", locals())
Exemplo n.º 18
0
def back(req):
    #接下来开始编写后台页面
    all_count = models.Book.objects.all().count()
    page_info = PageInfo(req.GET.get('p'), 5, all_count, req.path_info)
    all_book_list = models.Book.objects.all()[page_info.start():page_info.end()]
    return render(req, 'backend.html', {'all_book_list': all_book_list, 'page_info': page_info})