diff --git a/boards/abstracts/paginator.py b/boards/abstracts/paginator.py
--- a/boards/abstracts/paginator.py
+++ b/boards/abstracts/paginator.py
@@ -1,9 +1,9 @@
+from django.core.paginator import Paginator
from boards.abstracts.constants import PARAM_PAGE
__author__ = 'neko259'
-from django.core.paginator import Paginator
-
+PATTERN_PAGE_URL = '{}'
PAGINATOR_LOOKAROUND_SIZE = 2
@@ -16,11 +16,11 @@ class DividedPaginator(Paginator):
lookaround_size = PAGINATOR_LOOKAROUND_SIZE
def __init__(self, object_list, per_page, orphans=0,
- allow_empty_first_page=True, current_page=1):
+ allow_empty_first_page=True, current_page=1, link=None, params=None):
super().__init__(object_list, per_page, orphans, allow_empty_first_page)
- self.link = None
- self.params = None
+ self.link = link
+ self.params = params
self.current_page = current_page
def _left_range(self):
@@ -69,10 +69,6 @@ class DividedPaginator(Paginator):
return dividers
- def set_url(self, link, params):
- self.link = link
- self.params = params
-
def get_page_url(self, page):
self.params[PARAM_PAGE] = page
url_params = '&'.join(['{}={}'.format(key, self.params[key])
@@ -91,3 +87,20 @@ class DividedPaginator(Paginator):
current = self.page(self.current_page)
if current.has_previous():
return self.get_page_url(current.previous_page_number())
+
+ def get_page_url_list(self):
+ output = []
+
+ dividers = self.get_dividers()
+ for page in self.get_divided_range():
+ if page in dividers:
+ output.append('...')
+
+ if page == self.current_page:
+ cls = 'class="current_page'
+ else:
+ cls = ''
+ output.append(PATTERN_PAGE_URL.format(cls, self.get_page_url(page),
+ page))
+
+ return ', '.join(output)
diff --git a/boards/templates/boards/all_threads.html b/boards/templates/boards/all_threads.html
--- a/boards/templates/boards/all_threads.html
+++ b/boards/templates/boards/all_threads.html
@@ -160,25 +160,3 @@
{% endblock %}
-
-{% block metapanel %}
-
-
- {% trans "Pages:" %}
- [
- {% with dividers=paginator.get_dividers %}
- {% for page in paginator.get_divided_range %}
- {% if page in dividers %}
- …,
- {% endif %}
- {{ page }}{% if not forloop.last %},{% endif %}
- {% endfor %}
- {% endwith %}
- ]
-
-
-{% endblock %}
diff --git a/boards/templates/boards/notifications.html b/boards/templates/boards/notifications.html
--- a/boards/templates/boards/notifications.html
+++ b/boards/templates/boards/notifications.html
@@ -1,4 +1,4 @@
-{% extends 'boards/base.html' %}
+{% extends 'boards/paginated.html' %}
{% load board %}
{% load i18n %}
diff --git a/boards/templates/boards/paginated.html b/boards/templates/boards/paginated.html
--- a/boards/templates/boards/paginated.html
+++ b/boards/templates/boards/paginated.html
@@ -6,21 +6,7 @@
{% block metapanel %}
- {% trans "Pages:" %}
- [
- {% with dividers=paginator.get_dividers %}
- {% for page in paginator.get_divided_range %}
- {% if page in dividers %}
- …,
- {% endif %}
- {{ page }}{% if not forloop.last %},{% endif %}
- {% endfor %}
- {% endwith %}
- ]
+ {% trans "Pages:" %} [{{ paginator.get_page_url_list|safe }}]
{% endblock %}
diff --git a/boards/templates/boards/tag_gallery.html b/boards/templates/boards/tag_gallery.html
--- a/boards/templates/boards/tag_gallery.html
+++ b/boards/templates/boards/tag_gallery.html
@@ -1,4 +1,4 @@
-{% extends "boards/base.html" %}
+{% extends "boards/paginated.html" %}
{% load i18n %}
{% load board %}
@@ -88,27 +88,3 @@
{% endif %}
{% endblock %}
-
-{% block metapanel %}
-
-
- {{ site_name }} {{ version }}
- {% trans "Pages:" %}
- [
- {% with dividers=paginator.get_dividers %}
- {% for page in paginator.get_divided_range %}
- {% if page in dividers %}
- …,
- {% endif %}
- {{ page }}
- {% if not forloop.last %},{% endif %}
- {% endfor %}
- {% endwith %}
- ]
-
-
-{% endblock %}
diff --git a/boards/views/all_threads.py b/boards/views/all_threads.py
--- a/boards/views/all_threads.py
+++ b/boards/views/all_threads.py
@@ -70,7 +70,9 @@ class AllThreadsView(BaseBoardView, Pagi
threads = threads.distinct()
paginator = get_paginator(threads, settings.get_int(
- SECTION_VIEW, 'ThreadsPerPage'))
+ SECTION_VIEW, 'ThreadsPerPage'),
+ link=self.get_reverse_url(),
+ params=request.GET.dict())
paginator.current_page = int(page)
try:
@@ -82,7 +84,6 @@ class AllThreadsView(BaseBoardView, Pagi
params[CONTEXT_FORM] = form
params[PARAMETER_RSS_URL] = self.get_rss_url()
- paginator.set_url(self.get_reverse_url(), request.GET.dict())
params.update(self.get_page_context(paginator, page))
return render(request, TEMPLATE, params)
diff --git a/boards/views/feed.py b/boards/views/feed.py
--- a/boards/views/feed.py
+++ b/boards/views/feed.py
@@ -119,13 +119,13 @@ class FeedView(PaginatedMixin, BaseBoard
queries.append(query)
params[PARAMETER_QUERIES] = queries
- paginator = get_paginator(posts, POSTS_PER_PAGE)
+ paginator = get_paginator(posts, POSTS_PER_PAGE,
+ link=reverse('feed'),
+ params=request.GET.dict())
paginator.current_page = int(page)
params[PARAMETER_POSTS] = paginator.page(page).object_list
- paginator.set_url(reverse('feed'), request.GET.dict())
-
params.update(self.get_page_context(paginator, page))
return render(request, TEMPLATE, params)
diff --git a/boards/views/notifications.py b/boards/views/notifications.py
--- a/boards/views/notifications.py
+++ b/boards/views/notifications.py
@@ -1,4 +1,5 @@
from django.shortcuts import render
+from django.urls import reverse
from boards.abstracts.constants import PARAM_PAGE
from boards.abstracts.paginator import get_paginator
@@ -6,6 +7,7 @@ from boards.abstracts.settingsmanager im
SETTING_LAST_NOTIFICATION_ID
from boards.models.user import Notification
from boards.views.base import BaseBoardView
+from boards.views.mixins import PaginatedMixin
DEFAULT_PAGE = '1'
@@ -14,7 +16,7 @@ PARAM_USERNAMES = 'notification_username
RESULTS_PER_PAGE = 10
-class NotificationView(BaseBoardView):
+class NotificationView(BaseBoardView, PaginatedMixin):
def get(self, request, username=None):
params = self.get_context_data()
@@ -37,12 +39,13 @@ class NotificationView(BaseBoardView):
settings_manager.set_setting(SETTING_LAST_NOTIFICATION_ID,
last_id)
-
- paginator = get_paginator(posts, RESULTS_PER_PAGE)
-
page = int(request.GET.get(PARAM_PAGE, DEFAULT_PAGE))
+ paginator = get_paginator(posts, RESULTS_PER_PAGE,
+ link=reverse('notifications'),
+ params=request.GET.dict())
params[PARAM_PAGE] = paginator.page(page)
params[PARAM_USERNAMES] = notification_usernames
+ params.update(self.get_page_context(paginator, page))
return render(request, TEMPLATE, params)
diff --git a/boards/views/search.py b/boards/views/search.py
--- a/boards/views/search.py
+++ b/boards/views/search.py
@@ -40,8 +40,9 @@ class BoardSearchView(View, PaginatedMix
| Q(title__icontains=query) | Q(opening=True,
thread__tags__aliases__name__icontains=query)
| Q(attachments__url__icontains=query)).order_by('-id').distinct()
- paginator = get_paginator(results, RESULTS_PER_PAGE)
- paginator.set_url(reverse('search'), request.GET.dict())
+ paginator = get_paginator(results, RESULTS_PER_PAGE,
+ link=reverse('search'),
+ params=request.GET.dict())
page = int(request.GET.get(REQUEST_PAGE, '1'))
diff --git a/boards/views/tag_gallery.py b/boards/views/tag_gallery.py
--- a/boards/views/tag_gallery.py
+++ b/boards/views/tag_gallery.py
@@ -23,12 +23,14 @@ class TagGalleryView(BaseBoardView, Pagi
tag_alias = get_object_or_404(TagAlias, name=tag_name)
tag = tag_alias.parent
params['tag'] = tag
- paginator = get_paginator(tag.get_images(), IMAGES_PER_PAGE,
- current_page=page)
+ paginator = get_paginator(
+ tag.get_images(),
+ IMAGES_PER_PAGE,
+ current_page=page,
+ link=reverse('tag_gallery', kwargs={'tag_name': tag_name}),
+ params=request.GET.dict())
params['paginator'] = paginator
params['images'] = paginator.page(page).object_list
- paginator.set_url(reverse('tag_gallery', kwargs={'tag_name': tag_name}),
- request.GET.dict())
params.update(self.get_page_context(paginator, page))
return render(request, TEMPLATE, params)