From b0c1bacc0f509e14e90e5499c69ae120e13a3878 Mon Sep 17 00:00:00 2001 From: chirac Date: Sat, 19 Nov 2016 17:44:43 +0100 Subject: [PATCH] Omnibus, Gestion des MX par re2o , creation d'un model Ns --- machines/admin.py | 10 ++- machines/forms.py | 28 ++++++- .../migrations/0031_auto_20161119_1709.py | 43 +++++++++++ machines/models.py | 22 +++++- machines/templates/machines/aff_machines.html | 4 +- machines/templates/machines/aff_mx.html | 26 +++++++ .../templates/machines/index_extension.html | 15 +++- machines/urls.py | 5 ++ machines/views.py | 75 ++++++++++++++++++- 9 files changed, 211 insertions(+), 17 deletions(-) create mode 100644 machines/migrations/0031_auto_20161119_1709.py create mode 100644 machines/templates/machines/aff_mx.html diff --git a/machines/admin.py b/machines/admin.py index 658d8f85..b2550c68 100644 --- a/machines/admin.py +++ b/machines/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin from reversion.admin import VersionAdmin -from .models import IpType, Machine, MachineType, Alias, IpList, Interface, Extension +from .models import IpType, Machine, MachineType, Alias, IpList, Interface, Extension, Mx, Ns class MachineAdmin(VersionAdmin): list_display = ('user','name','active') @@ -16,6 +16,12 @@ class MachineTypeAdmin(VersionAdmin): class ExtensionAdmin(VersionAdmin): list_display = ('name',) +class MxAdmin(VersionAdmin): + list_display = ('zone', 'priority', 'name') + +class NsAdmin(VersionAdmin): + list_display = ('zone', 'interface') + class IpListAdmin(VersionAdmin): list_display = ('ipv4','ip_type') @@ -29,6 +35,8 @@ admin.site.register(Machine, MachineAdmin) admin.site.register(MachineType, MachineTypeAdmin) admin.site.register(IpType, IpTypeAdmin) admin.site.register(Extension, ExtensionAdmin) +admin.site.register(Mx, MxAdmin) +admin.site.register(Ns, NsAdmin) admin.site.register(IpList, IpListAdmin) admin.site.register(Interface, InterfaceAdmin) admin.site.register(Alias, AliasAdmin) diff --git a/machines/forms.py b/machines/forms.py index 9ee9558e..6b3d905e 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -1,6 +1,6 @@ from django.forms import ModelForm, Form, ValidationError from django import forms -from .models import Alias, Machine, Interface, IpList, MachineType, Extension, IpType +from .models import Alias, Machine, Interface, IpList, MachineType, Extension, Mx, Ns, IpType class EditMachineForm(ModelForm): class Meta: @@ -62,11 +62,18 @@ class BaseEditInterfaceForm(EditInterfaceForm): class NewAliasForm(ModelForm): class Meta: model = Alias - fields = ['alias'] + fields = ['alias','extension'] -class EditAliasFullForm(NewAliasForm): +class EditAliasForm(NewAliasForm): class Meta(NewAliasForm.Meta): - fields = '__all__' + fields = ['alias','extension'] + +class DelAliasForm(ModelForm): + del_alias = forms.ModelMultipleChoiceField(queryset=Alias.objects.all(), label="Alias actuels", widget=forms.CheckboxSelectMultiple) + + class Meta: + exclude = ['interface_parent', 'alias', 'extension'] + model = Alias class MachineTypeForm(ModelForm): class Meta: @@ -117,3 +124,16 @@ class DelExtensionForm(ModelForm): class Meta: exclude = ['name'] model = Extension + +class MxForm(ModelForm): + class Meta: + model = Mx + fields = ['zone', 'priority', 'name'] + +class DelMxForm(ModelForm): + mx = forms.ModelMultipleChoiceField(queryset=Mx.objects.all(), label="MX actuels", widget=forms.CheckboxSelectMultiple) + + class Meta: + exclude = ['zone', 'priority', 'name'] + model = Mx + diff --git a/machines/migrations/0031_auto_20161119_1709.py b/machines/migrations/0031_auto_20161119_1709.py new file mode 100644 index 00000000..35387793 --- /dev/null +++ b/machines/migrations/0031_auto_20161119_1709.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion +import django.core.validators + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0030_auto_20161118_1730'), + ] + + operations = [ + migrations.CreateModel( + name='Mx', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, verbose_name='ID', serialize=False)), + ('priority', models.IntegerField(unique=True)), + ('name', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, to='machines.Alias')), + ('zone', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='machines.Extension')), + ], + ), + migrations.CreateModel( + name='Ns', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, verbose_name='ID', serialize=False)), + ('interface', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, to='machines.Interface')), + ('zone', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='machines.Extension')), + ], + ), + migrations.AlterField( + model_name='iptype', + name='domaine_ip', + field=models.GenericIPAddressField(protocol='IPv4'), + ), + migrations.AlterField( + model_name='iptype', + name='domaine_range', + field=models.IntegerField(validators=[django.core.validators.MinValueValidator(8), django.core.validators.MaxValueValidator(32)]), + ), + ] diff --git a/machines/models.py b/machines/models.py index 0e2e264d..bf1eca2e 100644 --- a/machines/models.py +++ b/machines/models.py @@ -34,8 +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)]) + domaine_ip = models.GenericIPAddressField(protocol='IPv4') + domaine_range = models.IntegerField(validators=[MinValueValidator(8), MaxValueValidator(32)]) def __str__(self): return self.type @@ -48,6 +48,22 @@ class Extension(models.Model): def __str__(self): return self.name +class Mx(models.Model): + PRETTY_NAME = "Enregistrements MX" + + zone = models.ForeignKey('Extension', on_delete=models.PROTECT) + priority = models.IntegerField(unique=True) + name = models.OneToOneField('Alias', on_delete=models.PROTECT) + + def __str__(self): + return str(self.zone) + ' ' + str(self.priority) + ' ' + str(self.name) + +class Ns(models.Model): + PRETTY_NAME = "Enregistrements NS" + + zone = models.ForeignKey('Extension', on_delete=models.PROTECT) + interface = models.OneToOneField('Interface', on_delete=models.PROTECT) + class Interface(models.Model): PRETTY_NAME = "Interface" @@ -92,7 +108,7 @@ class Alias(models.Model): raise ValidationError("Impossible d'ajouter l'alias, déjà utilisé par une machine") def __str__(self): - return self.alias + return str(self.alias) + str(self.extension) class IpList(models.Model): PRETTY_NAME = "Addresses ipv4" diff --git a/machines/templates/machines/aff_machines.html b/machines/templates/machines/aff_machines.html index 2eff473c..75011282 100644 --- a/machines/templates/machines/aff_machines.html +++ b/machines/templates/machines/aff_machines.html @@ -36,8 +36,8 @@