FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
patchwork/patchwork/paginator.py at main · getpatchwork/patchwork · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
getpatchwork
/
patchwork
Public
Notifications
You must be signed in to change notification settings
Fork
90
Star
315
Code
Issues
97
Pull requests
22
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
patchwork
/
patchwork
/
paginator.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
96 lines (80 loc) · 3.09 KB
Breadcrumbs
patchwork
/
patchwork
/
paginator.py
Copy path
File metadata and controls
96 lines (80 loc) · 3.09 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Patchwork - automated patch tracking system
# Copyright (C) 2008 Jeremy Kerr <jk@ozlabs.org>
#
# SPDX-License-Identifier: GPL-2.0-or-later
from
django
.
conf
import
settings
from
django
.
core
import
paginator
DEFAULT_ITEMS_PER_PAGE
=
100
LONG_PAGE_THRESHOLD
=
30
LEADING_PAGE_RANGE_DISPLAYED
=
4
TRAILING_PAGE_RANGE_DISPLAYED
=
4
LEADING_PAGE_RANGE
=
4
TRAILING_PAGE_RANGE
=
2
NUM_PAGES_OUTSIDE_RANGE
=
2
ADJACENT_PAGES
=
1
# parts from:
# http://blog.localkinegrinds.com/2007/09/06/digg-style-pagination-in-django/
class
Paginator
(
paginator
.
Paginator
):
def
__init__
(
self
,
request
,
objects
):
items_per_page
=
settings
.
DEFAULT_ITEMS_PER_PAGE
if
request
.
user
.
is_authenticated
:
items_per_page
=
request
.
user
.
profile
.
items_per_page
super
().
__init__
(
objects
,
items_per_page
)
try
:
page_no
=
int
(
request
.
GET
.
get
(
'page'
,
1
))
self
.
current_page
=
self
.
page
(
int
(
page_no
))
except
ValueError
:
page_no
=
1
self
.
current_page
=
self
.
page
(
page_no
)
except
paginator
.
EmptyPage
:
if
page_no
<
1
:
page_no
=
1
else
:
page_no
=
self
.
num_pages
self
.
current_page
=
self
.
page
(
page_no
)
self
.
leading_set
=
self
.
trailing_set
=
[]
pages
=
self
.
num_pages
if
pages
<=
LEADING_PAGE_RANGE_DISPLAYED
:
adjacent_start
=
1
adjacent_end
=
pages
+
1
elif
page_no
<
LEADING_PAGE_RANGE
:
adjacent_start
=
1
adjacent_end
=
LEADING_PAGE_RANGE_DISPLAYED
+
1
self
.
trailing_set
=
[
n
+
pages
for
n
in
reversed
(
range
(
0
,
-
NUM_PAGES_OUTSIDE_RANGE
,
-
1
))
]
elif
page_no
>=
pages
-
TRAILING_PAGE_RANGE
:
adjacent_start
=
pages
-
TRAILING_PAGE_RANGE_DISPLAYED
+
1
adjacent_end
=
pages
+
1
self
.
leading_set
=
[
n
+
1
for
n
in
range
(
0
,
NUM_PAGES_OUTSIDE_RANGE
)
]
else
:
adjacent_start
=
page_no
-
ADJACENT_PAGES
adjacent_end
=
page_no
+
ADJACENT_PAGES
+
1
self
.
leading_set
=
[
n
+
1
for
n
in
range
(
0
,
NUM_PAGES_OUTSIDE_RANGE
)
]
self
.
trailing_set
=
[
n
+
pages
for
n
in
reversed
(
range
(
0
,
-
NUM_PAGES_OUTSIDE_RANGE
,
-
1
))
]
self
.
adjacent_set
=
[
n
for
n
in
range
(
adjacent_start
,
adjacent_end
)
if
n
>
0
and
n
<=
pages
]
self
.
show_leading_ellipsis
=
False
if
self
.
leading_set
and
self
.
adjacent_set
:
# prevent e.g. 1 2 ... 3 4 5 ... 8 9
if
self
.
leading_set
[
-
1
]
!=
self
.
adjacent_set
[
0
]
-
1
:
self
.
show_leading_ellipsis
=
True
self
.
show_trailing_ellipsis
=
False
if
self
.
trailing_set
and
self
.
adjacent_set
:
# prevent e.g. 1 2 ... 5 6 7 ... 8 9
if
self
.
trailing_set
[
0
]
!=
self
.
adjacent_set
[
-
1
]
+
1
:
self
.
show_trailing_ellipsis
=
True
self
.
long_page
=
(
len
(
self
.
current_page
.
object_list
)
>=
LONG_PAGE_THRESHOLD
)
Back
|
FazBrowse Home
|
New Git URL