From cfecb157931193ae6fc9ae55191d1d80cb8e1c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Tue, 3 Oct 2017 02:09:41 +0000 Subject: [PATCH] =?UTF-8?q?Optimisation,=20essaye=20d'acc=C3=A9l=C3=A9rer?= =?UTF-8?q?=20la=20cr=C3=A9ation=20du=20form=20d'interface=20Long=20pour?= =?UTF-8?q?=20beaucoup=20d'ip=20(5-15=20sec=20pour=20un=20/16)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- machines/templates/machines/machine.html | 3 +-- machines/views.py | 9 ++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/machines/templates/machines/machine.html b/machines/templates/machines/machine.html index 2032a078..1e753f6f 100644 --- a/machines/templates/machines/machine.html +++ b/machines/templates/machines/machine.html @@ -43,8 +43,7 @@ with this program; if not, write to the Free Software Foundation, Inc., var type_to_ipv4 = { type: [{% for type, iplist in type_to_ipv4.items %}"{{ type }}",{% endfor %}], iplist: [{% for type, iplist in type_to_ipv4.items %} - [{% for ip in iplist %} {id:"{{ ip.id }}", ip:"{{ ip.ipv4 }}"}, - {% endfor %}], {% endfor %} + [ {{ iplist | safe }} ], {% endfor %} ] } $(document).ready(function() { diff --git a/machines/views.py b/machines/views.py index d1feb8df..951671c4 100644 --- a/machines/views.py +++ b/machines/views.py @@ -119,7 +119,8 @@ def new_machine(request, userid): return redirect("/users/profil/" + str(user.id)) type_to_ipv4 = {} for t in interface.fields['type'].queryset : - type_to_ipv4[str(t.id)] = IpList.objects.filter(interface__isnull=True).filter(ip_type=t.ip_type) + iplist = IpList.objects.filter(interface__isnull=True).filter(ip_type=t.ip_type) + type_to_ipv4[str(t.id)] = ','.join(['{id:"%s", ip:"%s"}' % (b.id, b.ipv4) for b in iplist]) return form({'machineform': machine, 'interfaceform': interface, 'domainform': domain, 'type_to_ipv4': type_to_ipv4}, 'machines/machine.html', request) @login_required @@ -159,7 +160,8 @@ def edit_interface(request, interfaceid): return redirect("/users/profil/" + str(interface.machine.user.id)) type_to_ipv4 = {} for t in interface_form.fields['type'].queryset : - type_to_ipv4[str(t.id)] = IpList.objects.filter(interface__isnull=True).filter(ip_type=t.ip_type) + iplist = IpList.objects.filter(interface__isnull=True).filter(ip_type=t.ip_type) + type_to_ipv4[str(t.id)] = ','.join(['{id:"%s", ip:"%s"}' % (b.id, b.ipv4) for b in iplist]) return form({'machineform': machine_form, 'interfaceform': interface_form, 'domainform': domain_form, 'type_to_ipv4': type_to_ipv4}, 'machines/machine.html', request) @login_required @@ -218,7 +220,8 @@ def new_interface(request, machineid): return redirect("/users/profil/" + str(machine.user.id)) type_to_ipv4 = {} for t in interface_form.fields['type'].queryset : - type_to_ipv4[str(t.id)] = IpList.objects.filter(interface__isnull=True).filter(ip_type=t.ip_type) + iplist = IpList.objects.filter(interface__isnull=True).filter(ip_type=t.ip_type) + type_to_ipv4[str(t.id)] = ','.join(['{id:"%s", ip:"%s"}' % (b.id, b.ipv4) for b in iplist]) return form({'interfaceform': interface_form, 'domainform': domain_form, 'type_to_ipv4': type_to_ipv4}, 'machines/machine.html', request) @login_required