diff --git a/logs/templates/logs/aff_summary.html b/logs/templates/logs/aff_summary.html index c9abd16f..9b791dfd 100644 --- a/logs/templates/logs/aff_summary.html +++ b/logs/templates/logs/aff_summary.html @@ -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., - {% for rev in reversions_list %} - {% if rev.rev.content_type.name == 'ban' %} + {% for v in versions_list %} + {% if v.version.content_type.model == 'ban' %} - {{ rev.datetime }} + {{ v.datetime }} - {{ rev.username }} a banni - {{ rev.rev.object.user.get_username }} + {{ v.username }} a banni + {{ v.version.object.user.get_username }} ( - {% if rev.rev.object.raison == '' %} + {% if v.version.object.raison == '' %} Aucune raison {% else %} - {{ rev.rev.object.raison }} + {{ v.version.object.raison }} {% endif %} ) {% if is_bureau %} - + Annuler {% endif %} - {% elif rev.rev.content_type.name == 'whitelist' %} + {% elif v.version.content_type.model == 'whitelist' %} - {{ rev.datetime }} + {{ v.datetime }} - {{ rev.username }} a autorisé gracieusement - {{ rev.rev.object.user.get_username }} + {{ v.username }} a autorisé gracieusement + {{ v.version.object.user.get_username }} ( - {% if rev.rev.object.raison == '' %} + {% if v.version.object.raison == '' %} Aucune raison {% else %} - {{ rev.rev.object.raison }} + {{ v.version.object.raison }} {% endif %} ) {% if is_bureau %} - + Annuler {% endif %} - {% elif rev.rev.content_type.name == 'user' %} + {% elif v.version.content_type.model == 'user' %} - {{ rev.datetime }} + {{ v.datetime }} - {{ rev.username }} a mis à jour - {{ rev.rev.object.get_username }} - {% if rev.comment != '' %} - ({{ rev.comment }}) + {{ v.username }} a mis à jour + {{ v.version.object.get_username }} + {% if v.comment != '' %} + ({{ v.comment }}) {% endif %} {% if is_bureau %} - + Annuler {% endif %} - {% elif rev.rev.content_type.name == 'vente' %} + {% elif v.version.content_type.model == 'vente' %} - {{ rev.datetime }} + {{ v.datetime }} - {{ rev.username }} a vendu {{ rev.rev.object.number }}x {{ rev.rev.object.name }} à - {{ rev.rev.object.facture.user.get_username }} - {% if rev.rev.object.iscotisation %} - (+{{ rev.rev.object.duration }} mois) + {{ v.username }} a vendu {{ v.version.object.number }}x {{ v.version.object.name }} à + {{ v.version.object.facture.user.get_username }} + {% if v.version.object.iscotisation %} + (+{{ v.version.object.duration }} mois) {% endif %} {% if is_bureau %} - + Annuler {% endif %} - {% elif rev.rev.content_type.name == 'interface' %} + {% elif v.version.content_type.model == 'interface' %} - {{ rev.datetime }} + {{ v.datetime }} - {{ rev.username }} a modifié une interface de - {{ rev.rev.object.machine.user.get_username }} - {% if rev.comment != '' %} - ({{ rev.comment }}) + {{ v.username }} a modifié une interface de + {{ v.version.object.machine.user.get_username }} + {% if v.comment != '' %} + ({{ v.comment }}) {% endif %} {% if is_bureau %} - + Annuler diff --git a/logs/templates/logs/index.html b/logs/templates/logs/index.html index 487f924e..a120a531 100644 --- a/logs/templates/logs/index.html +++ b/logs/templates/logs/index.html @@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% block content %}

Actions effectuées

- {% include "logs/aff_summary.html" with reversions_list=reversions_list %} + {% include "logs/aff_summary.html" with versions_list=versions_list %}


diff --git a/logs/views.py b/logs/views.py index 983c4d11..7e88237d 100644 --- a/logs/views.py +++ b/logs/views.py @@ -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')