8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-26 08:53:46 +00:00

Fix rapidité, fait le tri (boucle for) après le paginator pour pas dépasser 20-25 elts dans la boucle for

This commit is contained in:
Maël Kervella 2017-09-21 09:39:27 +00:00 committed by Pierre Cadart
parent 1923b0950b
commit 62fe8360bc

View file

@ -23,6 +23,9 @@
# App de gestion des statistiques pour re2o # App de gestion des statistiques pour re2o
# Gabriel Détraz # Gabriel Détraz
# Gplv2 # Gplv2
from __future__ import unicode_literals
from django.http import HttpResponse from django.http import HttpResponse
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
@ -76,30 +79,39 @@ def index(request):
# Select only wanted versions # Select only wanted versions
versions = Version.objects.filter(content_type__in=ContentType.objects.filter(model__in=content_type_filter)).order_by('revision__date_created').reverse().select_related('revision') versions = Version.objects.filter(content_type__in=ContentType.objects.filter(model__in=content_type_filter)).order_by('revision__date_created').reverse().select_related('revision')
# Setup nice struct for template paginator = Paginator(versions, pagination_number)
versions_list = [] page = request.GET.get('page')
for v in versions : try:
if v.object : versions = paginator.page(page)
versions_list.append( except PageNotAnInteger:
{'rev_id' : v.revision.id, # If page is not an integer, deliver first page.
versions = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
versions = paginator.page(paginator.num_pages)
# Force to have a list instead of QuerySet
versions.count(0)
# Items to remove later because invalid
to_remove = []
# Parse every item (max = pagination_number)
for i in range( len( versions.object_list ) ):
if versions.object_list[i].object :
v = versions.object_list[i]
versions.object_list[i] = {
'rev_id' : v.revision.id,
'comment': v.revision.comment, 'comment': v.revision.comment,
'datetime': v.revision.date_created.strftime('%d/%m/%y %H:%M:%S'), 'datetime': v.revision.date_created.strftime('%d/%m/%y %H:%M:%S'),
'username': v.revision.user.get_username() if v.revision.user else '?', 'username': v.revision.user.get_username() if v.revision.user else '?',
'user_id': v.revision.user_id, 'user_id': v.revision.user_id,
'version': v } 'version': v }
) else :
to_remove.append(i)
# Remove all tagged invalid items
for i in to_remove :
versions.object_list.pop(i)
paginator = Paginator(versions_list, pagination_number) return render(request, 'logs/index.html', {'versions_list': versions})
page = request.GET.get('page')
try:
versions_list = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
versions_list = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
versions_list = paginator.page(paginator.num_pages)
return render(request, 'logs/index.html', {'versions_list': versions_list})
@login_required @login_required
@permission_required('cableur') @permission_required('cableur')