1 | """Pagination Link Generators""" |
---|
2 | from webhelpers.htmlgen import html |
---|
3 | |
---|
4 | def pagelist(page): |
---|
5 | """PHPbb style Pagination Links |
---|
6 | |
---|
7 | This returns HTML source to be included into a page. The html is generated |
---|
8 | with htmlgen |
---|
9 | """ |
---|
10 | paginator = page.paginator |
---|
11 | |
---|
12 | first_page = paginator[0] |
---|
13 | first_window = first_page.window(padding=3) |
---|
14 | |
---|
15 | page_window = page.window(padding=1) |
---|
16 | |
---|
17 | last_page = paginator[-1] |
---|
18 | last_window = last_page.window(padding=3) |
---|
19 | |
---|
20 | first_past_page = first_window.last >= page_window.first |
---|
21 | page_past_last = page_window.last >= last_window.first |
---|
22 | |
---|
23 | def combine_pages(page_list): |
---|
24 | seen = {} |
---|
25 | result = [] |
---|
26 | for page in page_list: |
---|
27 | if page in seen: continue |
---|
28 | seen[page] = 1 |
---|
29 | result.append(page) |
---|
30 | return result |
---|
31 | |
---|
32 | if first_past_page: |
---|
33 | if page_past_last: |
---|
34 | display = first_window.pages |
---|
35 | else: |
---|
36 | first_window.last = page_window.last |
---|
37 | display = (first_window.pages + [None] + last_window.pages) |
---|
38 | else: |
---|
39 | if page_past_last: |
---|
40 | page_window.last = last_window.last |
---|
41 | display = (first_window.pages + [None] + page_window.pages) |
---|
42 | else: |
---|
43 | display = (first_window.pages + [None] + page_window.pages + [None] |
---|
44 | + last_window.pages) |
---|
45 | |
---|
46 | print display |
---|
47 | |
---|
48 | pager_c = [] |
---|
49 | for i in display: |
---|
50 | if i is None: |
---|
51 | pager_c.append(html.span(c='...')) |
---|
52 | elif i == page: |
---|
53 | pager_c.append(html.span(c=[i])) |
---|
54 | else: |
---|
55 | pager_c.append(html.a(href=i, c=[i])) |
---|
56 | |
---|
57 | pager = html.div(class_='pager', c=pager_c) |
---|
58 | |
---|
59 | return pager |
---|