From 9613d00256229da0fa8a3a40776aa670a31efef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sat, 9 Sep 2017 18:59:51 +0000 Subject: [PATCH 01/11] =?UTF-8?q?Duplique=20l'affichage=20des=20=C3=A9vene?= =?UTF-8?q?ment=20dans=20une=20nouvelle=20page=20"logs"=20Permet=20de=20la?= =?UTF-8?q?isser=20la=20place=20=C3=A0=20un=20r=C3=A9sum=C3=A9=20dans=20le?= =?UTF-8?q?=20/index.html=20de=20stats?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{aff_actions.html => aff_stats_logs.html} | 0 logs/templates/logs/aff_summary.html | 61 +++++++++++++++++++ logs/templates/logs/index.html | 2 +- logs/templates/logs/sidebar.html | 4 ++ logs/templates/logs/stats_logs.html | 36 +++++++++++ logs/urls.py | 1 + logs/views.py | 18 ++++++ 7 files changed, 121 insertions(+), 1 deletion(-) rename logs/templates/logs/{aff_actions.html => aff_stats_logs.html} (100%) create mode 100644 logs/templates/logs/aff_summary.html create mode 100644 logs/templates/logs/stats_logs.html diff --git a/logs/templates/logs/aff_actions.html b/logs/templates/logs/aff_stats_logs.html similarity index 100% rename from logs/templates/logs/aff_actions.html rename to logs/templates/logs/aff_stats_logs.html diff --git a/logs/templates/logs/aff_summary.html b/logs/templates/logs/aff_summary.html new file mode 100644 index 00000000..35504144 --- /dev/null +++ b/logs/templates/logs/aff_summary.html @@ -0,0 +1,61 @@ +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +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 %} +{% endif %} + +{% load logs_extra %} + + + + + + + + + + + + + {% for revision in revisions_list %} + {% for reversion in revision.version_set.all %} + + + + + + + {% if is_bureau %} + + {% endif %} + + {% endfor %} + {% endfor %} +
Objet modifiéType de l'objetModification parDate de modificationCommentaire
{{ reversion.object|truncatechars:20 }}{{ reversion.object|classname }}{{ revision.user }}{{ revision.date_created }}{{ revision.comment }} + + + Annuler + +
diff --git a/logs/templates/logs/index.html b/logs/templates/logs/index.html index 0255672e..baeb1cd7 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_actions.html" with revisions_list=revisions_list %} + {% include "logs/aff_summary.html" with revisions_list=revisions_list %}


diff --git a/logs/templates/logs/sidebar.html b/logs/templates/logs/sidebar.html index cd8bc02f..4137741f 100644 --- a/logs/templates/logs/sidebar.html +++ b/logs/templates/logs/sidebar.html @@ -27,6 +27,10 @@ with this program; if not, write to the Free Software Foundation, Inc., {% block sidebar %} {% if is_cableur %} + + Résumé + + Évènements diff --git a/logs/templates/logs/stats_logs.html b/logs/templates/logs/stats_logs.html new file mode 100644 index 00000000..4db77c68 --- /dev/null +++ b/logs/templates/logs/stats_logs.html @@ -0,0 +1,36 @@ +{% extends "logs/sidebar.html" %} +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + +{% load bootstrap3 %} + +{% block title %}Statistiques{% endblock %} + +{% block content %} +

Actions effectuées

+ {% include "logs/aff_stats_logs.html" with revisions_list=revisions_list %} +
+
+
+ {% endblock %} diff --git a/logs/urls.py b/logs/urls.py index 832288e0..b3d4b33b 100644 --- a/logs/urls.py +++ b/logs/urls.py @@ -26,6 +26,7 @@ from . import views urlpatterns = [ url(r'^$', views.index, name='index'), + url(r'^stats_logs$', views.stats_logs, name='stats-logs'), url(r'^revert_action/(?P[0-9]+)$', views.revert_action, name='revert-action'), url(r'^stats_general/$', views.stats_general, name='stats-general'), url(r'^stats_models/$', views.stats_models, name='stats-models'), diff --git a/logs/views.py b/logs/views.py index b20f1b5f..4be87899 100644 --- a/logs/views.py +++ b/logs/views.py @@ -82,6 +82,24 @@ def index(request): revisions = paginator.page(paginator.num_pages) return render(request, 'logs/index.html', {'revisions_list': revisions}) +@login_required +@permission_required('cableur') +def stats_logs(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') + paginator = Paginator(revisions, pagination_number) + page = request.GET.get('page') + try: + revisions = paginator.page(page) + except PageNotAnInteger: + # If page is not an integer, deliver first page. + revisions = 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/stats_logs.html', {'revisions_list': revisions}) + @login_required @permission_required('bureau') def revert_action(request, revision_id): From 2797ec29b66ff841a505ca8344a4f9722cb09c5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sun, 10 Sep 2017 00:40:42 +0000 Subject: [PATCH 02/11] Affiche des infos sur certains type d'event --- logs/templates/logs/aff_summary.html | 34 +++++++++++++++++----------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/logs/templates/logs/aff_summary.html b/logs/templates/logs/aff_summary.html index 35504144..57cf56e5 100644 --- a/logs/templates/logs/aff_summary.html +++ b/logs/templates/logs/aff_summary.html @@ -31,31 +31,39 @@ with this program; if not, write to the Free Software Foundation, Inc., - - - - - - + + + {% for revision in revisions_list %} {% for reversion in revision.version_set.all %} - - - - + {% if reversion.content_type.name in 'ban,whitelist,user,vente,interface'|slice:',' %} + - - {% if is_bureau %} + {% if reversion.content_type.name == 'ban' %} + + {% elif reversion.content_type.name == 'whitelist' %} + + {% elif reversion.content_type.name == 'user' %} + + {% elif reversion.content_type.name == 'vente' %} + + {% elif reversion.content_type.name == 'interface' %} + + {% endif %} + {% if is_bureau %} - {% endif %} + {% endif %} + {% endif %} {% endfor %} {% endfor %}
Objet modifiéType de l'objetModification parDate de modificationCommentaireDateModification
{{ reversion.object|truncatechars:20 }}{{ reversion.object|classname }}{{ revision.user }}
{{ revision.date_created }}{{ revision.comment }}{{ revision.user.get_username }} a banni {{ reversion.object.user.get_username }} ({{ reversion.object.raison }}){{ revision.user.get_username }} a autorisé gracieusement {{ reversion.object.user.get_username }} ({{ reversion.object.raison }}){{ revision.user.get_username }} a ajouté {{ reversion.object.get_username }}{{ reversion.object.facture.user.get_username }} a acheté {{ reversion.object.number }}x {{ reversion.object.name }}{% if reversion.object.iscotisation %} (+{{ reversion.object.duration }} mois){% endif %}{{ revision.user.get_username }} a ajouté une interface à {{ reversion.object.machine.user.get_username }} (MAC : {{ reversion.object.mac_bare }}) Annuler
+ + From 8e974cc82dd3a7ed85787846f1e89dba416356b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sun, 10 Sep 2017 01:07:53 +0000 Subject: [PATCH 03/11] =?UTF-8?q?Calcul=20la=20date=20dans=20views=20pour?= =?UTF-8?q?=20affichage=20plus=20condens=C3=A9=20+=20pr=C3=A9filtre=20les?= =?UTF-8?q?=20r=C3=A9visions=20Si=20quelqu'un=20sait=20faire=20le=20pr?= =?UTF-8?q?=C3=A9filtre=20avec=20des=20request=20de=20type=20.filter=20je?= =?UTF-8?q?=20suis=20preneur.=20J'ai=20peur=20que=20la=20solution=20actuel?= =?UTF-8?q?le=20soit=20lente=20pour=20un=20grand=20nombre=20d'event=20(tou?= =?UTF-8?q?s=20pars=C3=A9s)=20Mais=20de=20toute=20fa=C3=A7on=20le=20filtre?= =?UTF-8?q?=20est=20oblig=C3=A9=20d'=C3=AAtre=20dans=20views?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logs/templates/logs/aff_summary.html | 14 +++++++------- logs/views.py | 11 ++++++++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/logs/templates/logs/aff_summary.html b/logs/templates/logs/aff_summary.html index 57cf56e5..c20bf2cb 100644 --- a/logs/templates/logs/aff_summary.html +++ b/logs/templates/logs/aff_summary.html @@ -37,24 +37,24 @@ with this program; if not, write to the Free Software Foundation, Inc., {% for revision in revisions_list %} - {% for reversion in revision.version_set.all %} + {% for reversion in revision.revision.version_set.all %} {% if reversion.content_type.name in 'ban,whitelist,user,vente,interface'|slice:',' %} - {{ revision.date_created }} + {{ revision.datetime }} {% if reversion.content_type.name == 'ban' %} - {{ revision.user.get_username }} a banni {{ reversion.object.user.get_username }} ({{ reversion.object.raison }}) + {{ revision.revision.user.get_username }} a banni {{ reversion.object.user.get_username }} ({{ reversion.object.raison }}) {% elif reversion.content_type.name == 'whitelist' %} - {{ revision.user.get_username }} a autorisé gracieusement {{ reversion.object.user.get_username }} ({{ reversion.object.raison }}) + {{ revision.revision.user.get_username }} a autorisé gracieusement {{ reversion.object.user.get_username }} ({{ reversion.object.raison }}) {% elif reversion.content_type.name == 'user' %} - {{ revision.user.get_username }} a ajouté {{ reversion.object.get_username }} + {{ revision.revision.user.get_username }} a ajouté {{ reversion.object.get_username }} {% elif reversion.content_type.name == 'vente' %} {{ reversion.object.facture.user.get_username }} a acheté {{ reversion.object.number }}x {{ reversion.object.name }}{% if reversion.object.iscotisation %} (+{{ reversion.object.duration }} mois){% endif %} {% elif reversion.content_type.name == 'interface' %} - {{ revision.user.get_username }} a ajouté une interface à {{ reversion.object.machine.user.get_username }} (MAC : {{ reversion.object.mac_bare }}) + {{ revision.revision.user.get_username }} a ajouté une interface à {{ reversion.object.machine.user.get_username }} (MAC : {{ reversion.object.mac_bare }}) {% endif %} {% if is_bureau %} - + Annuler diff --git a/logs/views.py b/logs/views.py index 4be87899..be24dcac 100644 --- a/logs/views.py +++ b/logs/views.py @@ -69,7 +69,16 @@ def form(ctx, template, request): 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') + + 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 } ) + break + paginator = Paginator(revisions, pagination_number) page = request.GET.get('page') try: From 129c787a9c85066c4da00f45c5e4a580f96290af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sun, 10 Sep 2017 01:52:02 +0000 Subject: [PATCH 04/11] =?UTF-8?q?Remplace=20par=20'=3F'=20quand=20on=20ne?= =?UTF-8?q?=20sait=20pas=20qui=20a=20fait=20la=20reversion=20(None)=20+=20?= =?UTF-8?q?=C3=A9clate=20le=20code=20sur=20plusieures=20lignes=20pour=20la?= =?UTF-8?q?=20lisibilit=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logs/templates/logs/aff_summary.html | 52 +++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/logs/templates/logs/aff_summary.html b/logs/templates/logs/aff_summary.html index c20bf2cb..5170bcd6 100644 --- a/logs/templates/logs/aff_summary.html +++ b/logs/templates/logs/aff_summary.html @@ -42,15 +42,57 @@ with this program; if not, write to the Free Software Foundation, Inc., {{ revision.datetime }} {% if reversion.content_type.name == 'ban' %} - {{ revision.revision.user.get_username }} a banni {{ reversion.object.user.get_username }} ({{ reversion.object.raison }}) + + {% if revision.revision.user.et_username %} + {{ revision.revision.user.get_username }} + {% else %} + ? + {% endif %} + a banni + {{ reversion.object.user.get_username }} + ({{ reversion.object.raison }}) + {% elif reversion.content_type.name == 'whitelist' %} - {{ revision.revision.user.get_username }} a autorisé gracieusement {{ reversion.object.user.get_username }} ({{ reversion.object.raison }}) + + {% if revision.revision.user.get_username %} + {{ revision.revision.user.get_username }} + {% else %} + ? + {% endif %} + a autorisé gracieusement + {{ reversion.object.user.get_username }} + ({{ reversion.object.raison }}) + {% elif reversion.content_type.name == 'user' %} - {{ revision.revision.user.get_username }} a ajouté {{ reversion.object.get_username }} + + {% if revision.revision.user.get_username %} + {{ revision.revision.user.get_username }} + {% else %} + ? + {% endif %} + a ajouté + {{ reversion.object.get_username }} + {% elif reversion.content_type.name == 'vente' %} - {{ reversion.object.facture.user.get_username }} a acheté {{ reversion.object.number }}x {{ reversion.object.name }}{% if reversion.object.iscotisation %} (+{{ reversion.object.duration }} mois){% endif %} + + {{ reversion.object.facture.user.get_username }} + a acheté + {{ reversion.object.number }}x {{ reversion.object.name }} + {% if reversion.object.iscotisation %} + (+{{ reversion.object.duration }} mois) + {% endif %} + {% elif reversion.content_type.name == 'interface' %} - {{ revision.revision.user.get_username }} a ajouté une interface à {{ reversion.object.machine.user.get_username }} (MAC : {{ reversion.object.mac_bare }}) + {{ revision.revision.user.get_username }} + {% if revision.revision.user.get_username %} + {{ revision.revision.user.get_username }} + {% else %} + ? + {% endif %} + a ajouté une interface à + {{ reversion.object.machine.user.get_username }} + (MAC : {{ reversion.object.mac_bare }}) + {% endif %} {% if is_bureau %} From c5e7431e1a025f1ac8826b9ea9ba434c76bb8f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sun, 10 Sep 2017 01:54:55 +0000 Subject: [PATCH 05/11] Fix : doublons du pseudo sur le type interface --- logs/templates/logs/aff_summary.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logs/templates/logs/aff_summary.html b/logs/templates/logs/aff_summary.html index 5170bcd6..69d64033 100644 --- a/logs/templates/logs/aff_summary.html +++ b/logs/templates/logs/aff_summary.html @@ -83,7 +83,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% endif %} {% elif reversion.content_type.name == 'interface' %} - {{ revision.revision.user.get_username }} + {% if revision.revision.user.get_username %} {{ revision.revision.user.get_username }} {% else %} From 67b271008b368d970412d9fb443b07c33c35859d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sun, 10 Sep 2017 14:17:59 +0000 Subject: [PATCH 06/11] =?UTF-8?q?D=C3=A9place=20une=20partie=20des=20v?= =?UTF-8?q?=C3=A9rif=20dans=20views=20pour=20all=C3=A9ger=20le=20template?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logs/templates/logs/aff_summary.html | 115 +++++++++++---------------- logs/templates/logs/index.html | 2 +- logs/views.py | 29 ++++--- 3 files changed, 63 insertions(+), 83 deletions(-) diff --git a/logs/templates/logs/aff_summary.html b/logs/templates/logs/aff_summary.html index 69d64033..8fe646d7 100644 --- a/logs/templates/logs/aff_summary.html +++ b/logs/templates/logs/aff_summary.html @@ -36,76 +36,51 @@ with this program; if not, write to the Free Software Foundation, Inc., - {% 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:',' %} - - {{ revision.datetime }} - {% if reversion.content_type.name == 'ban' %} - - {% if revision.revision.user.et_username %} - {{ revision.revision.user.get_username }} - {% else %} - ? - {% endif %} - a banni - {{ reversion.object.user.get_username }} - ({{ reversion.object.raison }}) - - {% elif reversion.content_type.name == 'whitelist' %} - - {% if revision.revision.user.get_username %} - {{ revision.revision.user.get_username }} - {% else %} - ? - {% endif %} - a autorisé gracieusement - {{ reversion.object.user.get_username }} - ({{ reversion.object.raison }}) - - {% elif reversion.content_type.name == 'user' %} - - {% if revision.revision.user.get_username %} - {{ revision.revision.user.get_username }} - {% else %} - ? - {% endif %} - a ajouté - {{ reversion.object.get_username }} - - {% elif reversion.content_type.name == 'vente' %} - - {{ reversion.object.facture.user.get_username }} - a acheté - {{ reversion.object.number }}x {{ reversion.object.name }} - {% if reversion.object.iscotisation %} - (+{{ reversion.object.duration }} mois) - {% endif %} - - {% elif reversion.content_type.name == 'interface' %} - - {% if revision.revision.user.get_username %} - {{ revision.revision.user.get_username }} - {% else %} - ? - {% endif %} - a ajouté une interface à - {{ reversion.object.machine.user.get_username }} - (MAC : {{ reversion.object.mac_bare }}) - - {% endif %} - {% if is_bureau %} - - - - Annuler - - - {% endif %} - - {% endif %} - {% endfor %} - {% endfor %} + {% for rev in reversions_list %} + + {{ rev.datetime }} + {% if rev.rev.content_type.name == 'ban' %} + + {{ rev.username }} a banni + {{ rev.rev.object.user.get_username }} + ({{ rev.rev.object.raison }}) + + {% elif rev.rev.content_type.name == 'whitelist' %} + + {{ rev.username }} a autorisé gracieusement + {{ rev.rev.object.user.get_username }} + ({{ rev.rev.object.raison }}) + + {% elif rev.rev.content_type.name == 'user' %} + + {{ rev.username }} a ajouté + {{ rev.rev.object.get_username }} + + {% elif rev.rev.content_type.name == 'vente' %} + + {{ rev.rev.object.facture.user.get_username }} + a acheté {{ rev.rev.object.number }}x {{ rev.rev.object.name }} + {% if rev.rev.object.iscotisation %} + (+{{ rev.rev.object.duration }} mois) + {% endif %} + + {% elif rev.rev.content_type.name == 'interface' %} + + {{ rev.username }} a ajouté une interface à + {{ rev.rev.object.machine.user.get_username }} + (MAC : {{ rev.rev.object.mac_bare }}) + + {% endif %} + {% if is_bureau %} + + + + Annuler + + + {% endif %} + + {% endfor %} diff --git a/logs/templates/logs/index.html b/logs/templates/logs/index.html index baeb1cd7..487f924e 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 revisions_list=revisions_list %} + {% include "logs/aff_summary.html" with reversions_list=reversions_list %}


diff --git a/logs/views.py b/logs/views.py index be24dcac..886f8dc2 100644 --- a/logs/views.py +++ b/logs/views.py @@ -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') From e1bf240df9e7d269be872c6373fa2f30199ac01e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sun, 10 Sep 2017 15:03:58 +0000 Subject: [PATCH 07/11] =?UTF-8?q?V=C3=A9rifie=20que=20le=20content=5Ftype?= =?UTF-8?q?=20existe=20dans=20un=20objet=20Revision=20Pr=C3=A9vient=20le?= =?UTF-8?q?=20cas=20d'un=20objet=20delete=20mais=20sans=20revert=20l'actio?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logs/views.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/logs/views.py b/logs/views.py index 886f8dc2..584972ff 100644 --- a/logs/views.py +++ b/logs/views.py @@ -74,7 +74,15 @@ def index(request): reversions = [] for revision in revisions : for reversion in revision.version_set.all() : - if reversion.content_type.name in ['ban', 'whitelist', 'vente', 'cotisation', 'interface', 'user'] : + + content = '' + try : + content = reversion.content_type.name + except : + # If reversion has no content_type (when object has been deleted) + pass + + if content in ['ban', 'whitelist', 'vente', 'cotisation', 'interface', 'user'] : reversions.append( {'id' : revision.id, 'datetime': revision.date_created.strftime('%d/%m/%y %H:%M:%S'), From 88ea16d2ed1452b70ec7e096d61b218e0425d606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sun, 10 Sep 2017 15:54:46 +0000 Subject: [PATCH 08/11] =?UTF-8?q?Affichage=20des=20comment=20pour=20distin?= =?UTF-8?q?guer=20la=20cr=C3=A9ation=20de=20l'update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logs/templates/logs/aff_summary.html | 29 ++++++++++++++++++++++------ logs/views.py | 1 + 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/logs/templates/logs/aff_summary.html b/logs/templates/logs/aff_summary.html index 8fe646d7..543cd60a 100644 --- a/logs/templates/logs/aff_summary.html +++ b/logs/templates/logs/aff_summary.html @@ -43,32 +43,49 @@ with this program; if not, write to the Free Software Foundation, Inc., {{ rev.username }} a banni {{ rev.rev.object.user.get_username }} - ({{ rev.rev.object.raison }}) + ( + {% if rev.rev.object.raison == '' %} + Aucune raison + {% else %} + {{ rev.rev.object.raison }} + {% endif %} + ) {% elif rev.rev.content_type.name == 'whitelist' %} {{ rev.username }} a autorisé gracieusement {{ rev.rev.object.user.get_username }} - ({{ rev.rev.object.raison }}) + ( + {% if rev.rev.object.raison == '' %} + Aucune raison + {% else %} + {{ rev.rev.object.raison }} + {% endif %} + ) {% elif rev.rev.content_type.name == 'user' %} - {{ rev.username }} a ajouté + {{ rev.username }} a mis à jour {{ rev.rev.object.get_username }} + {% if rev.comment != '' %} + ({{ rev.comment }}) + {% endif %} {% elif rev.rev.content_type.name == 'vente' %} + {{ rev.username }} a vendu {{ rev.rev.object.number }}x {{ rev.rev.object.name }} à {{ rev.rev.object.facture.user.get_username }} - a acheté {{ rev.rev.object.number }}x {{ rev.rev.object.name }} {% if rev.rev.object.iscotisation %} (+{{ rev.rev.object.duration }} mois) {% endif %} {% elif rev.rev.content_type.name == 'interface' %} - {{ rev.username }} a ajouté une interface à + {{ rev.username }} a modifié une interface de {{ rev.rev.object.machine.user.get_username }} - (MAC : {{ rev.rev.object.mac_bare }}) + {% if rev.comment != '' %} + ({{ rev.comment }}) + {% endif %} {% endif %} {% if is_bureau %} diff --git a/logs/views.py b/logs/views.py index 584972ff..3bb5d45a 100644 --- a/logs/views.py +++ b/logs/views.py @@ -85,6 +85,7 @@ def index(request): if content in ['ban', 'whitelist', 'vente', 'cotisation', '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, From 938501523b98d300f779f7ed59c843cc5692e175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Wed, 13 Sep 2017 22:21:49 +0000 Subject: [PATCH 09/11] Met en avant les ban et les whitelist (couleur rouge et verte) --- logs/templates/logs/aff_summary.html | 100 +++++++++++++++++++-------- 1 file changed, 72 insertions(+), 28 deletions(-) diff --git a/logs/templates/logs/aff_summary.html b/logs/templates/logs/aff_summary.html index 543cd60a..c9abd16f 100644 --- a/logs/templates/logs/aff_summary.html +++ b/logs/templates/logs/aff_summary.html @@ -37,9 +37,9 @@ with this program; if not, write to the Free Software Foundation, Inc., {% for rev in reversions_list %} - + {% if rev.rev.content_type.name == 'ban' %} + {{ rev.datetime }} - {% if rev.rev.content_type.name == 'ban' %} {{ rev.username }} a banni {{ rev.rev.object.user.get_username }} @@ -51,7 +51,18 @@ with this program; if not, write to the Free Software Foundation, Inc., {% endif %} ) - {% elif rev.rev.content_type.name == 'whitelist' %} + {% if is_bureau %} + + + + Annuler + + + {% endif %} + + {% elif rev.rev.content_type.name == 'whitelist' %} + + {{ rev.datetime }} {{ rev.username }} a autorisé gracieusement {{ rev.rev.object.user.get_username }} @@ -63,31 +74,6 @@ with this program; if not, write to the Free Software Foundation, Inc., {% endif %} ) - {% elif rev.rev.content_type.name == 'user' %} - - {{ rev.username }} a mis à jour - {{ rev.rev.object.get_username }} - {% if rev.comment != '' %} - ({{ rev.comment }}) - {% endif %} - - {% elif rev.rev.content_type.name == 'vente' %} - - {{ 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) - {% endif %} - - {% elif rev.rev.content_type.name == 'interface' %} - - {{ rev.username }} a modifié une interface de - {{ rev.rev.object.machine.user.get_username }} - {% if rev.comment != '' %} - ({{ rev.comment }}) - {% endif %} - - {% endif %} {% if is_bureau %} @@ -97,6 +83,64 @@ with this program; if not, write to the Free Software Foundation, Inc., {% endif %} + {% elif rev.rev.content_type.name == 'user' %} + + {{ rev.datetime }} + + {{ rev.username }} a mis à jour + {{ rev.rev.object.get_username }} + {% if rev.comment != '' %} + ({{ rev.comment }}) + {% endif %} + + {% if is_bureau %} + + + + Annuler + + + {% endif %} + + {% elif rev.rev.content_type.name == 'vente' %} + + {{ rev.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) + {% endif %} + + {% if is_bureau %} + + + + Annuler + + + {% endif %} + + {% elif rev.rev.content_type.name == 'interface' %} + + {{ rev.datetime }} + + {{ rev.username }} a modifié une interface de + {{ rev.rev.object.machine.user.get_username }} + {% if rev.comment != '' %} + ({{ rev.comment }}) + {% endif %} + + {% if is_bureau %} + + + + Annuler + + + {% endif %} + + {% endif %} {% endfor %} From a3e6b3e02b20f9201afaaf782957575873271890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Wed, 13 Sep 2017 22:22:07 +0000 Subject: [PATCH 10/11] =?UTF-8?q?Les=20cotis=20sont=20d=C3=A9j=C3=A0=20com?= =?UTF-8?q?pt=C3=A9es=20dans=20les=20ventes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logs/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logs/views.py b/logs/views.py index 3bb5d45a..983c4d11 100644 --- a/logs/views.py +++ b/logs/views.py @@ -82,7 +82,7 @@ def index(request): # If reversion has no content_type (when object has been deleted) pass - if content in ['ban', 'whitelist', 'vente', 'cotisation', 'interface', 'user'] : + if content in ['ban', 'whitelist', 'vente', 'interface', 'user'] : reversions.append( {'id' : revision.id, 'comment': revision.comment, From 1923b0950b9a696c5ef9b9e00e6e9c72cdb7fbd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Mon, 18 Sep 2017 22:46:57 +0000 Subject: [PATCH 11/11] =?UTF-8?q?Utilisation=20de=20QuerySet=20pour=20sele?= =?UTF-8?q?ctionner=20les=20versions=20voulues=20Optimise=20plut=C3=B4t=20?= =?UTF-8?q?que=20de=20devoir=20faire=20une=20fat=20boucle=20for=20sur=20l'?= =?UTF-8?q?ensemble=20Fix=20l'affichage=20du=20paginator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logs/templates/logs/aff_summary.html | 76 ++++++++++++++-------------- logs/templates/logs/index.html | 2 +- logs/views.py | 50 +++++++++--------- 3 files changed, 62 insertions(+), 66 deletions(-) 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')