0001-add-generic-pagination-template-14939.patch
README.txt | ||
---|---|---|
80 | 80 |
gadjo/static/css/header-03.jpeg is copied from let's encrypt website, licensed |
81 | 81 |
under Mozilla Public License Version 2.0, see their repository at |
82 | 82 |
https://github.com/letsencrypt/website.git. |
83 | ||
84 |
The querystring template tag is originally from django-tables2, copyright (c) |
|
85 |
2011, Bradley Ayers, copyright (c) 2008, Michael Elsdörfer, published under |
|
86 |
the MIT license. |
|
87 |
https://raw.githubusercontent.com/jieter/django-tables2/master/LICENSE |
gadjo/static/css/gadjo.scss | ||
---|---|---|
538 | 538 |
} |
539 | 539 | |
540 | 540 |
p.paginator span.this-page { |
541 |
background: #0066CC;
|
|
542 |
border-color: #0066CC;
|
|
541 |
background: #5B616B;
|
|
542 |
border-color: #5B616B;
|
|
543 | 543 |
color: white; |
544 | 544 |
} |
545 | 545 | |
546 | 546 |
p.paginator span.this-page + a { |
547 |
border-left-color: #0066CC;
|
|
547 |
border-left-color: #5B616B;
|
|
548 | 548 |
} |
549 | 549 | |
550 | 550 |
p.paginator a:hover { |
gadjo/templates/gadjo/pagination.html | ||
---|---|---|
1 |
{% load gadjo %} |
|
2 |
{% comment %} |
|
3 |
Pagination bar |
|
4 | ||
5 |
Expected context variables: |
|
6 |
- request: django request object |
|
7 |
- page_obj: Paginator page object |
|
8 |
- page_key (optional): name of page parameter (default: page) |
|
9 |
- anchor (optional): anchor to use in links |
|
10 | ||
11 |
{% endcomment %} |
|
12 |
{% if page_obj.paginator.num_pages > 1 %} |
|
13 |
{% with page_key=page_key|default:"page" %} |
|
14 |
{% spaceless %} |
|
15 |
<p class="paginator"> |
|
16 |
{% if page_obj.number > 1 %} |
|
17 |
{% if page_obj.previous_page_number != 1 %} |
|
18 |
<a href="{% querystring page_key=1 %}{{ anchor }}">1</a> |
|
19 |
… |
|
20 |
{% endif %} |
|
21 |
{% endif %} |
|
22 | ||
23 |
{% if page_obj.has_previous %} |
|
24 |
<a href="{% querystring page_key=page_obj.previous_page_number %}{{ anchor }}">{{ page_obj.previous_page_number }}</a> |
|
25 |
{% endif %} |
|
26 | ||
27 |
<span class="this-page">{{ page_obj.number }}</span> |
|
28 | ||
29 |
{% if page_obj.has_next %} |
|
30 |
<a href="{% querystring page_key=page_obj.next_page_number %}{{ anchor }}">{{ page_obj.next_page_number }}</a> |
|
31 |
{% endif %} |
|
32 |
{% if page_obj.number != page_obj.paginator.num_pages %} |
|
33 |
{% if page_obj.paginator.num_pages > 1 %} |
|
34 |
{% if page_obj.next_page_number != page_obj.paginator.num_pages %} |
|
35 |
… |
|
36 |
<a href="{% querystring page_key=page_obj.paginator.num_pages %}{{ anchor }}">{{ page_obj.paginator.num_pages }}</a> |
|
37 |
{% endif %} |
|
38 |
{% endif %} |
|
39 |
{% endif %} |
|
40 |
</p> |
|
41 |
{% endspaceless %} |
|
42 |
{% endwith %} |
|
43 |
{% endif %} |
gadjo/templatetags/gadjo.py | ||
---|---|---|
1 |
from collections import OrderedDict |
|
2 |
import re |
|
3 | ||
1 | 4 |
from xstatic.main import XStatic |
2 | 5 | |
3 | 6 |
from django import template |
4 | 7 |
from django.conf import settings |
8 |
from django.core.exceptions import ImproperlyConfigured |
|
9 |
from django.utils.html import escape |
|
10 |
from django.utils.http import urlencode |
|
5 | 11 | |
6 | 12 |
register = template.Library() |
7 | 13 | |
... | ... | |
34 | 40 |
return base_url.get(filename) |
35 | 41 | |
36 | 42 |
return settings.STATIC_URL + 'xstatic/' + filename |
43 | ||
44 | ||
45 |
# {% querystring %} bits originally from django-tables2. |
|
46 |
kwarg_re = re.compile(r"(?:(.+)=)?(.+)") |
|
47 | ||
48 |
def token_kwargs(bits, parser): |
|
49 |
""" |
|
50 |
Based on Django's `~django.template.defaulttags.token_kwargs`, but with a |
|
51 |
few changes: |
|
52 | ||
53 |
- No legacy mode. |
|
54 |
- Both keys and values are compiled as a filter |
|
55 |
""" |
|
56 |
if not bits: |
|
57 |
return {} |
|
58 |
kwargs = OrderedDict() |
|
59 |
while bits: |
|
60 |
match = kwarg_re.match(bits[0]) |
|
61 |
if not match or not match.group(1): |
|
62 |
return kwargs |
|
63 |
key, value = match.groups() |
|
64 |
del bits[:1] |
|
65 |
kwargs[parser.compile_filter(key)] = parser.compile_filter(value) |
|
66 |
return kwargs |
|
67 | ||
68 |
class QuerystringNode(template.Node): |
|
69 |
def __init__(self, updates, removals): |
|
70 |
super(QuerystringNode, self).__init__() |
|
71 |
self.updates = updates |
|
72 |
self.removals = removals |
|
73 | ||
74 |
def render(self, context): |
|
75 |
if not 'request' in context: |
|
76 |
raise ImproperlyConfigured('Missing django.core.context_processors.request') |
|
77 |
params = dict(context['request'].GET) |
|
78 |
for key, value in self.updates.items(): |
|
79 |
key = key.resolve(context) |
|
80 |
value = value.resolve(context) |
|
81 |
if key not in ("", None): |
|
82 |
params[key] = value |
|
83 |
for removal in self.removals: |
|
84 |
params.pop(removal.resolve(context), None) |
|
85 |
return escape("?" + urlencode(params, doseq=True)) |
|
86 | ||
87 |
@register.tag |
|
88 |
def querystring(parser, token): |
|
89 |
""" |
|
90 |
Creates a URL (containing only the querystring [including "?"]) derived |
|
91 |
from the current URL's querystring, by updating it with the provided |
|
92 |
keyword arguments. |
|
93 | ||
94 |
Example (imagine URL is ``/abc/?gender=male&name=Brad``):: |
|
95 | ||
96 |
{% querystring "name"="Ayers" "age"=20 %} |
|
97 |
?name=Ayers&gender=male&age=20 |
|
98 |
{% querystring "name"="Ayers" without "gender" %} |
|
99 |
?name=Ayers |
|
100 | ||
101 |
""" |
|
102 |
bits = token.split_contents() |
|
103 |
tag = bits.pop(0) |
|
104 |
updates = token_kwargs(bits, parser) |
|
105 |
# ``bits`` should now be empty of a=b pairs, it should either be empty, or |
|
106 |
# have ``without`` arguments. |
|
107 |
if bits and bits.pop(0) != "without": |
|
108 |
raise TemplateSyntaxError("Malformed arguments to '%s'" % tag) |
|
109 |
removals = [parser.compile_filter(bit) for bit in bits] |
|
110 |
return QuerystringNode(updates, removals) |
|
37 |
- |