From 787e048a2a4c1cb9458e6854e6e2412a9baad3d5 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Fri, 26 May 2017 04:32:45 +0200 Subject: [PATCH] More stats --- logs/templates/logs/sidebar.html | 4 ++++ logs/urls.py | 1 + logs/views.py | 25 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/logs/templates/logs/sidebar.html b/logs/templates/logs/sidebar.html index b12ed00c..cd8bc02f 100644 --- a/logs/templates/logs/sidebar.html +++ b/logs/templates/logs/sidebar.html @@ -30,6 +30,10 @@ with this program; if not, write to the Free Software Foundation, Inc., Évènements + + + Général + Base de données diff --git a/logs/urls.py b/logs/urls.py index b8042083..832288e0 100644 --- a/logs/urls.py +++ b/logs/urls.py @@ -27,6 +27,7 @@ from . import views urlpatterns = [ url(r'^$', views.index, name='index'), 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'), 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 05e0150c..61e6f6e3 100644 --- a/logs/views.py +++ b/logs/views.py @@ -93,9 +93,34 @@ def revert_action(request, revision_id): return redirect("/logs/") return form({'objet': revision, 'objet_name': revision.__class__.__name__ }, 'logs/delete.html', request) +@login_required +@permission_required('cableur') +def stats_general(request): + all_active_users = User.objects.filter(state=User.STATE_ACTIVE) + ip = dict() + for ip_range in IpType.objects.all(): + all_ip = IpList.objects.filter(ip_type=ip_range) + used_ip = Interface.objects.filter(ipv4__in=all_ip).count() + ip[ip_range] = [ip_range, all_ip.count(), used_ip, all_ip.count()-used_ip] + stats = [ + [["Categorie", "Nombre d'utilisateurs"], { + 'active_users' : ["Users actifs", User.objects.filter(state=User.STATE_ACTIVE).count()], + 'inactive_users' : ["Users désactivés", User.objects.filter(state=User.STATE_DISABLED).count()], + 'archive_users' : ["Users archivés", User.objects.filter(state=User.STATE_ARCHIVE).count()], + 'adherent_users' : ["Adhérents à l'association", len([user for user in all_active_users if user.is_adherent()])], + 'connexion_users' : ["Utilisateurs bénéficiant d'une connexion", len([user for user in all_active_users if user.has_access()])], + 'ban_users' : ["Utilisateurs bannis", len([user for user in all_active_users if user.is_ban()])], + 'whitelisted_user' : ["Utilisateurs bénéficiant d'une connexion gracieuse", len([user for user in all_active_users if user.is_whitelisted()])], + }], + [["Range d'ip", "Nombre d'ip totales", "Nombre d'ip utilisées", "Nombre d'ip libres"] ,ip] + ] + return render(request, 'logs/stats_general.html', {'stats_list': stats}) + + @login_required @permission_required('cableur') def stats_models(request): + all_active_users = User.objects.filter(state=User.STATE_ACTIVE) stats = { 'Users' : { 'users' : [User.PRETTY_NAME, User.objects.count()],