diff --git a/machines/admin.py b/machines/admin.py index b4446277..0ee9d483 100644 --- a/machines/admin.py +++ b/machines/admin.py @@ -7,13 +7,13 @@ class MachineAdmin(VersionAdmin): list_display = ('user','name','active') class MachineTypeAdmin(VersionAdmin): - list_display = ('type','extension') + list_display = ('type','extension','need_infra') class ExtensionAdmin(VersionAdmin): list_display = ('name',) class IpListAdmin(VersionAdmin): - list_display = ('ipv4',) + list_display = ('ipv4','ip_type') class InterfaceAdmin(VersionAdmin): list_display = ('machine','type','dns','mac_address','ipv4','details') diff --git a/machines/forms.py b/machines/forms.py index 7ba3909a..8a0b744e 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 Machine, Interface, MachineType, Extension +from .models import Machine, Interface, IpList, MachineType, Extension class EditMachineForm(ModelForm): class Meta: @@ -36,8 +36,12 @@ class AddInterfaceForm(EditInterfaceForm): fields = ['ipv4','mac_address','dns','type','details'] def __init__(self, *args, **kwargs): + infra = kwargs.pop('infra') super(AddInterfaceForm, self).__init__(*args, **kwargs) self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4" + if not infra: + self.fields['type'].queryset = MachineType.objects.filter(need_infra=False) + self.fields['ipv4'].queryset = IpList.objects.filter(ip_type=MachineType.objects.filter(need_infra=False)) class NewInterfaceForm(EditInterfaceForm): class Meta(EditInterfaceForm.Meta): @@ -47,14 +51,18 @@ class BaseEditInterfaceForm(EditInterfaceForm): class Meta(EditInterfaceForm.Meta): fields = ['ipv4','mac_address','dns','type','details'] - def __init__(self, *args, **kwargs): + def __init__(self, infra=False, *args, **kwargs): + infra = kwargs.pop('infra') super(BaseEditInterfaceForm, self).__init__(*args, **kwargs) self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4" + if not infra: + self.fields['type'].queryset = MachineType.objects.filter(need_infra=False) + self.fields['ipv4'].queryset = IpList.objects.filter(ip_type=MachineType.objects.filter(need_infra=False)) class MachineTypeForm(ModelForm): class Meta: model = MachineType - fields = ['type','extension'] + fields = ['type','extension','need_infra'] def __init__(self, *args, **kwargs): super(MachineTypeForm, self).__init__(*args, **kwargs) diff --git a/machines/migrations/0023_iplist_ip_type.py b/machines/migrations/0023_iplist_ip_type.py new file mode 100644 index 00000000..cd40aec5 --- /dev/null +++ b/machines/migrations/0023_iplist_ip_type.py @@ -0,0 +1,21 @@ +# -*- 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', '0022_auto_20161011_1829'), + ] + + operations = [ + migrations.AddField( + model_name='iplist', + name='ip_type', + field=models.ForeignKey(to='machines.MachineType', on_delete=django.db.models.deletion.PROTECT, default=1), + preserve_default=False, + ), + ] diff --git a/machines/migrations/0024_machinetype_need_infra.py b/machines/migrations/0024_machinetype_need_infra.py new file mode 100644 index 00000000..8bc985d4 --- /dev/null +++ b/machines/migrations/0024_machinetype_need_infra.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', '0023_iplist_ip_type'), + ] + + operations = [ + migrations.AddField( + model_name='machinetype', + name='need_infra', + field=models.BooleanField(default=False), + ), + ] diff --git a/machines/models.py b/machines/models.py index a4c38aec..8c62ace0 100644 --- a/machines/models.py +++ b/machines/models.py @@ -18,6 +18,7 @@ class Machine(models.Model): class MachineType(models.Model): type = models.CharField(max_length=255) extension = models.ForeignKey('Extension', on_delete=models.PROTECT) + need_infra = models.BooleanField(default=False) def __str__(self): return self.type @@ -48,6 +49,7 @@ class Interface(models.Model): class IpList(models.Model): ipv4 = models.GenericIPAddressField(protocol='IPv4', unique=True) + ip_type = models.ForeignKey('MachineType', on_delete=models.PROTECT) def __str__(self): return self.ipv4 diff --git a/machines/templates/machines/aff_machinetype.html b/machines/templates/machines/aff_machinetype.html index 255c94ee..ea5d8691 100644 --- a/machines/templates/machines/aff_machinetype.html +++ b/machines/templates/machines/aff_machinetype.html @@ -3,6 +3,7 @@