예제 #1
0
파일: sorting.py 프로젝트: dahool/regeer
def sortheader(data, name, params=None, url=None, style=None):
    if not style:
        style = 'sorted'
    if data and data[:1]=='-':
        order = 'd'
        data = data[1:]
    else:
        order = 'a'
    if url:
        if url.find('?') != -1:
            url, urlpar = extract_params(url) 
            params.update(urlpar)
    else:
        url = ''
    if params:
        if not isinstance(params, dict):
            params = parse_params(params)
    else:
        params = {}
    params['sort']=name
    try:
        del params['order']
    except KeyError:
        pass
    try:
        del params['page']
    except KeyError:
        pass    
    url += '?%s' % serialize_params(params)
    return {'style': style, 'order': order, 'data': data, 'name': name, 'url': url}
예제 #2
0
파일: paginator.py 프로젝트: dahool/regeer
def paginatepage(context, data, params=None):
    " Initialize variables "
    in_leading_range = in_trailing_range = False
    pages_outside_leading_range = pages_outside_trailing_range = range(0)
 
    tagContext={'pages': data.paginator.num_pages, 'page': data.number}
    
    if (tagContext["pages"] <= LEADING_PAGE_RANGE_DISPLAYED):
        in_leading_range = in_trailing_range = True
        page_numbers = [n for n in range(1, tagContext["pages"] + 1) if n > 0 and n <= tagContext["pages"]]           
    elif (tagContext["page"] <= LEADING_PAGE_RANGE):
        in_leading_range = True
        page_numbers = [n for n in range(1, LEADING_PAGE_RANGE_DISPLAYED + 1) if n > 0 and n <= tagContext["pages"]]
        pages_outside_leading_range = [n + tagContext["pages"] for n in range(0, -NUM_PAGES_OUTSIDE_RANGE, -1)]
    elif (tagContext["page"] > tagContext["pages"] - TRAILING_PAGE_RANGE):
        in_trailing_range = True
        page_numbers = [n for n in range(tagContext["pages"] - TRAILING_PAGE_RANGE_DISPLAYED + 1, tagContext["pages"] + 1) if n > 0 and n <= tagContext["pages"]]
        pages_outside_trailing_range = [n + 1 for n in range(0, NUM_PAGES_OUTSIDE_RANGE)]
    else: 
        page_numbers = [n for n in range(tagContext["page"] - ADJACENT_PAGES, tagContext["page"] + ADJACENT_PAGES + 1) if n > 0 and n <= tagContext["pages"]]
        pages_outside_leading_range = [n + tagContext["pages"] for n in range(0, -NUM_PAGES_OUTSIDE_RANGE, -1)]
        pages_outside_trailing_range = [n + 1 for n in range(0, NUM_PAGES_OUTSIDE_RANGE)]

    # include server param if exists
    url = None
    if params:
        if params.find('?') != -1:
            url, params = extract_params(params) 
        else:
            params = parse_params(params)
        try:
            del params['page']
        except:
            pass
    else:
        params = {}

    request = context['request']
    if request.server:
        if not params.has_key('server'):
            params['server'] = request.server
    
    if url:
        pdata = '%s?%s' % (url, serialize_params(params))
    else:
        pdata = '?%s' % serialize_params(params)
     
    return {'data': data,
            'numbers': page_numbers,
            'in_leading_range': in_leading_range,
            'page_numbers': page_numbers,
            'pages_outside_trailing_range': pages_outside_trailing_range,
            'in_trailing_range': in_trailing_range,
            'pages_outside_leading_range': pages_outside_leading_range,
            'params': pdata}
예제 #3
0
파일: paginator.py 프로젝트: dahool/vertaal
def paginate(data, params=None):
    url = ''
    if params:
        if params.find("?"):
            url, params = extract_params(params) 
        else:
            params = parse_params(params)
    else:
        params = {}
    url += '?%s' % serialize_params(params)
    return {'data': data, 'params': url}