diff --git a/logs/templates/logs/aff_stats_users.html b/logs/templates/logs/aff_stats_users.html
new file mode 100644
index 00000000..08418fde
--- /dev/null
+++ b/logs/templates/logs/aff_stats_users.html
@@ -0,0 +1,19 @@
+ {% for key, stats in stats_list.items %}
+
+ Statistiques par utilisateur de {{ key }}
+
+
+ Utilisateur |
+ Nombre d'objets de l'utilisateur |
+ Rang |
+
+
+ {% for stat in stats %}
+
+ {{ stat }} |
+ {{ stat.num }} |
+ {{ forloop.counter }} |
+
+ {% endfor %}
+
+ {% endfor %}
diff --git a/logs/templates/logs/sidebar.html b/logs/templates/logs/sidebar.html
index fd1e35f3..dc0e2ff6 100644
--- a/logs/templates/logs/sidebar.html
+++ b/logs/templates/logs/sidebar.html
@@ -3,5 +3,7 @@
{% block sidebar %}
{% if is_cableur %}
Statistiques base de donnée
+ Statistiques des actions de cablage
+ Statistiques utilisateurs
{% endif %}
{% endblock %}
diff --git a/logs/templates/logs/stats_users.html b/logs/templates/logs/stats_users.html
new file mode 100644
index 00000000..cd5aa379
--- /dev/null
+++ b/logs/templates/logs/stats_users.html
@@ -0,0 +1,12 @@
+{% extends "logs/sidebar.html" %}
+{% load bootstrap3 %}
+
+{% block title %}Statistiques par utilisateur{% endblock %}
+
+{% block content %}
+ Statistiques par utilisateur
+ {% include "logs/aff_stats_users.html" with stats_list=stats_list %}
+
+
+
+ {% endblock %}
diff --git a/logs/urls.py b/logs/urls.py
index 8ed34e1d..673405ff 100644
--- a/logs/urls.py
+++ b/logs/urls.py
@@ -6,4 +6,6 @@ urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^revert_action/(?P[0-9]+)$', views.revert_action, name='revert-action'),
url(r'^stats_models/$', views.stats_models, name='stats-models'),
+ url(r'^stats_users/$', views.stats_users, name='stats-users'),
+ url(r'^stats_actions/$', views.stats_actions, name='stats-actions'),
]
diff --git a/logs/views.py b/logs/views.py
index 00e04af8..9afac353 100644
--- a/logs/views.py
+++ b/logs/views.py
@@ -12,6 +12,7 @@ from django.contrib.auth.decorators import login_required, permission_required
from django.db.models import ProtectedError
from django.forms import ValidationError
from django.db import transaction
+from django.db.models import Count
from reversion.models import Revision
from reversion.models import Version
@@ -94,5 +95,28 @@ def stats_models(request):
'port' : [Port.PRETTY_NAME, Port.objects.count()],
'chambre' : [Room.PRETTY_NAME, Room.objects.count()],
},
+ 'Actions effectuées sur la base' :
+ {
+ 'revision' : ["Nombre d'actions", Revision.objects.count()],
+ },
}
return render(request, 'logs/stats_models.html', {'stats_list': stats})
+
+@login_required
+@permission_required('cableur')
+def stats_users(request):
+ stats = {
+ 'Machines' : User.objects.annotate(num=Count('machine')).order_by('-num')[:10],
+ 'Facture' : User.objects.annotate(num=Count('facture')).order_by('-num')[:10],
+ 'Bannissement' : User.objects.annotate(num=Count('ban')).order_by('-num')[:10],
+ 'Accès gracieux' : User.objects.annotate(num=Count('whitelist')).order_by('-num')[:10],
+ }
+ return render(request, 'logs/stats_users.html', {'stats_list': stats})
+
+@login_required
+@permission_required('cableur')
+def stats_actions(request):
+ stats = {
+ 'Action' : User.objects.annotate(num=Count('revision')).order_by('-num')[:40],
+ }
+ return render(request, 'logs/stats_users.html', {'stats_list': stats})