From fd914066d4e724fc1aa6e8317aa308469f067c55 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sun, 23 Oct 2016 00:55:58 +0200 Subject: [PATCH] =?UTF-8?q?Diff=C3=A9rencie=20iptype=20et=20machinetype?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- machines/admin.py | 9 ++- machines/forms.py | 32 +++++++-- .../migrations/0025_auto_20161023_0038.py | 42 +++++++++++ machines/models.py | 9 ++- machines/templates/machines/aff_iptype.html | 21 ++++++ .../templates/machines/aff_machinetype.html | 6 +- machines/templates/machines/index_iptype.html | 17 +++++ machines/templates/machines/sidebar.html | 1 + machines/urls.py | 5 ++ machines/views.py | 71 +++++++++++++++++-- users/migrations/0036_auto_20161022_2146.py | 19 +++++ 11 files changed, 213 insertions(+), 19 deletions(-) create mode 100644 machines/migrations/0025_auto_20161023_0038.py create mode 100644 machines/templates/machines/aff_iptype.html create mode 100644 machines/templates/machines/index_iptype.html create mode 100644 users/migrations/0036_auto_20161022_2146.py 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 @@ + + + + + + + + + + + {% for type in iptype_list %} + + + + + + + + {% endfor %} +
Type d'ipExtensionNécessite l'autorisation infra
{{ type.type }}{{ type.extension }}{{ type.need_infra }}{% if is_infra %} Editer{% endif %} Historique
+ diff --git a/machines/templates/machines/aff_machinetype.html b/machines/templates/machines/aff_machinetype.html index ea5d8691..5bdbd127 100644 --- a/machines/templates/machines/aff_machinetype.html +++ b/machines/templates/machines/aff_machinetype.html @@ -2,8 +2,7 @@ Type de machine - Extension - Nécessite l'autorisation infra + Type d'ip correspondant @@ -11,8 +10,7 @@ {% for type in machinetype_list %} {{ type.type }} - {{ type.extension }} - {{ type.need_infra }} + {{ type.ip_type }} {% if is_infra %} Editer{% endif %} Historique diff --git a/machines/templates/machines/index_iptype.html b/machines/templates/machines/index_iptype.html new file mode 100644 index 00000000..16648d2c --- /dev/null +++ b/machines/templates/machines/index_iptype.html @@ -0,0 +1,17 @@ +{% extends "machines/sidebar.html" %} +{% load bootstrap3 %} + +{% block title %}Ip{% endblock %} + +{% block content %} +

Liste des types d'ip

+ {% if is_infra %} + Ajouter un type d'ip + Supprimer un ou plusieurs types d'ip + {% endif %} + {% include "machines/aff_iptype.html" with iptype_list=iptype_list %} +
+
+
+{% endblock %} + diff --git a/machines/templates/machines/sidebar.html b/machines/templates/machines/sidebar.html index 9647b75f..80650a2d 100644 --- a/machines/templates/machines/sidebar.html +++ b/machines/templates/machines/sidebar.html @@ -4,5 +4,6 @@ {% if is_cableur %}

Liste des types de machine

Liste des types des extensions

+

Liste des types d'ip

{% 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[0-9]+)$', views.edit_machinetype, name='edit-machinetype'), url(r'^del_machinetype/$', views.del_machinetype, name='del-machinetype'), url(r'^index_machinetype/$', views.index_machinetype, name='index-machinetype'), + url(r'^add_iptype/$', views.add_iptype, name='add-iptype'), + url(r'^edit_iptype/(?P[0-9]+)$', views.edit_iptype, name='edit-iptype'), + url(r'^del_iptype/$', views.del_iptype, name='del-iptype'), + url(r'^index_iptype/$', views.index_iptype, name='index-iptype'), url(r'^add_extension/$', views.add_extension, name='add-extension'), url(r'^edit_extension/(?P[0-9]+)$', views.edit_extension, name='edit-extension'), url(r'^del_extension/$', views.del_extension, name='del-extension'), @@ -20,6 +24,7 @@ urlpatterns = [ url(r'^history/(?Pinterface)/(?P[0-9]+)$', views.history, name='history'), url(r'^history/(?Pmachinetype)/(?P[0-9]+)$', views.history, name='history'), url(r'^history/(?Pextension)/(?P[0-9]+)$', views.history, name='history'), + url(r'^history/(?Piptype)/(?P[0-9]+)$', views.history, name='history'), url(r'^$', views.index, name='index'), url(r'^rest/mac-ip/$', views.mac_ip, name='mac-ip'), url(r'^rest/mac-ip-dns/$', views.mac_ip_dns, name='mac-ip-dns'), diff --git a/machines/views.py b/machines/views.py index 0c9cafaf..332d3563 100644 --- a/machines/views.py +++ b/machines/views.py @@ -20,7 +20,8 @@ from reversion import revisions as reversion import re from .forms import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm, MachineTypeForm, DelMachineTypeForm, ExtensionForm, DelExtensionForm, BaseEditInterfaceForm, BaseEditMachineForm -from .models import Machine, Interface, IpList, MachineType, Extension +from .forms import IpTypeForm, DelIpTypeForm +from .models import IpType, Machine, Interface, IpList, MachineType, Extension from users.models import User from re2o.settings import PAGINATION_NUMBER, PAGINATION_LARGE_NUMBER @@ -28,7 +29,7 @@ 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-]+(?