From e538d3b2dc31c0673a8ffb4fda9aa60004e1efd2 Mon Sep 17 00:00:00 2001 From: guimoz Date: Tue, 15 Nov 2016 15:25:27 +0100 Subject: [PATCH] Ajout du domaine d'ip --- logs/templates/logs/aff_stats_users.html | 7 ++++- logs/views.py | 28 ++++++++++++++++--- machines/admin.py | 2 +- machines/forms.py | 4 +-- machines/migrations/0028_iptype_domaine_ip.py | 19 +++++++++++++ .../migrations/0029_iptype_domaine_range.py | 20 +++++++++++++ machines/models.py | 3 ++ machines/templates/machines/aff_iptype.html | 8 ++++-- 8 files changed, 81 insertions(+), 10 deletions(-) create mode 100644 machines/migrations/0028_iptype_domaine_ip.py create mode 100644 machines/migrations/0029_iptype_domaine_range.py diff --git a/logs/templates/logs/aff_stats_users.html b/logs/templates/logs/aff_stats_users.html index ee60c8cf..e8914f51 100644 --- a/logs/templates/logs/aff_stats_users.html +++ b/logs/templates/logs/aff_stats_users.html @@ -1,8 +1,13 @@ + + {% for key_dict, stats_dict in stats_list.items %} {% for key, stats in stats_dict.items %} -

Statistiques par {{ key_dict }} de {{ key }}

+

Statistiques par {{ key_dict }} de {{ key }}

diff --git a/logs/views.py b/logs/views.py index 072b4efc..82fc464b 100644 --- a/logs/views.py +++ b/logs/views.py @@ -24,6 +24,18 @@ from topologie.models import Switch, Port, Room from re2o.settings import PAGINATION_NUMBER, PAGINATION_LARGE_NUMBER +from django.utils import timezone +from dateutil.relativedelta import relativedelta + +STATS_DICT = { + 0 : ["Tout", 36], + 1 : ["1 mois", 1], + 2 : ["2 mois", 2], + 3 : ["6 mois", 6], + 4 : ["1 an", 12], + 5 : ["2 an", 24], +} + def form(ctx, template, request): c = ctx c.update(csrf(request)) @@ -105,11 +117,18 @@ def stats_models(request): @login_required @permission_required('cableur') def stats_users(request): + onglet = request.GET.get('onglet') + try: + search_field = STATS_DICT[onglet] + except: + search_field = STATS_DICT[0] + onglet = 0 + start_date = timezone.now() + relativedelta(months=-search_field[1]) stats = { 'Utilisateur' : { - '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], + 'Machines' : User.objects.filter(registered__gt=search_field[1]).annotate(num=Count('machine')).order_by('-num')[:10], + 'Facture' : User.objects.filter(registered__gt=search_field[1]).annotate(num=Count('facture')).order_by('-num')[:10], + 'Bannissement' : User.objects.filter(registered__gt=search_field[1]).annotate(num=Count('ban')).order_by('-num')[:10], 'Accès gracieux' : User.objects.annotate(num=Count('whitelist')).order_by('-num')[:10], 'Droits' : User.objects.annotate(num=Count('right')).order_by('-num')[:10], }, @@ -123,11 +142,12 @@ def stats_users(request): 'Utilisateur' : Banque.objects.annotate(num=Count('facture')).order_by('-num')[:10], }, } - return render(request, 'logs/stats_users.html', {'stats_list': stats}) + return render(request, 'logs/stats_users.html', {'stats_list': stats, 'stats_dict' : STATS_DICT, 'active_field': onglet}) @login_required @permission_required('cableur') def stats_actions(request): + onglet = request.GET.get('onglet') stats = { 'Utilisateur' : { 'Action' : User.objects.annotate(num=Count('revision')).order_by('-num')[:40], diff --git a/machines/admin.py b/machines/admin.py index 6423e1c1..d44e2248 100644 --- a/machines/admin.py +++ b/machines/admin.py @@ -7,7 +7,7 @@ class MachineAdmin(VersionAdmin): list_display = ('user','name','active') class IpTypeAdmin(VersionAdmin): - list_display = ('type','extension','need_infra') + list_display = ('type','extension','need_infra','domaine_ip','domaine_range') class MachineTypeAdmin(VersionAdmin): list_display = ('type','ip_type') diff --git a/machines/forms.py b/machines/forms.py index 5a9e3395..9ee9558e 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -88,7 +88,7 @@ class DelMachineTypeForm(ModelForm): class IpTypeForm(ModelForm): class Meta: model = IpType - fields = ['type','extension','need_infra'] + fields = ['type','extension','need_infra','domaine_ip','domaine_range'] def __init__(self, *args, **kwargs): super(IpTypeForm, self).__init__(*args, **kwargs) @@ -98,7 +98,7 @@ class DelIpTypeForm(ModelForm): iptypes = forms.ModelMultipleChoiceField(queryset=IpType.objects.all(), label="Types d'ip actuelles", widget=forms.CheckboxSelectMultiple) class Meta: - exclude = ['type','extension','need_infra'] + exclude = ['type','extension','need_infra','domaine_ip','domaine_range'] model = IpType diff --git a/machines/migrations/0028_iptype_domaine_ip.py b/machines/migrations/0028_iptype_domaine_ip.py new file mode 100644 index 00000000..e3889fd7 --- /dev/null +++ b/machines/migrations/0028_iptype_domaine_ip.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0027_alias'), + ] + + operations = [ + migrations.AddField( + model_name='iptype', + name='domaine_ip', + field=models.GenericIPAddressField(blank=True, unique=True, null=True, protocol='IPv4'), + ), + ] diff --git a/machines/migrations/0029_iptype_domaine_range.py b/machines/migrations/0029_iptype_domaine_range.py new file mode 100644 index 00000000..a6b91a48 --- /dev/null +++ b/machines/migrations/0029_iptype_domaine_range.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import django.core.validators + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0028_iptype_domaine_ip'), + ] + + operations = [ + migrations.AddField( + model_name='iptype', + name='domaine_range', + field=models.IntegerField(null=True, validators=[django.core.validators.MinValueValidator(8), django.core.validators.MaxValueValidator(32)], blank=True), + ), + ] diff --git a/machines/models.py b/machines/models.py index a638bb47..926dfb51 100644 --- a/machines/models.py +++ b/machines/models.py @@ -4,6 +4,7 @@ from django.dispatch import receiver from django.forms import ValidationError from macaddress.fields import MACAddressField from netaddr import EUI +from django.core.validators import MinValueValidator,MaxValueValidator from re2o.settings import MAIN_EXTENSION @@ -33,6 +34,8 @@ class IpType(models.Model): type = models.CharField(max_length=255) extension = models.ForeignKey('Extension', on_delete=models.PROTECT) need_infra = models.BooleanField(default=False) + domaine_ip = models.GenericIPAddressField(protocol='IPv4', unique=True, blank=True, null=True) + domaine_range = models.IntegerField(blank=True, null=True, validators=[MinValueValidator(8), MaxValueValidator(32)]) def __str__(self): return self.type diff --git a/machines/templates/machines/aff_iptype.html b/machines/templates/machines/aff_iptype.html index 0e54f061..7067b0cc 100644 --- a/machines/templates/machines/aff_iptype.html +++ b/machines/templates/machines/aff_iptype.html @@ -4,7 +4,9 @@ - + + + @@ -13,7 +15,9 @@ - + + + {% endfor %}
{{ key_dict }} Nombre de {{ key }} par {{ key_dict }}Type d'ip Extension Nécessite l'autorisation infraDomaine d'ipRange
{{ type.type }} {{ type.extension }} {{ type.need_infra }}{% if is_infra %} Editer{% endif %}{{ type.domaine_ip }}{{ type.domaine_range }}{% if is_infra %} Editer{% endif %} Historique