From 2d0033e556176d68a908b3ac96716819426ef408 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Wed, 15 Nov 2017 03:06:33 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Fix=20bug=20sur=20l'edition=20du=20txt=20+?= =?UTF-8?q?=20=C3=A9largi=20le=20champ=20pour=20dnssec?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0064_auto_20171115_0253.py | 20 +++++++++++++++++++ machines/models.py | 2 +- machines/templates/machines/aff_txt.html | 2 +- machines/urls.py | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 machines/migrations/0064_auto_20171115_0253.py diff --git a/machines/migrations/0064_auto_20171115_0253.py b/machines/migrations/0064_auto_20171115_0253.py new file mode 100644 index 00000000..a028e2cb --- /dev/null +++ b/machines/migrations/0064_auto_20171115_0253.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-11-15 01:53 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0063_auto_20171020_0040'), + ] + + operations = [ + migrations.AlterField( + model_name='text', + name='field2', + field=models.TextField(max_length=2047), + ), + ] diff --git a/machines/models.py b/machines/models.py index c2cd2143..6453f08a 100644 --- a/machines/models.py +++ b/machines/models.py @@ -388,7 +388,7 @@ class Text(models.Model): zone = models.ForeignKey('Extension', on_delete=models.PROTECT) field1 = models.CharField(max_length=255) - field2 = models.CharField(max_length=255) + field2 = models.TextField(max_length=2047) def __str__(self): return str(self.zone) + " : " + str(self.field1) + " " +\ diff --git a/machines/templates/machines/aff_txt.html b/machines/templates/machines/aff_txt.html index fd7c5ee6..eb060440 100644 --- a/machines/templates/machines/aff_txt.html +++ b/machines/templates/machines/aff_txt.html @@ -31,7 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc., - {% for txt in txt_list %} + {% for txt in text_list %} {{ txt.zone }} {{ txt.dns_entry }} diff --git a/machines/urls.py b/machines/urls.py index 3669b5b9..906fec1c 100644 --- a/machines/urls.py +++ b/machines/urls.py @@ -51,7 +51,7 @@ urlpatterns = [ url(r'^edit_mx/(?P[0-9]+)$', views.edit_mx, name='edit-mx'), url(r'^del_mx/$', views.del_mx, name='del-mx'), url(r'^add_txt/$', views.add_txt, name='add-txt'), - url(r'^edit_txt/(?P[0-9]+)$', views.edit_txt, name='edit-txt'), + url(r'^edit_txt/(?P[0-9]+)$', views.edit_txt, name='edit-txt'), url(r'^del_txt/$', views.del_txt, name='del-txt'), url(r'^add_ns/$', views.add_ns, name='add-ns'), url(r'^edit_ns/(?P[0-9]+)$', views.edit_ns, name='edit-ns'), From da06613505c7b707b4da99a62b86a35988d8b128 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Wed, 15 Nov 2017 15:17:22 +0100 Subject: [PATCH 2/2] Text devient Txt --- machines/admin.py | 6 ++--- machines/forms.py | 6 ++--- .../migrations/0065_auto_20171115_1514.py | 19 ++++++++++++++++ machines/models.py | 6 ++--- machines/serializers.py | 12 +++++----- machines/templates/machines/aff_txt.html | 2 +- machines/urls.py | 2 +- machines/views.py | 22 +++++++++---------- 8 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 machines/migrations/0065_auto_20171115_1514.py diff --git a/machines/admin.py b/machines/admin.py index 93e936e6..763cff43 100644 --- a/machines/admin.py +++ b/machines/admin.py @@ -27,7 +27,7 @@ from django.contrib import admin from reversion.admin import VersionAdmin from .models import IpType, Machine, MachineType, Domain, IpList, Interface -from .models import Extension, SOA, Mx, Ns, Vlan, Text, Nas, Service +from .models import Extension, SOA, Mx, Ns, Vlan, Txt, Nas, Service from .models import OuverturePort, OuverturePortList @@ -63,7 +63,7 @@ class NsAdmin(VersionAdmin): pass -class TextAdmin(VersionAdmin): +class TxtAdmin(VersionAdmin): pass @@ -102,7 +102,7 @@ admin.site.register(Extension, ExtensionAdmin) admin.site.register(SOA, SOAAdmin) admin.site.register(Mx, MxAdmin) admin.site.register(Ns, NsAdmin) -admin.site.register(Text, TextAdmin) +admin.site.register(Txt, TxtAdmin) admin.site.register(IpList, IpListAdmin) admin.site.register(Interface, InterfaceAdmin) admin.site.register(Domain, DomainAdmin) diff --git a/machines/forms.py b/machines/forms.py index 2c1c53c7..b043d9f5 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -47,7 +47,7 @@ from .models import ( Extension, SOA, Mx, - Text, + Txt, Ns, Service, Vlan, @@ -364,7 +364,7 @@ class DelNsForm(Form): class TxtForm(ModelForm): """Ajout d'un txt pour une zone""" class Meta: - model = Text + model = Txt fields = '__all__' def __init__(self, *args, **kwargs): @@ -375,7 +375,7 @@ class TxtForm(ModelForm): class DelTxtForm(Form): """Suppression d'un ou plusieurs TXT""" txt = forms.ModelMultipleChoiceField( - queryset=Text.objects.all(), + queryset=Txt.objects.all(), label="Enregistrements Txt actuels", widget=forms.CheckboxSelectMultiple ) diff --git a/machines/migrations/0065_auto_20171115_1514.py b/machines/migrations/0065_auto_20171115_1514.py new file mode 100644 index 00000000..c8c5699b --- /dev/null +++ b/machines/migrations/0065_auto_20171115_1514.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-11-15 14:14 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0064_auto_20171115_0253'), + ] + + operations = [ + migrations.RenameModel( + old_name='Text', + new_name='Txt', + ), + ] diff --git a/machines/models.py b/machines/models.py index 6453f08a..e3104f22 100644 --- a/machines/models.py +++ b/machines/models.py @@ -382,7 +382,7 @@ class Ns(models.Model): return str(self.zone) + ' ' + str(self.ns) -class Text(models.Model): +class Txt(models.Model): """ Un enregistrement TXT associé à une extension""" PRETTY_NAME = "Enregistrement TXT" @@ -920,13 +920,13 @@ def ns_post_delete(sender, **kwargs): regen('dns') -@receiver(post_save, sender=Text) +@receiver(post_save, sender=Txt) def text_post_save(sender, **kwargs): """Regeneration dns après modification d'un TXT""" regen('dns') -@receiver(post_delete, sender=Text) +@receiver(post_delete, sender=Txt) def text_post_delete(sender, **kwargs): """Regeneration dns après modification d'un TX""" regen('dns') diff --git a/machines/serializers.py b/machines/serializers.py index 7d78ebc3..6d128da4 100644 --- a/machines/serializers.py +++ b/machines/serializers.py @@ -31,7 +31,7 @@ from machines.models import ( IpList, MachineType, Domain, - Text, + Txt, Mx, Service_link, Ns, @@ -195,20 +195,20 @@ class MxSerializer(serializers.ModelSerializer): return str(obj.dns_entry) -class TextSerializer(serializers.ModelSerializer): +class TxtSerializer(serializers.ModelSerializer): """Serialisation d'un txt : zone cible et l'entrée txt sont evaluées à part""" zone = serializers.SerializerMethodField('get_zone_name') - text_entry = serializers.SerializerMethodField('get_text_name') + txt_entry = serializers.SerializerMethodField('get_txt_name') class Meta: - model = Text - fields = ('zone', 'text_entry', 'field1', 'field2') + model = Txt + fields = ('zone', 'txt_entry', 'field1', 'field2') def get_zone_name(self, obj): return str(obj.zone.name) - def get_text_name(self, obj): + def get_txt_name(self, obj): return str(obj.dns_entry) diff --git a/machines/templates/machines/aff_txt.html b/machines/templates/machines/aff_txt.html index eb060440..fd7c5ee6 100644 --- a/machines/templates/machines/aff_txt.html +++ b/machines/templates/machines/aff_txt.html @@ -31,7 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc., - {% for txt in text_list %} + {% for txt in txt_list %} {{ txt.zone }} {{ txt.dns_entry }} diff --git a/machines/urls.py b/machines/urls.py index 906fec1c..e9306605 100644 --- a/machines/urls.py +++ b/machines/urls.py @@ -94,7 +94,7 @@ urlpatterns = [ url(r'^rest/corresp/$', views.corresp, name='corresp'), url(r'^rest/mx/$', views.mx, name='mx'), url(r'^rest/ns/$', views.ns, name='ns'), - url(r'^rest/text/$', views.text, name='text'), + url(r'^rest/txt/$', views.txt, name='txt'), url(r'^rest/zones/$', views.zones, name='zones'), url(r'^rest/service_servers/$', views.service_servers, name='service-servers'), url(r'^rest/ouverture_ports/$', views.ouverture_ports, name='ouverture-ports'), diff --git a/machines/views.py b/machines/views.py index de7fd414..3508cba2 100644 --- a/machines/views.py +++ b/machines/views.py @@ -48,7 +48,7 @@ from machines.serializers import ( FullInterfaceSerializer, InterfaceSerializer, TypeSerializer, DomainSerializer, - TextSerializer, + TxtSerializer, MxSerializer, ExtensionSerializer, ServiceServersSerializer, @@ -109,7 +109,7 @@ from .models import ( Service_link, Vlan, Nas, - Text, + Txt, OuverturePortList, OuverturePort ) @@ -721,8 +721,8 @@ def add_txt(request): @permission_required('infra') def edit_txt(request, txtid): try: - txt_instance = Text.objects.get(pk=txtid) - except Text.DoesNotExist: + txt_instance = Txt.objects.get(pk=txtid) + except Txt.DoesNotExist: messages.error(request, u"Entrée inexistante" ) return redirect(reverse('machines:index-extension')) txt = TxtForm(request.POST or None, instance=txt_instance) @@ -1045,8 +1045,8 @@ def index_extension(request): soa_list = SOA.objects.order_by('name') mx_list = Mx.objects.order_by('zone').select_related('zone').select_related('name__extension') ns_list = Ns.objects.order_by('zone').select_related('zone').select_related('ns__extension') - text_list = Text.objects.all().select_related('zone') - return render(request, 'machines/index_extension.html', {'extension_list':extension_list, 'soa_list': soa_list, 'mx_list': mx_list, 'ns_list': ns_list, 'text_list' : text_list}) + txt_list = Txt.objects.all().select_related('zone') + return render(request, 'machines/index_extension.html', {'extension_list':extension_list, 'soa_list': soa_list, 'mx_list': mx_list, 'ns_list': ns_list, 'txt_list' : txt_list}) @login_required def index_alias(request, interfaceid): @@ -1141,8 +1141,8 @@ def history(request, object, id): return redirect(reverse('machines:index')) elif object == 'txt' and request.user.has_perms(('cableur',)): try: - object_instance = Text.objects.get(pk=id) - except Text.DoesNotExist: + object_instance = Txt.objects.get(pk=id) + except Txt.DoesNotExist: messages.error(request, "Txt inexistant") return redirect(reverse('machines:index')) elif object == 'ns' and request.user.has_perms(('cableur',)): @@ -1338,9 +1338,9 @@ def mx(request): @csrf_exempt @login_required @permission_required('serveur') -def text(request): - text = Text.objects.all().select_related('zone') - seria = TextSerializer(text, many=True) +def txt(request): + txt = Txt.objects.all().select_related('zone') + seria = TxtSerializer(txt, many=True) return JSONResponse(seria.data) @csrf_exempt