Commit 5c14ac1f authored by chirac's avatar chirac

PAginateurs sur l'historique

parent b57ef3ee
......@@ -387,4 +387,14 @@ def history(request, object, id):
messages.error(request, "Objet inconnu")
return redirect("/cotisations/")
reversions = reversion.get_for_object(object_instance)
paginator = Paginator(reversions, PAGINATION_NUMBER)
page = request.GET.get('page')
try:
reversions = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
reversions = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
reversions = paginator.page(paginator.num_pages)
return render(request, 're2o/history.html', {'reversions': reversions, 'object': object_instance})
......@@ -22,7 +22,7 @@ import re
from .forms import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm, MachineTypeForm, DelMachineTypeForm, ExtensionForm, DelExtensionForm, BaseEditInterfaceForm, BaseEditMachineForm
from .models import Machine, Interface, IpList, MachineType, Extension
from users.models import User
from re2o.settings import PAGINATION_NUMBER
from re2o.settings import PAGINATION_NUMBER, PAGINATION_LARGE_NUMBER
def full_domain_validator(request, interface):
""" Validation du nom de domaine, extensions dans type de machine, prefixe pas plus long que 63 caractères """
......@@ -315,7 +315,7 @@ def del_extension(request):
@permission_required('cableur')
def index(request):
machines_list = Machine.objects.order_by('pk')
paginator = Paginator(machines_list, PAGINATION_NUMBER)
paginator = Paginator(machines_list, PAGINATION_LARGE_NUMBER)
page = request.GET.get('page')
try:
machines_list = paginator.page(page)
......@@ -375,6 +375,16 @@ def history(request, object, id):
messages.error(request, "Objet inconnu")
return redirect("/machines/")
reversions = reversion.get_for_object(object_instance)
paginator = Paginator(reversions, PAGINATION_NUMBER)
page = request.GET.get('page')
try:
reversions = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
reversions = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
reversions = paginator.page(paginator.num_pages)
return render(request, 're2o/history.html', {'reversions': reversions, 'object': object_instance})
......
......@@ -133,4 +133,6 @@ RIGHTS_LINK = {
'bofh' : ['bureau','trésorier'],
}
PAGINATION_NUMBER = 5
PAGINATION_NUMBER = 25
PAGINATION_LARGE_NUMBER = 8
{% if reversions.paginator %}
<ul class="pagination nav navbar-nav">
{% if reversions.has_previous %}
<li><a href="?page={{ reversions.previous_page_number }}">Suivants</a></li>
{% endif %}
{% for page in reversions.paginator.page_range %}
<li class="{% if reversions.number == page %}active{% endif %}"><a href="?page={{page }}">{{ page }}</a></li>
{% endfor %}
{% if reversions.has_next %}
<li> <a href="?page={{ reversions.next_page_number }}">Précédents</a></li>
{% endif %}
</ul>
{% endif %}
<table class="table table-striped">
<thead>
<tr>
......
......@@ -3,12 +3,15 @@ from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required
from django.db import IntegrityError
from django.db import transaction
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from reversion import revisions as reversion
from topologie.models import Switch, Port, Room
from topologie.forms import EditPortForm, EditSwitchForm, AddPortForm, EditRoomForm
from users.views import form
from re2o.settings import PAGINATION_NUMBER
@login_required
@permission_required('cableur')
def index(request):
......@@ -40,6 +43,16 @@ def history(request, object, id):
messages.error(request, "Objet inconnu")
return redirect("/topologie/")
reversions = reversion.get_for_object(object_instance)
paginator = Paginator(reversions, PAGINATION_NUMBER)
page = request.GET.get('page')
try:
reversions = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
reversions = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
reversions = paginator.page(paginator.num_pages)
return render(request, 're2o/history.html', {'reversions': reversions, 'object': object_instance})
@login_required
......
......@@ -467,6 +467,16 @@ def history(request, object, id):
messages.error(request, "Objet inconnu")
return redirect("/users/")
reversions = reversion.get_for_object(object_instance)
paginator = Paginator(reversions, PAGINATION_NUMBER)
page = request.GET.get('page')
try:
reversions = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
reversions = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
reversions = paginator.page(paginator.num_pages)
return render(request, 're2o/history.html', {'reversions': reversions, 'object': object_instance})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment