From 0706021fa2967fc7f2da31e61f136e5bab0cf816 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Mon, 26 Dec 2016 17:43:41 +0100 Subject: [PATCH] Change ns path --- machines/admin.py | 2 +- machines/forms.py | 4 ++-- .../migrations/0041_remove_ns_interface.py | 18 ++++++++++++++++ machines/migrations/0042_ns_ns.py | 21 +++++++++++++++++++ machines/models.py | 4 ++-- machines/serializers.py | 8 +++---- machines/templates/machines/aff_ns.html | 2 +- machines/views.py | 2 +- 8 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 machines/migrations/0041_remove_ns_interface.py create mode 100644 machines/migrations/0042_ns_ns.py diff --git a/machines/admin.py b/machines/admin.py index 1eddaa38..1e571ff7 100644 --- a/machines/admin.py +++ b/machines/admin.py @@ -20,7 +20,7 @@ class MxAdmin(VersionAdmin): list_display = ('zone', 'priority', 'name') class NsAdmin(VersionAdmin): - list_display = ('zone', 'interface') + list_display = ('zone', 'ns') class IpListAdmin(VersionAdmin): list_display = ('ipv4','ip_type') diff --git a/machines/forms.py b/machines/forms.py index 4b65c609..a0a34c75 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -152,11 +152,11 @@ class DelMxForm(ModelForm): class NsForm(ModelForm): class Meta: model = Ns - fields = ['zone', 'interface'] + fields = ['zone', 'ns'] class DelNsForm(ModelForm): ns = forms.ModelMultipleChoiceField(queryset=Ns.objects.all(), label="Enregistrements NS actuels", widget=forms.CheckboxSelectMultiple) class Meta: - exclude = ['zone', 'interface'] + exclude = ['zone', 'ns'] model = Ns diff --git a/machines/migrations/0041_remove_ns_interface.py b/machines/migrations/0041_remove_ns_interface.py new file mode 100644 index 00000000..88ea6985 --- /dev/null +++ b/machines/migrations/0041_remove_ns_interface.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0040_remove_interface_dns'), + ] + + operations = [ + migrations.RemoveField( + model_name='ns', + name='interface', + ), + ] diff --git a/machines/migrations/0042_ns_ns.py b/machines/migrations/0042_ns_ns.py new file mode 100644 index 00000000..2f0dd3f7 --- /dev/null +++ b/machines/migrations/0042_ns_ns.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', '0041_remove_ns_interface'), + ] + + operations = [ + migrations.AddField( + model_name='ns', + name='ns', + field=models.OneToOneField(to='machines.Domain', default=1, on_delete=django.db.models.deletion.PROTECT), + preserve_default=False, + ), + ] diff --git a/machines/models.py b/machines/models.py index 315627f7..6527f088 100644 --- a/machines/models.py +++ b/machines/models.py @@ -64,10 +64,10 @@ class Ns(models.Model): PRETTY_NAME = "Enregistrements NS" zone = models.ForeignKey('Extension', on_delete=models.PROTECT) - interface = models.OneToOneField('Interface', on_delete=models.PROTECT) + ns = models.OneToOneField('Domain', on_delete=models.PROTECT) def __str__(self): - return str(self.zone) + ' ' + str(self.interface) + return str(self.zone) + ' ' + str(self.ns) class Interface(models.Model): PRETTY_NAME = "Interface" diff --git a/machines/serializers.py b/machines/serializers.py index 97ae94f5..8c1dc789 100644 --- a/machines/serializers.py +++ b/machines/serializers.py @@ -27,7 +27,7 @@ class InterfaceSerializer(serializers.ModelSerializer): class ExtensionNameField(serializers.RelatedField): def to_representation(self, value): - return value.alias + return value.name class TypeSerializer(serializers.ModelSerializer): extension = ExtensionNameField(read_only=True) @@ -62,17 +62,17 @@ class MxSerializer(serializers.ModelSerializer): class NsSerializer(serializers.ModelSerializer): zone = serializers.SerializerMethodField('get_zone_name') - interface = serializers.SerializerMethodField('get_interface_name') + ns = serializers.SerializerMethodField('get_interface_name') class Meta: model = Ns - fields = ('zone', 'interface') + fields = ('zone', 'ns') def get_zone_name(self, obj): return obj.zone.name def get_interface_name(self, obj): - return obj.interface + return obj.ns class DomainSerializer(serializers.ModelSerializer): extension = serializers.SerializerMethodField('get_zone_name') diff --git a/machines/templates/machines/aff_ns.html b/machines/templates/machines/aff_ns.html index 56ba3b3e..678cc765 100644 --- a/machines/templates/machines/aff_ns.html +++ b/machines/templates/machines/aff_ns.html @@ -10,7 +10,7 @@ {% for ns in ns_list %} {{ ns.zone }} - {{ ns.interface }} + {{ ns.ns }} {% if is_infra %} {% include 'buttons/edit.html' with href='machines:edit-ns' id=ns.id %} diff --git a/machines/views.py b/machines/views.py index 9d86dab1..b7a36615 100644 --- a/machines/views.py +++ b/machines/views.py @@ -730,7 +730,7 @@ def mx(request): @login_required @permission_required('serveur') def ns(request): - ns = Ns.objects.filter(interface__in=Interface.objects.exclude(ipv4=None)) + ns = Ns.objects.exclude(ns__in=Domain.objects.filter(interface_parent__in=Interface.objects.filter(ipv4=None))) seria = NsSerializer(ns, many=True) return JSONResponse(seria.data)