mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 07:02:26 +00:00
Ajout du domaine d'ip
This commit is contained in:
parent
d82e1af4fd
commit
e538d3b2dc
8 changed files with 81 additions and 10 deletions
|
@ -1,8 +1,13 @@
|
|||
<ul class="pagination nav navbar-nav">
|
||||
<li><a href="?onglet=1">1 mois</a></li>
|
||||
<li><a href="?onglet=2">2 mois</a></li>
|
||||
</ul>
|
||||
|
||||
{% for key_dict, stats_dict in stats_list.items %}
|
||||
{% for key, stats in stats_dict.items %}
|
||||
<table class="table table-striped">
|
||||
<h4>Statistiques par {{ key_dict }} de {{ key }}</h4>
|
||||
<thead>
|
||||
<h4>Statistiques par {{ key_dict }} de {{ key }}</h4>
|
||||
<tr>
|
||||
<th>{{ key_dict }}</th>
|
||||
<th>Nombre de {{ key }} par {{ key_dict }}</th>
|
||||
|
|
|
@ -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],
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
19
machines/migrations/0028_iptype_domaine_ip.py
Normal file
19
machines/migrations/0028_iptype_domaine_ip.py
Normal file
|
@ -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'),
|
||||
),
|
||||
]
|
20
machines/migrations/0029_iptype_domaine_range.py
Normal file
20
machines/migrations/0029_iptype_domaine_range.py
Normal file
|
@ -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),
|
||||
),
|
||||
]
|
|
@ -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
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
<th>Type d'ip</th>
|
||||
<th>Extension</th>
|
||||
<th>Nécessite l'autorisation infra</th>
|
||||
<th>Domaine d'ip</th>
|
||||
<th>Range</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
@ -13,6 +15,8 @@
|
|||
<td>{{ type.type }}</td>
|
||||
<td>{{ type.extension }}</td>
|
||||
<td>{{ type.need_infra }}</td>
|
||||
<td>{{ type.domaine_ip }}</td>
|
||||
<td>{{ type.domaine_range }}</td>
|
||||
<td>{% if is_infra %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:edit-iptype' type.id %}"><i class="glyphicon glyphicon-pushpin"></i> Editer</a>{% endif %}</td>
|
||||
<td><a class="btn btn-info btn-sm" role="button" href="{% url 'machines:history' 'iptype' type.id %}"><i class="glyphicon glyphicon-repeat"></i> Historique</a></td>
|
||||
</tr>
|
||||
|
|
Loading…
Reference in a new issue