Exemplo n.º 1
0
def dataTable(request, key, value, low=None, high=None):
    if not request.is_ajax():
        return __renderErrorJSON__('Expected AJAX')

    if key is None or value is None:
        return __renderErrorJSON__('Missing Key and/or Value')

    if key not in [keys[0] for keys in settings.SEARCH_KEYS]:
        return __renderErrorJSON__('Invalid Key')

    key = urllib.unquote(key)
    value = urllib.unquote(value)

    #TODO Support Post -- need to add cooresponding form
    if request.method == "GET":
        page = int(request.GET.get('iDisplayStart', 0))
        pagesize = int(request.GET.get('iDisplayLength', 50))
        sortcols = int(request.GET.get('iSortingCols', 0))
        sEcho = request.GET.get('sEcho')
        sSearch = request.GET.get('sSearch', '')

        sort = []
        for x in range(sortcols):
            sortTuple = handler.formatSort(
                int(request.GET.get("iSortCol_%d" % x)),
                request.GET.get("sSortDir_%d" % x))
            if sortTuple is not None:
                sort.append(sortTuple)

    else:
        return __renderErrorJSON__('Unsupported Method')

    if (len(sSearch) == 0):
        sSearch = None

    try:
        results = handler.dataTableSearch(key, value, page, pagesize, sort,
                                          sSearch, low, high)
    except Exception as e:
        return __renderErrorJSON__(str(e))

    #Echo back the echo
    results['sEcho'] = sEcho

    return HttpResponse(json.dumps(results), content_type='application/json')
Exemplo n.º 2
0
def dataTable(request, key, value, low = None, high = None):
    if not request.is_ajax():
        return __renderErrorJSON__('Expected AJAX')

    if key is None or value is None:
        return __renderErrorJSON__('Missing Key and/or Value')

    if key not in [keys[0] for keys in settings.SEARCH_KEYS]:
        return __renderErrorJSON__('Invalid Key')


    key = urllib.unquote(key)
    value = urllib.unquote(value)
    
    #TODO Support Post -- need to add cooresponding form
    if request.method == "GET":
        page = int(request.GET.get('iDisplayStart', 0))
        pagesize = int(request.GET.get('iDisplayLength', 50))
        sortcols = int(request.GET.get('iSortingCols', 0))
        sEcho = request.GET.get('sEcho')
        sSearch = request.GET.get('sSearch', '')

        sort = []
        for x in range(sortcols):
            sortTuple = handler.formatSort(int(request.GET.get("iSortCol_%d" % x)), 
                                                request.GET.get("sSortDir_%d" % x))
            if sortTuple is not None:
                sort.append(sortTuple)

    else:
        return __renderErrorJSON__('Unsupported Method')

    if (len(sSearch) == 0):
        sSearch = None

    results = handler.dataTableSearch(key, value, page, pagesize, sort, sSearch, low, high)
    #Echo back the echo
    results['sEcho'] = sEcho
    
    return HttpResponse(json.dumps(results), content_type='application/json')