Replace django-pagination with django-pure-pagination and use Django's native CBV pagination context.
This commit is contained in:
@@ -31,6 +31,7 @@ What's new in Mayan EDMS v2.0
|
|||||||
|
|
||||||
* South
|
* South
|
||||||
* GitPython
|
* GitPython
|
||||||
|
* django-pagination
|
||||||
* psutil
|
* psutil
|
||||||
* python-hkp
|
* python-hkp
|
||||||
* sendfile
|
* sendfile
|
||||||
@@ -52,6 +53,7 @@ What's new in Mayan EDMS v2.0
|
|||||||
|
|
||||||
* PyYAML
|
* PyYAML
|
||||||
* django-autoadmin
|
* django-autoadmin
|
||||||
|
* django-pure-pagination
|
||||||
* djangorestframework-recursive
|
* djangorestframework-recursive
|
||||||
|
|
||||||
* Permissions refactor
|
* Permissions refactor
|
||||||
@@ -79,6 +81,7 @@ What's new in Mayan EDMS v2.0
|
|||||||
* Improved API
|
* Improved API
|
||||||
* Text parsers and OCR backend are used in tandem.
|
* Text parsers and OCR backend are used in tandem.
|
||||||
* Invert page title/project name order in browser title.
|
* Invert page title/project name order in browser title.
|
||||||
|
* Use Django's class based views pagination
|
||||||
|
|
||||||
Upgrading from a previous version
|
Upgrading from a previous version
|
||||||
=================================
|
=================================
|
||||||
|
|||||||
@@ -2,18 +2,20 @@
|
|||||||
{% load static %}
|
{% load static %}
|
||||||
|
|
||||||
{% load common_tags %}
|
{% load common_tags %}
|
||||||
{% load pagination_tags %}
|
|
||||||
{% load navigation_tags %}
|
{% load navigation_tags %}
|
||||||
|
|
||||||
{% autopaginate object_list %}
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<h4>
|
<h4>
|
||||||
{% ifnotequal page_obj.paginator.num_pages 1 %}
|
{% if page_obj %}
|
||||||
{% blocktrans with page_obj.start_index as start and page_obj.end_index as end and page_obj.paginator.object_list|length as total and page_obj.number as page_number and page_obj.paginator.num_pages as total_pages %}Total ({{ start }} - {{ end }} out of {{ total }}) (Page {{ page_number }} of {{ total_pages }}){% endblocktrans %}
|
{% if page_obj.paginator.num_pages != 1 %}
|
||||||
|
{% blocktrans with page_obj.start_index as start and page_obj.end_index as end and page_obj.paginator.object_list|length as total and page_obj.number as page_number and page_obj.paginator.num_pages as total_pages %}Total ({{ start }} - {{ end }} out of {{ total }}) (Page {{ page_number }} of {{ total_pages }}){% endblocktrans %}
|
||||||
|
{% else %}
|
||||||
|
{% blocktrans with page_obj.paginator.object_list|length as total %}Total: {{ total }}{% endblocktrans %}
|
||||||
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% blocktrans with page_obj.paginator.object_list|length as total %}Total: {{ total }}{% endblocktrans %}
|
{% blocktrans with object_list|length as total %}Total: {{ total }}{% endblocktrans %}
|
||||||
{% endifnotequal %}
|
{% endif %}
|
||||||
</h4>
|
</h4>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
@@ -119,7 +121,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
{% paginate %}
|
{% include 'pagination/pagination.html' %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,27 +1,27 @@
|
|||||||
{% if is_paginated %}
|
{% if is_paginated %}
|
||||||
<ul class="pagination pagination-sm">
|
<ul class="pagination pagination-sm">
|
||||||
{% if page_obj.has_previous %}
|
{% if page_obj.has_previous %}
|
||||||
<li><a href="?page={{ page_obj.previous_page_number }}{{ getvars }}">‹‹</a></li>
|
<li><a href="?{{ page_obj.previous_page_number.querystring }}">‹‹</a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li class="disabled"><a href="#">‹‹</a></li>
|
<li class="disabled"><a href="#">‹‹</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% for page in pages %}
|
{% for page in page_obj.pages %}
|
||||||
|
|
||||||
{% if page %}
|
{% if page %}
|
||||||
|
|
||||||
{% ifequal page page_obj.number %}
|
{% ifequal page page_obj.number %}
|
||||||
<li class="active"><a href="#">{{ page }}</a></li>
|
<li class="active"><a href="#">{{ page }}</a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li><a href="?page={{ page }}{{ getvars }}{{ hashtag }}">{{ page }}</a></li>
|
<li><a href="?{{ page.querystring }}">{{ page }}</a></li>
|
||||||
{% endifequal %}
|
{% endifequal %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<span class="disabled">...</span>
|
<li class="disabled"><a href="#" class="disabled">...</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if page_obj.has_next %}
|
{% if page_obj.has_next %}
|
||||||
<li><a href="?page={{ page_obj.next_page_number }}{{ getvars }}">››</a></li>
|
<li><a href="?{{ page_obj.next_page_number.querystring }}">››</a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li class="disabled"><a href="#">››</a></li>
|
<li class="disabled"><a href="#">››</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -12,12 +12,14 @@ from django.views.generic.detail import SingleObjectMixin
|
|||||||
from django.views.generic.edit import CreateView, DeleteView, UpdateView
|
from django.views.generic.edit import CreateView, DeleteView, UpdateView
|
||||||
from django.views.generic.list import ListView
|
from django.views.generic.list import ListView
|
||||||
|
|
||||||
|
from pure_pagination.mixins import PaginationMixin
|
||||||
|
|
||||||
from .forms import ChoiceForm
|
from .forms import ChoiceForm
|
||||||
from .mixins import (
|
from .mixins import (
|
||||||
ExtraContextMixin, ObjectListPermissionFilterMixin,
|
ExtraContextMixin, ObjectListPermissionFilterMixin,
|
||||||
ObjectPermissionCheckMixin, RedirectionMixin, ViewPermissionCheckMixin
|
ObjectPermissionCheckMixin, RedirectionMixin, ViewPermissionCheckMixin
|
||||||
)
|
)
|
||||||
|
from .settings import setting_paginate_by
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'AssignRemoveView', 'ConfirmView', 'MultiFormView', 'ParentChildListView',
|
'AssignRemoveView', 'ConfirmView', 'MultiFormView', 'ParentChildListView',
|
||||||
@@ -430,5 +432,6 @@ class SingleObjectEditView(ViewPermissionCheckMixin, ObjectPermissionCheckMixin,
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
class SingleObjectListView(ViewPermissionCheckMixin, ObjectListPermissionFilterMixin, ExtraContextMixin, RedirectionMixin, ListView):
|
class SingleObjectListView(PaginationMixin, ViewPermissionCheckMixin, ObjectListPermissionFilterMixin, ExtraContextMixin, RedirectionMixin, ListView):
|
||||||
|
paginate_by = setting_paginate_by.value
|
||||||
template_name = 'appearance/generic_list.html'
|
template_name = 'appearance/generic_list.html'
|
||||||
|
|||||||
@@ -17,3 +17,8 @@ setting_shared_storage = namespace.add_setting(
|
|||||||
default='storage.backends.filebasedstorage.FileBasedStorage',
|
default='storage.backends.filebasedstorage.FileBasedStorage',
|
||||||
help_text=_('A storage backend that all workers can use to share files.')
|
help_text=_('A storage backend that all workers can use to share files.')
|
||||||
)
|
)
|
||||||
|
setting_paginate_by = namespace.add_setting(
|
||||||
|
global_name='COMMON_PAGINATE_BY',
|
||||||
|
default=40,
|
||||||
|
help_text=_('An integer specifying how many objects should be displayed per page.')
|
||||||
|
)
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ INSTALLED_APPS = (
|
|||||||
'djcelery',
|
'djcelery',
|
||||||
'filetransfers',
|
'filetransfers',
|
||||||
'mptt',
|
'mptt',
|
||||||
|
'pure_pagination',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'rest_framework.authtoken',
|
'rest_framework.authtoken',
|
||||||
'solo',
|
'solo',
|
||||||
@@ -97,9 +98,6 @@ INSTALLED_APPS = (
|
|||||||
'tags.apps.TagsApp',
|
'tags.apps.TagsApp',
|
||||||
# Placed after rest_api to allow template overriding
|
# Placed after rest_api to allow template overriding
|
||||||
'rest_framework_swagger',
|
'rest_framework_swagger',
|
||||||
# Pagination app must go after the main app so that the main app can
|
|
||||||
# override the default pagination template
|
|
||||||
'pagination',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
MIDDLEWARE_CLASSES = (
|
MIDDLEWARE_CLASSES = (
|
||||||
@@ -114,7 +112,6 @@ MIDDLEWARE_CLASSES = (
|
|||||||
'common.middleware.timezone.TimezoneMiddleware',
|
'common.middleware.timezone.TimezoneMiddleware',
|
||||||
'common.middleware.strip_spaces_widdleware.SpacelessMiddleware',
|
'common.middleware.strip_spaces_widdleware.SpacelessMiddleware',
|
||||||
'authentication.middleware.login_required_middleware.LoginRequiredMiddleware',
|
'authentication.middleware.login_required_middleware.LoginRequiredMiddleware',
|
||||||
'pagination.middleware.PaginationMiddleware',
|
|
||||||
'common.middleware.ajax_redirect.AjaxRedirect',
|
'common.middleware.ajax_redirect.AjaxRedirect',
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -239,9 +236,6 @@ LOGIN_EXEMPT_URLS = (
|
|||||||
|
|
||||||
r'^api/',
|
r'^api/',
|
||||||
)
|
)
|
||||||
# --------- Pagination ----------------
|
|
||||||
PAGINATION_INVALID_PAGE_RAISES_404 = True
|
|
||||||
PAGINATION_DEFAULT_PAGINATION = 40
|
|
||||||
# ---------- Django REST framework -----------
|
# ---------- Django REST framework -----------
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'PAGINATE_BY': 10,
|
'PAGINATE_BY': 10,
|
||||||
@@ -253,6 +247,11 @@ REST_FRAMEWORK = {
|
|||||||
'rest_framework.authentication.SessionAuthentication',
|
'rest_framework.authentication.SessionAuthentication',
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
# --------- Pagination --------
|
||||||
|
PAGINATION_SETTINGS = {
|
||||||
|
'PAGE_RANGE_DISPLAYED': 8,
|
||||||
|
'MARGIN_PAGES_DISPLAYED': 2,
|
||||||
|
}
|
||||||
# ----------- Celery ----------
|
# ----------- Celery ----------
|
||||||
CELERY_ACCEPT_CONTENT = ('json',)
|
CELERY_ACCEPT_CONTENT = ('json',)
|
||||||
CELERY_ALWAYS_EAGER = True
|
CELERY_ALWAYS_EAGER = True
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ django-colorful==1.1.0
|
|||||||
django-compressor==1.5
|
django-compressor==1.5
|
||||||
django-cors-headers==1.1.0
|
django-cors-headers==1.1.0
|
||||||
django-filetransfers==0.1.0
|
django-filetransfers==0.1.0
|
||||||
django-pagination==1.0.7
|
django-pure-pagination==0.2.1
|
||||||
django-model-utils==2.2
|
django-model-utils==2.2
|
||||||
django-mptt==0.7.4
|
django-mptt==0.7.4
|
||||||
django-rest-swagger==0.3.3
|
django-rest-swagger==0.3.3
|
||||||
|
|||||||
Reference in New Issue
Block a user