8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-27 01:13:46 +00:00

Ajoute des paginateurs bootstrap/django

This commit is contained in:
Gabriel Detraz 2016-07-22 03:25:04 +02:00
parent 21221e8dd6
commit 545b71b8bf
7 changed files with 88 additions and 7 deletions

View file

@ -1,3 +1,18 @@
{% if facture_list.paginator %}
<ul class="pagination nav navbar-nav">
{% if facture_list.has_previous %}
<li><a href="?page={{ facture_list.previous_page_number }}">Suivantes</a></li>
{% endif %}
{% for page in facture_list.paginator.page_range %}
<li class="{% if facture_list.number == page %}active{% endif %}"><a href="?page={{page }}">{{ page }}</a></li>
{% endfor %}
{% if facture_list.has_next %}
<li> <a href="?page={{ facture_list.next_page_number }}">Précédentes</a></li>
{% endif %}
</ul>
{% endif %}
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>

View file

@ -4,6 +4,7 @@
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.shortcuts import render_to_response, get_object_or_404 from django.shortcuts import render_to_response, get_object_or_404
from django.core.context_processors import csrf from django.core.context_processors import csrf
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.template import Context, RequestContext, loader from django.template import Context, RequestContext, loader
from django.contrib.auth.decorators import login_required, permission_required from django.contrib.auth.decorators import login_required, permission_required
from django.contrib import messages from django.contrib import messages
@ -17,7 +18,7 @@ from .models import Facture, Article, Vente, Cotisation, Paiement, Banque
from .forms import NewFactureForm, TrezEditFactureForm, EditFactureForm, ArticleForm, DelArticleForm, PaiementForm, DelPaiementForm, BanqueForm, DelBanqueForm, NewFactureFormPdf, SelectArticleForm from .forms import NewFactureForm, TrezEditFactureForm, EditFactureForm, ArticleForm, DelArticleForm, PaiementForm, DelPaiementForm, BanqueForm, DelBanqueForm, NewFactureFormPdf, SelectArticleForm
from users.models import User from users.models import User
from .tex import render_tex from .tex import render_tex
from re2o.settings import ASSO_NAME, ASSO_ADDRESS_LINE1, ASSO_ADDRESS_LINE2, ASSO_SIRET, ASSO_EMAIL, ASSO_PHONE, LOGO_PATH from re2o.settings import ASSO_NAME, ASSO_ADDRESS_LINE1, ASSO_ADDRESS_LINE2, ASSO_SIRET, ASSO_EMAIL, ASSO_PHONE, LOGO_PATH, PAGINATION_NUMBER
from re2o import settings from re2o import settings
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
@ -341,6 +342,16 @@ def index_banque(request):
@permission_required('cableur') @permission_required('cableur')
def index(request): def index(request):
facture_list = Facture.objects.order_by('date').reverse() facture_list = Facture.objects.order_by('date').reverse()
paginator = Paginator(facture_list, PAGINATION_NUMBER)
page = request.GET.get('page')
try:
facture_list = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
facture_list = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
facture_list = paginator.page(paginator.num_pages)
return render(request, 'cotisations/index.html', {'facture_list': facture_list}) return render(request, 'cotisations/index.html', {'facture_list': facture_list})
@login_required @login_required

View file

@ -1,3 +1,18 @@
{% if machines_list.paginator %}
<ul class="pagination nav navbar-nav">
{% if machines_list.has_previous %}
<li><a href="?page={{ machines_list.previous_page_number }}">Suivants</a></li>
{% endif %}
{% for page in machines_list.paginator.page_range %}
<li class="{% if machines_list.number == page %}active{% endif %}"><a href="?page={{page }}">{{ page }}</a></li>
{% endfor %}
{% if machines_list.has_next %}
<li> <a href="?page={{ machines_list.next_page_number }}">Précédents</a></li>
{% endif %}
</ul>
{% endif %}
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>

View file

@ -5,6 +5,7 @@ from django.http import HttpResponse
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.shortcuts import render_to_response, get_object_or_404 from django.shortcuts import render_to_response, get_object_or_404
from django.core.context_processors import csrf from django.core.context_processors import csrf
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.template import Context, RequestContext, loader from django.template import Context, RequestContext, loader
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required from django.contrib.auth.decorators import login_required, permission_required
@ -21,6 +22,7 @@ import re
from .forms import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm, MachineTypeForm, DelMachineTypeForm, ExtensionForm, DelExtensionForm, BaseEditInterfaceForm, BaseEditMachineForm from .forms import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm, MachineTypeForm, DelMachineTypeForm, ExtensionForm, DelExtensionForm, BaseEditInterfaceForm, BaseEditMachineForm
from .models import Machine, Interface, IpList, MachineType, Extension from .models import Machine, Interface, IpList, MachineType, Extension
from users.models import User from users.models import User
from re2o.settings import PAGINATION_NUMBER
def full_domain_validator(request, interface): def full_domain_validator(request, interface):
""" Validation du nom de domaine, extensions dans type de machine, prefixe pas plus long que 63 caractères """ """ Validation du nom de domaine, extensions dans type de machine, prefixe pas plus long que 63 caractères """
@ -313,6 +315,16 @@ def del_extension(request):
@permission_required('cableur') @permission_required('cableur')
def index(request): def index(request):
machines_list = Machine.objects.order_by('pk') machines_list = Machine.objects.order_by('pk')
paginator = Paginator(machines_list, PAGINATION_NUMBER)
page = request.GET.get('page')
try:
machines_list = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
machines_list = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
machines_list = paginator.page(paginator.num_pages)
return render(request, 'machines/index.html', {'machines_list': machines_list}) return render(request, 'machines/index.html', {'machines_list': machines_list})
@login_required @login_required

View file

@ -131,3 +131,4 @@ RIGHTS_LINK = {
'bofh' : ['bureau','trésorier'], 'bofh' : ['bureau','trésorier'],
} }
PAGINATION_NUMBER = 5

View file

@ -1,3 +1,18 @@
{% if users_list.paginator %}
<ul class="pagination nav navbar-nav">
{% if users_list.has_previous %}
<li><a href="?page={{ users_list.previous_page_number }}">Suivants</a></li>
{% endif %}
{% for page in users_list.paginator.page_range %}
<li class="{% if users_list.number == page %}active{% endif %}"><a href="?page={{page }}">{{ page }}</a></li>
{% endfor %}
{% if users_list.has_next %}
<li> <a href="?page={{ users_list.next_page_number }}">Précédents</a></li>
{% endif %}
</ul>
{% endif %}
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>

View file

@ -3,6 +3,7 @@
# Gplv2 # Gplv2
from django.shortcuts import render_to_response, get_object_or_404, render, redirect from django.shortcuts import render_to_response, get_object_or_404, render, redirect
from django.core.context_processors import csrf from django.core.context_processors import csrf
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.template import Context, RequestContext, loader from django.template import Context, RequestContext, loader
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required from django.contrib.auth.decorators import login_required, permission_required
@ -14,7 +15,7 @@ from django.core.urlresolvers import reverse
from django.db import transaction from django.db import transaction
from reversion import revisions as reversion from reversion import revisions as reversion
from users.models import User, Right, Ban, Whitelist, School, Request from users.models import User, Right, Ban, Whitelist, School, ListRight, Request
from users.models import DelRightForm, BanForm, WhitelistForm, DelSchoolForm from users.models import DelRightForm, BanForm, WhitelistForm, DelSchoolForm
from users.models import InfoForm, BaseInfoForm, StateForm, RightForm, SchoolForm from users.models import InfoForm, BaseInfoForm, StateForm, RightForm, SchoolForm
from cotisations.models import Facture from cotisations.models import Facture
@ -23,7 +24,7 @@ from users.forms import PassForm, ResetPasswordForm
from machines.views import unassign_ips, assign_ips from machines.views import unassign_ips, assign_ips
from re2o.login import hashNT from re2o.login import hashNT
from re2o.settings import REQ_EXPIRE_STR, EMAIL_FROM, ASSO_NAME, ASSO_EMAIL, SITE_NAME from re2o.settings import REQ_EXPIRE_STR, EMAIL_FROM, ASSO_NAME, ASSO_EMAIL, SITE_NAME, PAGINATION_NUMBER
def archive(user): def archive(user):
""" Archive un utilisateur """ """ Archive un utilisateur """
@ -182,13 +183,14 @@ def add_right(request, userid):
@login_required @login_required
@permission_required('bureau') @permission_required('bureau')
def del_right(request): def del_right(request):
right = DelRightForm(request.POST or None) user_right_list = DelRightForm(request.POST or None)
if right.is_valid(): right_list = ListRight.objects.all()
right_del = right.cleaned_data['rights'] if user_right_list.is_valid():
right_del = user_right_list.cleaned_data['rights']
right_del.delete() right_del.delete()
messages.success(request, "Droit retiré avec succès") messages.success(request, "Droit retiré avec succès")
return redirect("/users/") return redirect("/users/")
return form({'userform': right}, 'users/user.html', request) return form({'user_right_list': user_right_list, 'right_list': right_list}, 'users/index_rights.html', request)
@login_required @login_required
@permission_required('bofh') @permission_required('bofh')
@ -329,6 +331,16 @@ def del_school(request):
@permission_required('cableur') @permission_required('cableur')
def index(request): def index(request):
users_list = User.objects.order_by('pk') users_list = User.objects.order_by('pk')
paginator = Paginator(users_list, PAGINATION_NUMBER)
page = request.GET.get('page')
try:
users_list = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
users_list = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
users_list = paginator.page(paginator.num_pages)
return render(request, 'users/index.html', {'users_list': users_list}) return render(request, 'users/index.html', {'users_list': users_list})
@login_required @login_required