diff --git a/machines/admin.py b/machines/admin.py index 0ee9d483..7ee8cde1 100644 --- a/machines/admin.py +++ b/machines/admin.py @@ -1,14 +1,18 @@ from django.contrib import admin from reversion.admin import VersionAdmin -from .models import Machine, MachineType, IpList, Interface, Extension +from .models import IpType, Machine, MachineType, IpList, Interface, Extension class MachineAdmin(VersionAdmin): list_display = ('user','name','active') -class MachineTypeAdmin(VersionAdmin): +class IpTypeAdmin(VersionAdmin): list_display = ('type','extension','need_infra') +class MachineTypeAdmin(VersionAdmin): + list_display = ('type','ip_type') + + class ExtensionAdmin(VersionAdmin): list_display = ('name',) @@ -20,6 +24,7 @@ class InterfaceAdmin(VersionAdmin): admin.site.register(Machine, MachineAdmin) admin.site.register(MachineType, MachineTypeAdmin) +admin.site.register(IpType, IpTypeAdmin) admin.site.register(Extension, ExtensionAdmin) admin.site.register(IpList, IpListAdmin) admin.site.register(Interface, InterfaceAdmin) diff --git a/machines/forms.py b/machines/forms.py index 8a0b744e..5b40f2ca 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, IpList, MachineType, Extension +from .models import Machine, Interface, IpList, MachineType, Extension, IpType class EditMachineForm(ModelForm): class Meta: @@ -40,8 +40,8 @@ class AddInterfaceForm(EditInterfaceForm): 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)) + self.fields['type'].queryset = MachineType.objects.filter(ip_type=IpType.objects.filter(need_infra=False)) + self.fields['ipv4'].queryset = IpList.objects.filter(ip_type=IpType.objects.filter(need_infra=False)) class NewInterfaceForm(EditInterfaceForm): class Meta(EditInterfaceForm.Meta): @@ -56,25 +56,43 @@ class BaseEditInterfaceForm(EditInterfaceForm): 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)) + self.fields['type'].queryset = MachineType.objects.filter(IpType.objects.filter(need_infra=False)) + self.fields['ipv4'].queryset = IpList.objects.filter(ip_type=IpType.objects.filter(need_infra=False)) class MachineTypeForm(ModelForm): class Meta: model = MachineType - fields = ['type','extension','need_infra'] + fields = ['type','ip_type'] def __init__(self, *args, **kwargs): super(MachineTypeForm, self).__init__(*args, **kwargs) self.fields['type'].label = 'Type de machine à ajouter' + self.fields['ip_type'].label = "Type d'ip relié" class DelMachineTypeForm(ModelForm): machinetypes = forms.ModelMultipleChoiceField(queryset=MachineType.objects.all(), label="Types de machines actuelles", widget=forms.CheckboxSelectMultiple) class Meta: - exclude = ['type','extension'] + exclude = ['type','ip_type'] model = MachineType +class IpTypeForm(ModelForm): + class Meta: + model = IpType + fields = ['type','extension','need_infra'] + + def __init__(self, *args, **kwargs): + super(IpTypeForm, self).__init__(*args, **kwargs) + self.fields['type'].label = 'Type ip à ajouter' + +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'] + model = IpType + + class ExtensionForm(ModelForm): class Meta: model = Extension diff --git a/machines/migrations/0025_auto_20161023_0038.py b/machines/migrations/0025_auto_20161023_0038.py new file mode 100644 index 00000000..c425e539 --- /dev/null +++ b/machines/migrations/0025_auto_20161023_0038.py @@ -0,0 +1,42 @@ +# -*- 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', '0024_machinetype_need_infra'), + ] + + operations = [ + migrations.CreateModel( + name='IpType', + fields=[ + ('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)), + ('type', models.CharField(max_length=255)), + ('need_infra', models.BooleanField(default=False)), + ('extension', models.ForeignKey(to='machines.Extension', on_delete=django.db.models.deletion.PROTECT)), + ], + ), + migrations.RemoveField( + model_name='machinetype', + name='extension', + ), + migrations.RemoveField( + model_name='machinetype', + name='need_infra', + ), + migrations.AlterField( + model_name='iplist', + name='ip_type', + field=models.ForeignKey(to='machines.IpType', on_delete=django.db.models.deletion.PROTECT), + ), + migrations.AddField( + model_name='machinetype', + name='ip_type', + field=models.ForeignKey(to='machines.IpType', null=True, blank=True, on_delete=django.db.models.deletion.PROTECT), + ), + ] diff --git a/machines/models.py b/machines/models.py index 8c62ace0..b764edfc 100644 --- a/machines/models.py +++ b/machines/models.py @@ -16,6 +16,13 @@ class Machine(models.Model): return str(self.user) + ' - ' + str(self.id) + ' - ' + str(self.name) class MachineType(models.Model): + type = models.CharField(max_length=255) + ip_type = models.ForeignKey('IpType', on_delete=models.PROTECT, blank=True, null=True) + + def __str__(self): + return self.type + +class IpType(models.Model): type = models.CharField(max_length=255) extension = models.ForeignKey('Extension', on_delete=models.PROTECT) need_infra = models.BooleanField(default=False) @@ -49,7 +56,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) + ip_type = models.ForeignKey('IpType', on_delete=models.PROTECT) def __str__(self): return self.ipv4 diff --git a/machines/templates/machines/aff_iptype.html b/machines/templates/machines/aff_iptype.html new file mode 100644 index 00000000..0e54f061 --- /dev/null +++ b/machines/templates/machines/aff_iptype.html @@ -0,0 +1,21 @@ +
Type d'ip | +Extension | +Nécessite l'autorisation infra | ++ | + |
---|---|---|---|---|
{{ type.type }} | +{{ type.extension }} | +{{ type.need_infra }} | +{% if is_infra %} Editer{% endif %} | +Historique | +
Liste des types des extensions
+ {% endif %} {% endblock %} diff --git a/machines/urls.py b/machines/urls.py index 5f1280f2..c0c2f07a 100644 --- a/machines/urls.py +++ b/machines/urls.py @@ -12,6 +12,10 @@ urlpatterns = [ url(r'^edit_machinetype/(?P