From 60b741834f12202170aa5f411985374138936987 Mon Sep 17 00:00:00 2001 From: chirac Date: Mon, 18 Jul 2016 19:14:48 +0200 Subject: [PATCH] Type est un attribut de interface --- machines/admin.py | 4 +-- machines/forms.py | 14 +++++------ .../migrations/0020_auto_20160718_1849.py | 25 +++++++++++++++++++ machines/models.py | 2 +- machines/templates/machines/aff_machines.html | 6 ++--- machines/views.py | 14 +++++------ 6 files changed, 45 insertions(+), 20 deletions(-) create mode 100644 machines/migrations/0020_auto_20160718_1849.py diff --git a/machines/admin.py b/machines/admin.py index 02424537..850e8a9b 100644 --- a/machines/admin.py +++ b/machines/admin.py @@ -3,7 +3,7 @@ from django.contrib import admin from .models import Machine, MachineType, IpList, Interface, Extension class MachineAdmin(admin.ModelAdmin): - list_display = ('user','name','type','active') + list_display = ('user','name','active') class MachineTypeAdmin(admin.ModelAdmin): list_display = ('type','extension') @@ -15,7 +15,7 @@ class IpListAdmin(admin.ModelAdmin): list_display = ('ipv4',) class InterfaceAdmin(admin.ModelAdmin): - list_display = ('machine','dns','mac_address','ipv4','details') + list_display = ('machine','type','dns','mac_address','ipv4','details') admin.site.register(Machine, MachineAdmin) admin.site.register(MachineType, MachineTypeAdmin) diff --git a/machines/forms.py b/machines/forms.py index 009db045..7ba3909a 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -10,16 +10,14 @@ class EditMachineForm(ModelForm): def __init__(self, *args, **kwargs): super(EditMachineForm, self).__init__(*args, **kwargs) self.fields['name'].label = 'Nom de la machine' - self.fields['type'].label = 'Type de machine' - self.fields['type'].empty_label = "Séléctionner un type de machine" class NewMachineForm(EditMachineForm): class Meta(EditMachineForm.Meta): - fields = ['type','name'] + fields = ['name'] class BaseEditMachineForm(EditMachineForm): class Meta(EditMachineForm.Meta): - fields = ['type','name','active'] + fields = ['name','active'] class EditInterfaceForm(ModelForm): class Meta: @@ -30,10 +28,12 @@ class EditInterfaceForm(ModelForm): super(EditInterfaceForm, self).__init__(*args, **kwargs) self.fields['dns'].label = 'Nom dns de la machine' self.fields['mac_address'].label = 'Adresse mac' + self.fields['type'].label = 'Type de machine' + self.fields['type'].empty_label = "Séléctionner un type de machine" class AddInterfaceForm(EditInterfaceForm): class Meta(EditInterfaceForm.Meta): - fields = ['ipv4','mac_address','dns','details'] + fields = ['ipv4','mac_address','dns','type','details'] def __init__(self, *args, **kwargs): super(AddInterfaceForm, self).__init__(*args, **kwargs) @@ -41,11 +41,11 @@ class AddInterfaceForm(EditInterfaceForm): class NewInterfaceForm(EditInterfaceForm): class Meta(EditInterfaceForm.Meta): - fields = ['mac_address','dns','details'] + fields = ['mac_address','dns','type','details'] class BaseEditInterfaceForm(EditInterfaceForm): class Meta(EditInterfaceForm.Meta): - fields = ['ipv4','mac_address','dns','details'] + fields = ['ipv4','mac_address','dns','type','details'] def __init__(self, *args, **kwargs): super(BaseEditInterfaceForm, self).__init__(*args, **kwargs) diff --git a/machines/migrations/0020_auto_20160718_1849.py b/machines/migrations/0020_auto_20160718_1849.py new file mode 100644 index 00000000..1028368d --- /dev/null +++ b/machines/migrations/0020_auto_20160718_1849.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0019_auto_20160718_1141'), + ] + + operations = [ + migrations.RemoveField( + model_name='machine', + name='type', + ), + migrations.AddField( + model_name='interface', + name='type', + field=models.ForeignKey(to='machines.MachineType', default=1, on_delete=django.db.models.deletion.PROTECT), + preserve_default=False, + ), + ] diff --git a/machines/models.py b/machines/models.py index 3ef39702..bf52c9e1 100644 --- a/machines/models.py +++ b/machines/models.py @@ -4,7 +4,6 @@ from macaddress.fields import MACAddressField class Machine(models.Model): user = models.ForeignKey('users.User', on_delete=models.PROTECT) - type = models.ForeignKey('MachineType', on_delete=models.PROTECT) name = models.CharField(max_length=255, help_text="Optionnel", blank=True, null=True) active = models.BooleanField(default=True) @@ -35,6 +34,7 @@ class Interface(models.Model): #ipv6 = models.GenericIPAddressField(protocol='IPv6', null=True) mac_address = MACAddressField(integer=False, unique=True) machine = models.ForeignKey('Machine', on_delete=models.CASCADE) + type = models.ForeignKey('MachineType', on_delete=models.PROTECT) details = models.CharField(max_length=255, blank=True) dns = models.CharField(help_text="Obligatoire et unique, doit se terminer en %s et ne pas comporter d'autres points" % ", ".join(Extension.objects.values_list('name', flat=True)), max_length=255, unique=True) diff --git a/machines/templates/machines/aff_machines.html b/machines/templates/machines/aff_machines.html index ee601e69..5bf72384 100644 --- a/machines/templates/machines/aff_machines.html +++ b/machines/templates/machines/aff_machines.html @@ -2,20 +2,19 @@ Proprietaire - Type Interfaces {% for machine in machines_list %} - {{ machine.user }} - {{ machine.type }} +

{{ machine.user }}

Ajouter une interface

Supprimer la machine

+ @@ -24,6 +23,7 @@ {% for interface in machine.interface_set.all %} +
Nom dnsType Mac Ipv4
{{ interface.dns }}{{ interface.type }} {{ interface.mac_address }} {{ interface.ipv4 }} Editer diff --git a/machines/views.py b/machines/views.py index 1dcbf309..f714320e 100644 --- a/machines/views.py +++ b/machines/views.py @@ -11,15 +11,15 @@ from django.db.models import ProtectedError from django.forms import ValidationError import re -from .forms import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm, NewInterfaceForm, MachineTypeForm, DelMachineTypeForm, ExtensionForm, DelExtensionForm, BaseEditInterfaceForm, BaseEditMachineForm +from .forms import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm, MachineTypeForm, DelMachineTypeForm, ExtensionForm, DelExtensionForm, BaseEditInterfaceForm, BaseEditMachineForm from .models import Machine, Interface, IpList, MachineType, Extension from users.models import User -def full_domain_validator(request, interface, machine): +def full_domain_validator(request, interface): """ Validation du nom de domaine, extensions dans type de machine, prefixe pas plus long que 63 caractères """ HOSTNAME_LABEL_PATTERN = re.compile("(?!-)[A-Z\d-]+(?