Ejemplo n.º 1
0
def foo_list(request):
    result = None
    if request.GET:
        rows = None
        pageNo = None
        try:
            rows = int(request.GET[PageUtil.JQGRID_ROWS]) # 详细显示的记录,默认对应jqGrid中配置的rowNum
        except ValueError:
            rows = PageUtil.PAGE_NUM

        try:
            pageNo = int(request.GET[PageUtil.JQGRID_PAGE])
        except ValueError:
            pageNo = PageUtil.PAGE_NO

        sortname = str(request.GET[PageUtil.JQGRID_SORT_NAME]) # 排序字段
        sortorder = str(request.GET[PageUtil.JQGRID_SORT_ORDER])    # 排序方式
        if sortorder and sortorder.upper() == "DESC":
            sortname = "-" + sortname

        foos = Foo.objects.all().order_by(sortname)

        pageHelper = PageHelper(foos, rows, pageNo)
        result = pageHelper.getPaginatorJson()

    return HttpResponse(result, mimetype="application/javascript")
Ejemplo n.º 2
0
def requirement_list(request):
    """
    需求列表查询页面:
    GET:进入requirement_list页面
    POST:分页查询数据
    """
    if request.method == "GET":
        return render_to_response("admin/wc/requirement_list.html", context_instance=RequestContext(request))
    else:
        rows = None
        pageNo = None
        try:
            rows = int(request.POST.get(PageUtil.JQGRID_ROWS)) # 详细显示的记录,默认对应jqGrid中配置的rowNum
        except:
            rows = PageUtil.PAGE_NUM

        try:
            pageNo = int(request.POST.get(PageUtil.JQGRID_PAGE))
        except:
            pageNo = PageUtil.PAGE_NO

        try:
            sortname = str(request.POST.get(PageUtil.JQGRID_SORT_NAME)) # 排序字段
            sortorder = str(request.POST.get(PageUtil.JQGRID_SORT_ORDER))    # 排序方式
            if sortorder and sortorder.upper() == "DESC":
                sortname = "-" + sortname
        except:
            sortname = None

        # 查询条件
        searchDict = {}
        for field in Requirement._meta.fields:
            if request.POST.get(field.name):
                fieldValue = request.POST.get(field.name)
                if isinstance(field, DateField) or isinstance(field, DateTimeField):
                    fieldValue = datetime.datetime.strptime(fieldValue, "%Y-%m-%d")
                    searchDict[field.name + '__range'] = (
                        datetime.datetime.combine(fieldValue, datetime.time.min),
                        datetime.datetime.combine(fieldValue, datetime.time.max))
                else:
                    searchDict[field.name + '__icontains'] = fieldValue

        if sortname:
            requirements = Requirement.objects.filter(**searchDict).order_by(sortname)
        else:
            requirements = Requirement.objects.filter(**searchDict)

        pageHelper = PageHelper(requirements, rows, pageNo)
        result = pageHelper.getPaginatorJson()
        return HttpResponse(result, mimetype="application/javascript")