mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-28 01:43:46 +00:00
Utilisation de QuerySet pour selectionner les versions voulues
Optimise plutôt que de devoir faire une fat boucle for sur l'ensemble Fix l'affichage du paginator
This commit is contained in:
parent
fadcbc9b31
commit
689d0c7912
3 changed files with 62 additions and 66 deletions
|
@ -22,8 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
{% endcomment %}
|
||||
|
||||
{% if revisions_list.paginator %}
|
||||
{% include "pagination.html" with list=revisions_list %}
|
||||
{% if versions_list.paginator %}
|
||||
{% include "pagination.html" with list=versions_list %}
|
||||
{% endif %}
|
||||
|
||||
{% load logs_extra %}
|
||||
|
@ -36,104 +36,104 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for rev in reversions_list %}
|
||||
{% if rev.rev.content_type.name == 'ban' %}
|
||||
{% for v in versions_list %}
|
||||
{% if v.version.content_type.model == 'ban' %}
|
||||
<tr class="danger">
|
||||
<td>{{ rev.datetime }}</td>
|
||||
<td>{{ v.datetime }}</td>
|
||||
<td>
|
||||
{{ rev.username }} a banni
|
||||
<a href="{% url 'users:profil' rev.rev.object.user_id %}">{{ rev.rev.object.user.get_username }}</a>
|
||||
{{ v.username }} a banni
|
||||
<a href="{% url 'users:profil' v.version.object.user_id %}">{{ v.version.object.user.get_username }}</a>
|
||||
(<i>
|
||||
{% if rev.rev.object.raison == '' %}
|
||||
{% if v.version.object.raison == '' %}
|
||||
Aucune raison
|
||||
{% else %}
|
||||
{{ rev.rev.object.raison }}
|
||||
{{ v.version.object.raison }}
|
||||
{% endif %}
|
||||
</i>)
|
||||
</td>
|
||||
{% if is_bureau %}
|
||||
<td>
|
||||
<a class="btn btn-danger btn-sm" role="button" href="{% url 'logs:revert-action' rev.id %}">
|
||||
<a class="btn btn-danger btn-sm" role="button" href="{% url 'logs:revert-action' v.rev_id %}">
|
||||
<i class="glyphicon glyphicon-remove"></i>
|
||||
Annuler
|
||||
</a>
|
||||
</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% elif rev.rev.content_type.name == 'whitelist' %}
|
||||
{% elif v.version.content_type.model == 'whitelist' %}
|
||||
<tr class="success">
|
||||
<td>{{ rev.datetime }}</td>
|
||||
<td>{{ v.datetime }}</td>
|
||||
<td>
|
||||
{{ rev.username }} a autorisé gracieusement
|
||||
<a href="{% url 'users:profil' rev.rev.object.user_id %}">{{ rev.rev.object.user.get_username }}</a>
|
||||
{{ v.username }} a autorisé gracieusement
|
||||
<a href="{% url 'users:profil' v.version.object.user_id %}">{{ v.version.object.user.get_username }}</a>
|
||||
(<i>
|
||||
{% if rev.rev.object.raison == '' %}
|
||||
{% if v.version.object.raison == '' %}
|
||||
Aucune raison
|
||||
{% else %}
|
||||
{{ rev.rev.object.raison }}
|
||||
{{ v.version.object.raison }}
|
||||
{% endif %}
|
||||
</i>)
|
||||
</td>
|
||||
{% if is_bureau %}
|
||||
<td>
|
||||
<a class="btn btn-danger btn-sm" role="button" href="{% url 'logs:revert-action' rev.id %}">
|
||||
<a class="btn btn-danger btn-sm" role="button" href="{% url 'logs:revert-action' v.rev_id %}">
|
||||
<i class="glyphicon glyphicon-remove"></i>
|
||||
Annuler
|
||||
</a>
|
||||
</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% elif rev.rev.content_type.name == 'user' %}
|
||||
{% elif v.version.content_type.model == 'user' %}
|
||||
<tr>
|
||||
<td>{{ rev.datetime }}</td>
|
||||
<td>{{ v.datetime }}</td>
|
||||
<td>
|
||||
{{ rev.username }} a mis à jour
|
||||
<a href="{% url 'users:profil' rev.rev.object.id %}">{{ rev.rev.object.get_username }}</a>
|
||||
{% if rev.comment != '' %}
|
||||
(<i>{{ rev.comment }}</i>)
|
||||
{{ v.username }} a mis à jour
|
||||
<a href="{% url 'users:profil' v.version.object.id %}">{{ v.version.object.get_username }}</a>
|
||||
{% if v.comment != '' %}
|
||||
(<i>{{ v.comment }}</i>)
|
||||
{% endif %}
|
||||
</td>
|
||||
{% if is_bureau %}
|
||||
<td>
|
||||
<a class="btn btn-danger btn-sm" role="button" href="{% url 'logs:revert-action' rev.id %}">
|
||||
<a class="btn btn-danger btn-sm" role="button" href="{% url 'logs:revert-action' v.rev_id %}">
|
||||
<i class="glyphicon glyphicon-remove"></i>
|
||||
Annuler
|
||||
</a>
|
||||
</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% elif rev.rev.content_type.name == 'vente' %}
|
||||
{% elif v.version.content_type.model == 'vente' %}
|
||||
<tr>
|
||||
<td>{{ rev.datetime }}</td>
|
||||
<td>{{ v.datetime }}</td>
|
||||
<td>
|
||||
{{ rev.username }} a vendu {{ rev.rev.object.number }}x {{ rev.rev.object.name }} à
|
||||
<a href="{% url 'users:profil' rev.rev.object.facture.user_id %}">{{ rev.rev.object.facture.user.get_username }}</a>
|
||||
{% if rev.rev.object.iscotisation %}
|
||||
(<i>+{{ rev.rev.object.duration }} mois</i>)
|
||||
{{ v.username }} a vendu {{ v.version.object.number }}x {{ v.version.object.name }} à
|
||||
<a href="{% url 'users:profil' v.version.object.facture.user_id %}">{{ v.version.object.facture.user.get_username }}</a>
|
||||
{% if v.version.object.iscotisation %}
|
||||
(<i>+{{ v.version.object.duration }} mois</i>)
|
||||
{% endif %}
|
||||
</td>
|
||||
{% if is_bureau %}
|
||||
<td>
|
||||
<a class="btn btn-danger btn-sm" role="button" href="{% url 'logs:revert-action' rev.id %}">
|
||||
<a class="btn btn-danger btn-sm" role="button" href="{% url 'logs:revert-action' v.rev_id %}">
|
||||
<i class="glyphicon glyphicon-remove"></i>
|
||||
Annuler
|
||||
</a>
|
||||
</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% elif rev.rev.content_type.name == 'interface' %}
|
||||
{% elif v.version.content_type.model == 'interface' %}
|
||||
<tr>
|
||||
<td>{{ rev.datetime }}</td>
|
||||
<td>{{ v.datetime }}</td>
|
||||
<td>
|
||||
{{ rev.username }} a modifié une interface de
|
||||
<a href="{% url 'users:profil' rev.rev.object.machine.user_id %}">{{ rev.rev.object.machine.user.get_username }}</a>
|
||||
{% if rev.comment != '' %}
|
||||
(<i>{{ rev.comment }}</i>)
|
||||
{{ v.username }} a modifié une interface de
|
||||
<a href="{% url 'users:profil' v.version.object.machine.user_id %}">{{ v.version.object.machine.user.get_username }}</a>
|
||||
{% if v.comment != '' %}
|
||||
(<i>{{ v.comment }}</i>)
|
||||
{% endif %}
|
||||
</td>
|
||||
{% if is_bureau %}
|
||||
<td>
|
||||
<a class="btn btn-danger btn-sm" role="button" href="{% url 'logs:revert-action' rev.id %}">
|
||||
<a class="btn btn-danger btn-sm" role="button" href="{% url 'logs:revert-action' v.rev_id %}">
|
||||
<i class="glyphicon glyphicon-remove"></i>
|
||||
Annuler
|
||||
</a>
|
||||
|
|
|
@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
{% block content %}
|
||||
<h2>Actions effectuées</h2>
|
||||
{% include "logs/aff_summary.html" with reversions_list=reversions_list %}
|
||||
{% include "logs/aff_summary.html" with versions_list=versions_list %}
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
|
|
|
@ -37,7 +37,7 @@ from django.db import transaction
|
|||
from django.db.models import Count
|
||||
|
||||
from reversion.models import Revision
|
||||
from reversion.models import Version
|
||||
from reversion.models import Version, ContentType
|
||||
|
||||
from users.models import User, ServiceUser, Right, School, ListRight, ListShell, Ban, Whitelist
|
||||
from users.models import all_has_access, all_whitelisted, all_baned, all_adherent
|
||||
|
@ -70,40 +70,36 @@ def index(request):
|
|||
options, created = GeneralOption.objects.get_or_create()
|
||||
pagination_number = options.pagination_number
|
||||
|
||||
revisions = Revision.objects.all().order_by('date_created').reverse().select_related('user').prefetch_related('version_set__object')
|
||||
reversions = []
|
||||
for revision in revisions :
|
||||
for reversion in revision.version_set.all() :
|
||||
|
||||
content = ''
|
||||
try :
|
||||
content = reversion.content_type.name
|
||||
except :
|
||||
# If reversion has no content_type (when object has been deleted)
|
||||
pass
|
||||
# The types of content kept for display
|
||||
content_type_filter = ['ban', 'whitelist', 'vente', 'interface', 'user']
|
||||
|
||||
if content in ['ban', 'whitelist', 'vente', 'interface', 'user'] :
|
||||
reversions.append(
|
||||
{'id' : revision.id,
|
||||
'comment': revision.comment,
|
||||
'datetime': revision.date_created.strftime('%d/%m/%y %H:%M:%S'),
|
||||
'username': revision.user.get_username() if revision.user else '?',
|
||||
'user_id': revision.user_id,
|
||||
'rev': reversion }
|
||||
)
|
||||
break
|
||||
# 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')
|
||||
|
||||
paginator = Paginator(reversions, pagination_number)
|
||||
# Setup nice struct for template
|
||||
versions_list = []
|
||||
for v in versions :
|
||||
if v.object :
|
||||
versions_list.append(
|
||||
{'rev_id' : v.revision.id,
|
||||
'comment': v.revision.comment,
|
||||
'datetime': v.revision.date_created.strftime('%d/%m/%y %H:%M:%S'),
|
||||
'username': v.revision.user.get_username() if v.revision.user else '?',
|
||||
'user_id': v.revision.user_id,
|
||||
'version': v }
|
||||
)
|
||||
|
||||
paginator = Paginator(versions_list, pagination_number)
|
||||
page = request.GET.get('page')
|
||||
try:
|
||||
reversions = paginator.page(page)
|
||||
versions_list = paginator.page(page)
|
||||
except PageNotAnInteger:
|
||||
# If page is not an integer, deliver first page.
|
||||
reversions = paginator.page(1)
|
||||
versions_list = 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, 'logs/index.html', {'reversions_list': reversions})
|
||||
versions_list = paginator.page(paginator.num_pages)
|
||||
return render(request, 'logs/index.html', {'versions_list': versions_list})
|
||||
|
||||
@login_required
|
||||
@permission_required('cableur')
|
||||
|
|
Loading…
Reference in a new issue