Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

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., ...@@ -43,8 +43,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
var type_to_ipv4 = { var type_to_ipv4 = {
type: [{% for type, iplist in type_to_ipv4.items %}"{{ type }}",{% endfor %}], type: [{% for type, iplist in type_to_ipv4.items %}"{{ type }}",{% endfor %}],
iplist: [{% for type, iplist in type_to_ipv4.items %} iplist: [{% for type, iplist in type_to_ipv4.items %}
[{% for ip in iplist %} {id:"{{ ip.id }}", ip:"{{ ip.ipv4 }}"}, [ {{ iplist | safe }} ], {% endfor %}
{% endfor %}], {% endfor %}
] ]
} }
$(document).ready(function() { $(document).ready(function() {
......
...@@ -119,7 +119,8 @@ def new_machine(request, userid): ...@@ -119,7 +119,8 @@ def new_machine(request, userid):
return redirect("/users/profil/" + str(user.id)) return redirect("/users/profil/" + str(user.id))
type_to_ipv4 = {} type_to_ipv4 = {}
for t in interface.fields['type'].queryset : 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) return form({'machineform': machine, 'interfaceform': interface, 'domainform': domain, 'type_to_ipv4': type_to_ipv4}, 'machines/machine.html', request)
@login_required @login_required
...@@ -159,7 +160,8 @@ def edit_interface(request, interfaceid): ...@@ -159,7 +160,8 @@ def edit_interface(request, interfaceid):
return redirect("/users/profil/" + str(interface.machine.user.id)) return redirect("/users/profil/" + str(interface.machine.user.id))
type_to_ipv4 = {} type_to_ipv4 = {}
for t in interface_form.fields['type'].queryset : 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) return form({'machineform': machine_form, 'interfaceform': interface_form, 'domainform': domain_form, 'type_to_ipv4': type_to_ipv4}, 'machines/machine.html', request)
@login_required @login_required
...@@ -218,7 +220,8 @@ def new_interface(request, machineid): ...@@ -218,7 +220,8 @@ def new_interface(request, machineid):
return redirect("/users/profil/" + str(machine.user.id)) return redirect("/users/profil/" + str(machine.user.id))
type_to_ipv4 = {} type_to_ipv4 = {}
for t in interface_form.fields['type'].queryset : 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) return form({'interfaceform': interface_form, 'domainform': domain_form, 'type_to_ipv4': type_to_ipv4}, 'machines/machine.html', request)
@login_required @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