Commit f2a4f837 authored by Maël Kervella's avatar Maël Kervella Committed by Pierre Cadart

Optimisation, essaye d'accélérer la création du form d'interface

Long pour beaucoup d'ip (5-15 sec pour un /16)
parent 4491f56d
......@@ -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() {
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment