Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
AE
Sith
Commits
f400be3a
Commit
f400be3a
authored
Mar 15, 2017
by
Skia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor topic to use paginator instead of custom paging
parent
701f23b5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
13 deletions
+13
-13
forum/templates/forum/topic.jinja
forum/templates/forum/topic.jinja
+4
-4
forum/views.py
forum/views.py
+9
-9
No files found.
forum/templates/forum/topic.jinja
View file @
f400be3a
...
...
@@ -39,8 +39,8 @@
<p><a
href=
"
{{
url
(
'forum:new_message'
,
topic_id
=
topic.id
)
}}
"
>
{%
trans
%}
Reply
{%
endtrans
%}
</a></p>
<p
style=
"text-align: right; background: #d8e7f3;"
>
{%
for
p
in
range
(
1
,
page_count
+
1
)
%}
<span
class=
"ib"
style=
"background:
{%
if
p
==
current_page
%}
white
{%
endif
%}
; margin: 0;"
><a
href=
"?page=
{{
p
}}
"
>
{{
p
}}
</a></span>
{%
for
p
in
msgs.paginator.page_range
%}
<span
class=
"ib"
style=
"background:
{%
if
p
==
msgs.
number
%}
white
{%
endif
%}
; margin: 0;"
><a
href=
"?page=
{{
p
}}
"
>
{{
p
}}
</a></span>
{%
endfor
%}
</p>
...
...
@@ -58,8 +58,8 @@
<p><a
href=
"
{{
url
(
'forum:new_message'
,
topic_id
=
topic.id
)
}}
"
>
{%
trans
%}
Reply
{%
endtrans
%}
</a></p>
<p
style=
"text-align: right; background: #d8e7f3;"
>
{%
for
p
in
range
(
1
,
page_count
+
1
)
%}
<span
class=
"ib"
style=
"background:
{%
if
p
==
current_page
%}
white
{%
endif
%}
; margin: 0;"
><a
href=
"?page=
{{
p
}}
"
>
{{
p
}}
</a></span>
{%
for
p
in
msgs.paginator.page_range
%}
<span
class=
"ib"
style=
"background:
{%
if
p
==
msgs.
number
%}
white
{%
endif
%}
; margin: 0;"
><a
href=
"?page=
{{
p
}}
"
>
{{
p
}}
</a></span>
{%
endfor
%}
</p>
{%
endblock
%}
...
...
forum/views.py
View file @
f400be3a
...
...
@@ -9,6 +9,7 @@ from django.conf import settings
from
django
import
forms
from
django.db
import
models
from
django.core.exceptions
import
PermissionDenied
from
django.core.paginator
import
Paginator
,
EmptyPage
,
PageNotAnInteger
from
ajax_select
import
make_ajax_form
,
make_ajax_field
...
...
@@ -139,16 +140,15 @@ class ForumTopicDetailView(CanViewMixin, DetailView):
kwargs
[
'first_unread_message_id'
]
=
msg
.
id
except
:
kwargs
[
'first_unread_message_id'
]
=
float
(
"inf"
)
page_length
=
settings
.
SITH_FORUM_PAGE_LENGTH
paginator
=
Paginator
(
self
.
object
.
messages
.
select_related
(
'author__avatar_pict'
).
all
(),
settings
.
SITH_FORUM_PAGE_LENGTH
)
page
=
self
.
request
.
GET
.
get
(
'page'
)
try
:
page
=
int
(
self
.
request
.
GET
[
'page'
])
-
1
if
page
<
0
:
page
=
0
except
:
page
=
0
kwargs
[
"msgs"
]
=
self
.
object
.
messages
.
select_related
(
'author__avatar_pict'
).
all
()[
page
*
page_length
:
page
*
page_length
+
page_length
]
kwargs
[
"page_count"
]
=
int
(
self
.
object
.
messages
.
count
()
/
page_length
)
+
1
kwargs
[
"current_page"
]
=
page
+
1
kwargs
[
"msgs"
]
=
paginator
.
page
(
page
)
except
PageNotAnInteger
:
kwargs
[
"msgs"
]
=
paginator
.
page
(
1
)
except
EmptyPage
:
kwargs
[
"msgs"
]
=
paginator
.
page
(
paginator
.
num_pages
)
return
kwargs
class
ForumMessageEditView
(
CanEditMixin
,
UpdateView
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment