8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-23 23:43:47 +00:00

Déplace une partie des vérif dans views pour alléger le template

This commit is contained in:
Maël Kervella 2017-09-10 14:17:59 +00:00 committed by Pierre Cadart
parent 7941633d91
commit 357b794fad
3 changed files with 63 additions and 83 deletions

View file

@ -36,76 +36,51 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<th></th>
</tr>
</thead>
{% for revision in revisions_list %}
{% for reversion in revision.revision.version_set.all %}
{% if reversion.content_type.name in 'ban,whitelist,user,vente,interface'|slice:',' %}
<tr>
<td>{{ revision.datetime }}</td>
{% if reversion.content_type.name == 'ban' %}
<td>
{% if revision.revision.user.et_username %}
{{ revision.revision.user.get_username }}
{% else %}
?
{% endif %}
a banni
<a href="{% url 'users:profil' reversion.object.user_id %}">{{ reversion.object.user.get_username }}</a>
(<i>{{ reversion.object.raison }}</i>)
</td>
{% elif reversion.content_type.name == 'whitelist' %}
<td>
{% if revision.revision.user.get_username %}
{{ revision.revision.user.get_username }}
{% else %}
?
{% endif %}
a autorisé gracieusement
<a href="{% url 'users:profil' reversion.object.user_id %}">{{ reversion.object.user.get_username }}</a>
(<i>{{ reversion.object.raison }}</i>)
</td>
{% elif reversion.content_type.name == 'user' %}
<td>
{% if revision.revision.user.get_username %}
{{ revision.revision.user.get_username }}
{% else %}
?
{% endif %}
a ajouté
<a href="{% url 'users:profil' reversion.object.id %}">{{ reversion.object.get_username }}</a>
</td>
{% elif reversion.content_type.name == 'vente' %}
<td>
<a href="{% url 'users:profil' reversion.object.facture.user_id %}">{{ reversion.object.facture.user.get_username }}</a>
a acheté
{{ reversion.object.number }}x {{ reversion.object.name }}
{% if reversion.object.iscotisation %}
(<i>+{{ reversion.object.duration }} mois</i>)
{% endif %}
</td>
{% elif reversion.content_type.name == 'interface' %}
<td>
{% if revision.revision.user.get_username %}
{{ revision.revision.user.get_username }}
{% else %}
?
{% endif %}
a ajouté une interface à
<a href="{% url 'users:profil' reversion.object.machine.user_id %}">{{ reversion.object.machine.user.get_username }}</a>
(<i>MAC : {{ reversion.object.mac_bare }}</i>)
</td>
{% endif %}
{% if is_bureau %}
<td>
<a class="btn btn-danger btn-sm" role="button" href="{% url 'logs:revert-action' revision.revision.id %}">
<i class="glyphicon glyphicon-remove"></i>
Annuler
</a>
</td>
{% endif %}
</tr>
{% endif %}
{% endfor %}
{% endfor %}
{% for rev in reversions_list %}
<tr>
<td>{{ rev.datetime }}</td>
{% if rev.rev.content_type.name == 'ban' %}
<td>
{{ rev.username }} a banni
<a href="{% url 'users:profil' rev.rev.object.user_id %}">{{ rev.rev.object.user.get_username }}</a>
(<i>{{ rev.rev.object.raison }}</i>)
</td>
{% elif rev.rev.content_type.name == 'whitelist' %}
<td>
{{ rev.username }} a autorisé gracieusement
<a href="{% url 'users:profil' rev.rev.object.user_id %}">{{ rev.rev.object.user.get_username }}</a>
(<i>{{ rev.rev.object.raison }}</i>)
</td>
{% elif rev.rev.content_type.name == 'user' %}
<td>
{{ rev.username }} a ajouté
<a href="{% url 'users:profil' rev.rev.object.id %}">{{ rev.rev.object.get_username }}</a>
</td>
{% elif rev.rev.content_type.name == 'vente' %}
<td>
<a href="{% url 'users:profil' rev.rev.object.facture.user_id %}">{{ rev.rev.object.facture.user.get_username }}</a>
a acheté {{ rev.rev.object.number }}x {{ rev.rev.object.name }}
{% if rev.rev.object.iscotisation %}
(<i>+{{ rev.rev.object.duration }} mois</i>)
{% endif %}
</td>
{% elif rev.rev.content_type.name == 'interface' %}
<td>
{{ rev.username }} a ajouté une interface à
<a href="{% url 'users:profil' rev.rev.object.machine.user_id %}">{{ rev.rev.object.machine.user.get_username }}</a>
(<i>MAC : {{ rev.rev.object.mac_bare }}</i>)
</td>
{% endif %}
{% if is_bureau %}
<td>
<a class="btn btn-danger btn-sm" role="button" href="{% url 'logs:revert-action' rev.id %}">
<i class="glyphicon glyphicon-remove"></i>
Annuler
</a>
</td>
{% endif %}
</tr>
{% endfor %}
</table>

View file

@ -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 revisions_list=revisions_list %}
{% include "logs/aff_summary.html" with reversions_list=reversions_list %}
<br />
<br />
<br />

View file

@ -70,26 +70,31 @@ def index(request):
options, created = GeneralOption.objects.get_or_create()
pagination_number = options.pagination_number
revisions_not_filtered = Revision.objects.all().order_by('date_created').reverse().select_related('user').prefetch_related('version_set__object')
revisions = []
for revision in revisions_not_filtered :
reversions = revision.version_set.all()
for reversion in reversions :
if reversion.content_type.name in ['ban', 'whitelist', 'vente', 'cotisation', 'interface', 'machine', 'user'] :
revisions.append( {'datetime':revision.date_created.strftime('%d/%m/%y %H:%M:%S'), 'revision':revision } )
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() :
if reversion.content_type.name in ['ban', 'whitelist', 'vente', 'cotisation', 'interface', 'user'] :
reversions.append(
{'id' : revision.id,
'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
paginator = Paginator(revisions, pagination_number)
paginator = Paginator(reversions, pagination_number)
page = request.GET.get('page')
try:
revisions = paginator.page(page)
reversions = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
revisions = paginator.page(1)
reversions = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
revisions = paginator.page(paginator.num_pages)
return render(request, 'logs/index.html', {'revisions_list': revisions})
reversions = paginator.page(paginator.num_pages)
return render(request, 'logs/index.html', {'reversions_list': reversions})
@login_required
@permission_required('cableur')