Replace django-pagination with django-pure-pagination and use Django's native CBV pagination context.

This commit is contained in:
Roberto Rosario
2015-08-15 02:28:37 -04:00
parent 016231a0f5
commit 702bac8ed2
7 changed files with 34 additions and 22 deletions

View File

@@ -31,6 +31,7 @@ What's new in Mayan EDMS v2.0
* South
* GitPython
* django-pagination
* psutil
* python-hkp
* sendfile
@@ -52,6 +53,7 @@ What's new in Mayan EDMS v2.0
* PyYAML
* django-autoadmin
* django-pure-pagination
* djangorestframework-recursive
* Permissions refactor
@@ -79,6 +81,7 @@ What's new in Mayan EDMS v2.0
* Improved API
* Text parsers and OCR backend are used in tandem.
* Invert page title/project name order in browser title.
* Use Django's class based views pagination
Upgrading from a previous version
=================================

View File

@@ -2,18 +2,20 @@
{% load static %}
{% load common_tags %}
{% load pagination_tags %}
{% load navigation_tags %}
{% autopaginate object_list %}
<div class="row">
<div class="col-xs-12">
<h4>
{% ifnotequal page_obj.paginator.num_pages 1 %}
{% if page_obj %}
{% 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 %}
{% endifnotequal %}
{% endif %}
{% else %}
{% blocktrans with object_list|length as total %}Total: {{ total }}{% endblocktrans %}
{% endif %}
</h4>
<hr>
@@ -119,7 +121,7 @@
</div>
{% endif %}
</form>
{% paginate %}
{% include 'pagination/pagination.html' %}
</div>
</div>
</div>

View File

@@ -1,27 +1,27 @@
{% if is_paginated %}
<ul class="pagination pagination-sm">
{% if page_obj.has_previous %}
<li><a href="?page={{ page_obj.previous_page_number }}{{ getvars }}">&lsaquo;&lsaquo;</a></li>
<li><a href="?{{ page_obj.previous_page_number.querystring }}">&lsaquo;&lsaquo;</a></li>
{% else %}
<li class="disabled"><a href="#">&lsaquo;&lsaquo;</a></li>
{% endif %}
{% for page in pages %}
{% for page in page_obj.pages %}
{% if page %}
{% ifequal page page_obj.number %}
<li class="active"><a href="#">{{ page }}</a></li>
{% else %}
<li><a href="?page={{ page }}{{ getvars }}{{ hashtag }}">{{ page }}</a></li>
<li><a href="?{{ page.querystring }}">{{ page }}</a></li>
{% endifequal %}
{% else %}
<span class="disabled">...</span>
<li class="disabled"><a href="#" class="disabled">...</a></li>
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
<li><a href="?page={{ page_obj.next_page_number }}{{ getvars }}">&rsaquo;&rsaquo;</a></li>
<li><a href="?{{ page_obj.next_page_number.querystring }}">&rsaquo;&rsaquo;</a></li>
{% else %}
<li class="disabled"><a href="#">&rsaquo;&rsaquo;</a></li>
{% endif %}

View File

@@ -12,12 +12,14 @@ from django.views.generic.detail import SingleObjectMixin
from django.views.generic.edit import CreateView, DeleteView, UpdateView
from django.views.generic.list import ListView
from pure_pagination.mixins import PaginationMixin
from .forms import ChoiceForm
from .mixins import (
ExtraContextMixin, ObjectListPermissionFilterMixin,
ObjectPermissionCheckMixin, RedirectionMixin, ViewPermissionCheckMixin
)
from .settings import setting_paginate_by
__all__ = (
'AssignRemoveView', 'ConfirmView', 'MultiFormView', 'ParentChildListView',
@@ -430,5 +432,6 @@ class SingleObjectEditView(ViewPermissionCheckMixin, ObjectPermissionCheckMixin,
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'

View File

@@ -17,3 +17,8 @@ setting_shared_storage = namespace.add_setting(
default='storage.backends.filebasedstorage.FileBasedStorage',
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.')
)

View File

@@ -58,6 +58,7 @@ INSTALLED_APPS = (
'djcelery',
'filetransfers',
'mptt',
'pure_pagination',
'rest_framework',
'rest_framework.authtoken',
'solo',
@@ -97,9 +98,6 @@ INSTALLED_APPS = (
'tags.apps.TagsApp',
# Placed after rest_api to allow template overriding
'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 = (
@@ -114,7 +112,6 @@ MIDDLEWARE_CLASSES = (
'common.middleware.timezone.TimezoneMiddleware',
'common.middleware.strip_spaces_widdleware.SpacelessMiddleware',
'authentication.middleware.login_required_middleware.LoginRequiredMiddleware',
'pagination.middleware.PaginationMiddleware',
'common.middleware.ajax_redirect.AjaxRedirect',
)
@@ -239,9 +236,6 @@ LOGIN_EXEMPT_URLS = (
r'^api/',
)
# --------- Pagination ----------------
PAGINATION_INVALID_PAGE_RAISES_404 = True
PAGINATION_DEFAULT_PAGINATION = 40
# ---------- Django REST framework -----------
REST_FRAMEWORK = {
'PAGINATE_BY': 10,
@@ -253,6 +247,11 @@ REST_FRAMEWORK = {
'rest_framework.authentication.SessionAuthentication',
)
}
# --------- Pagination --------
PAGINATION_SETTINGS = {
'PAGE_RANGE_DISPLAYED': 8,
'MARGIN_PAGES_DISPLAYED': 2,
}
# ----------- Celery ----------
CELERY_ACCEPT_CONTENT = ('json',)
CELERY_ALWAYS_EAGER = True

View File

@@ -13,7 +13,7 @@ django-colorful==1.1.0
django-compressor==1.5
django-cors-headers==1.1.0
django-filetransfers==0.1.0
django-pagination==1.0.7
django-pure-pagination==0.2.1
django-model-utils==2.2
django-mptt==0.7.4
django-rest-swagger==0.3.3