Commit 626d4b9e authored by Amap's avatar Amap

corrige bug sur le paginateur multiple

parent 8e3a1d9e
......@@ -123,6 +123,6 @@ STATIC_ROOT = os.path.join(BASE_DIR, 'static_files')
RIGHTS_LINK = {
}
PAGINATION_NUMBER = 25
PAGINATION_NUMBER = 15
PAGINATION_LARGE_NUMBER = 8
......@@ -36,11 +36,18 @@ class LivraisonForm(ModelForm):
self.fields['date'].label = 'Date de livraison'
self.fields['date_modif'].label = 'Date limite de modification'
class DelLivraisonForm(ModelForm):
class SelectLivraisonForm(ModelForm):
date = forms.ModelMultipleChoiceField(queryset=Livraison.objects.all(), label="Date de livraison", widget=forms.CheckboxSelectMultiple)
class Meta:
exclude = ['date']
exclude = ['date', 'date_modif']
model = Livraison
class SelectOneLivraisonForm(ModelForm):
date = forms.ModelChoiceField(queryset=Livraison.objects.all(), label="Date de livraison")
class Meta:
exclude = ['date', 'date_modif']
model = Livraison
class PaiementForm(ModelForm):
......@@ -79,3 +86,4 @@ class CreditForm(ModelForm):
class CreditFullForm(CreditForm):
class Meta(CreditForm.Meta):
fields = '__all__'
......@@ -35,14 +35,18 @@
{% if paniers_list.paginator %}
<ul class="pagination nav navbar-nav">
{% if paniers_list.has_previous %}
<li><a href="?page={{ paniers_list.previous_page_number }}">Suivants</a></li>
<li><a href="?page1=1"> << </a></li>
<li><a href="?page1={{ paniers_list.previous_page_number }}">Suivants</a></li>
{% endif %}
{% for page in paniers_list.paginator.page_range %}
<li class="{% if paniers_list.number == page %}active{% endif %}"><a href="?page={{page }}">{{ page }}</a></li>
{% if paniers_list.number <= page|add:"3" and paniers_list.number >= page|add:"-3" %}
<li class="{% if paniers_list.number == page %}active{% endif %}"><a href="?page1={{page }}">{{ page }}</a></li>
{% endif %}
{% endfor %}
{% if paniers_list.has_next %}
<li> <a href="?page={{ paniers_list.next_page_number }}">Précédents</a></li>
<li> <a href="?page1={{ paniers_list.next_page_number }}">Précédents</a></li>
<li><a href2="?page1={{ paniers_list.paginator.page_range|length }}"> >> </a></li>
{% endif %}
</ul>
{% endif %}
......@@ -91,17 +95,21 @@
<h2>Credits</h2>
{% if paniers_list.paginator %}
{% if credit_list.paginator %}
<ul class="pagination nav navbar-nav">
{% if paniers_list.has_previous %}
<li><a href="?page={{ paniers_list.previous_page_number }}">Suivants</a></li>
{% if credit_list.has_previous %}
<li><a href="?page2=1"> << </a></li>
<li><a href="?page2={{ credit_list.previous_page_number }}">Suivants</a></li>
{% endif %}
{% for page in paniers_list.paginator.page_range %}
<li class="{% if paniers_list.number == page %}active{% endif %}"><a href="?page={{page }}">{{ page }}</a></li>
{% for page in credit_list.paginator.page_range %}
{% if credit_list.number <= page|add:"3" and credit_list.number >= page|add:"-3" %}
<li class="{% if credit_list.number == page %}active{% endif %}"><a href="?page2={{page }}">{{ page }}</a></li>
{% endif %}
{% endfor %}
{% if paniers_list.has_next %}
<li> <a href="?page={{ paniers_list.next_page_number }}">Précédents</a></li>
{% if credit_list.has_next %}
<li> <a href="?page2={{ credit_list.next_page_number }}">Précédents</a></li>
<li><a href2="?page2={{ credit_list.paginator.page_range|length }}"> >> </a></li>
{% endif %}
</ul>
{% endif %}
......
......@@ -5,9 +5,13 @@
{% block title %}Controle des livraisons{% endblock %}
{% block content %}
<h2>Etat des livraisons</h2>
<form class="form" method="post">
<h2>Date de livraison concernée</h2>
{% csrf_token %}
{% bootstrap_form livraisonform %}
<h2>Etat des livraisons</h2>
{{ controlform.management_form }}
<table class="table table-striped">
<thead>
......
......@@ -16,14 +16,14 @@ from django.http import HttpResponseRedirect
from django.db import transaction
from reversion import revisions as reversion
from .models import Panier, Paiement, Commande, Credit, Livraison
from .forms import PaiementForm, CreditForm, CreditFullForm, DelPaiementForm, LivraisonForm, DelLivraisonForm
from .forms import PaiementForm, CreditForm, CreditFullForm, DelPaiementForm, LivraisonForm, SelectOneLivraisonForm, SelectLivraisonForm
from .forms import PanierForm, DelPanierForm, SelectArticleForm, FullEditCommandeForm, BaseEditCommandeForm, NewCommandeForm
from django.forms import modelformset_factory, formset_factory
from users.views import User
from django.utils import timezone
from amap.settings import MINIMUM_LEVEL, PAGINATION_NUMBER
from amap.settings import MINIMUM_LEVEL, PAGINATION_LARGE_NUMBER, PAGINATION_NUMBER
def form(ctx, template, request):
c = ctx
......@@ -153,7 +153,7 @@ def edit_livraison(request, livraisonid):
@login_required
@permission_required('bureau')
def del_livraison(request):
livraison = DelLivraisonForm(request.POST or None)
livraison = SelectLivraisonForm(request.POST or None)
if livraison.is_valid():
livraison_dels = livraison.cleaned_data['date']
for livraison_del in livraison_dels:
......@@ -320,14 +320,18 @@ def del_article(request):
@login_required
@permission_required('bureau')
def control(request):
commande_list = Commande.objects.order_by('date').reverse()
livraison_select = Livraison.objects.order_by('date')[0]
livraison = SelectOneLivraisonForm(request.POST or None, initial = {'date': Livraison.objects.order_by('date')[0]})
if livraison.is_valid():
livraison_select = livraison.cleaned_data['date']
commande_list = Commande.objects.filter(date=livraison_select).order_by('date').reverse()
controlform_set = modelformset_factory(Commande, fields=('livre',), extra=0)
controlform = controlform_set(request.POST or None, queryset=commande_list)
if controlform.is_valid():
controlform.save()
messages.success(request, "Livraisons enregistrees")
return redirect("/panier/")
return render(request, 'panier/control.html', {'controlform': controlform})
return render(request, 'panier/control.html', {'livraisonform': livraison, 'controlform': controlform})
@login_required
@permission_required('bureau')
......@@ -423,16 +427,17 @@ def history(request, object, id):
@login_required
def index(request):
paniers_list = Commande.objects.order_by('pk').reverse()
paniers_list = Commande.objects.order_by('date').reverse()
credit_list = Credit.objects.order_by('pk').reverse()
if not request.user.has_perms(('bureau',)):
paniers_list = paniers_list.filter(user=request.user)
credit_list = credit_list.filter(user=request.user)
paginator_paniers = Paginator(paniers_list, PAGINATION_NUMBER)
paginator_paniers = Paginator(paniers_list, PAGINATION_LARGE_NUMBER)
paginator_credit = Paginator(credit_list, PAGINATION_NUMBER)
page = request.GET.get('page')
page1 = request.GET.get('page1')
page2 = request.GET.get('page2')
try:
paniers_list = paginator_paniers.page(page)
paniers_list = paginator_paniers.page(page1)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
paniers_list = paginator_paniers.page(1)
......@@ -440,7 +445,7 @@ def index(request):
# If page is out of range (e.g. 9999), deliver last page of results.
paniers_list = paginator_paniers.page(paginator_paniers.num_pages)
try:
credit_list = paginator_credit.page(page)
credit_list = paginator_credit.page(page2)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
credit_list = paginator_credit.page(1)
......
......@@ -163,7 +163,7 @@ class User(AbstractBaseUser):
return credit-debit
def __str__(self):
return self.pseudo
return self.name + " " + self.surname
class Right(models.Model):
user = models.ForeignKey('User', on_delete=models.PROTECT)
......
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