From 75aacc3f1dd8e5dfb3eb6e68aba921d47c2feb0d Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sat, 27 May 2017 03:51:21 +0200 Subject: [PATCH] La modification d'un port n'est plus lente et ne rame plus du cul --- topologie/forms.py | 10 ++++++---- topologie/views.py | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/topologie/forms.py b/topologie/forms.py index 1ac21907..6d62ad7f 100644 --- a/topologie/forms.py +++ b/topologie/forms.py @@ -22,6 +22,7 @@ from .models import Port, Switch, Room from django.forms import ModelForm, Form +from machines.models import Interface class PortForm(ModelForm): class Meta: @@ -30,11 +31,12 @@ class PortForm(ModelForm): class EditPortForm(ModelForm): class Meta(PortForm.Meta): - fields = ['room', 'related', 'radius', 'details'] + fields = ['room', 'related', 'machine_interface', 'radius', 'details'] -# def __init__(self, *args, **kwargs): -# super(EditPortForm, self).__init__(*args, **kwargs) -# self.fields['related'].queryset = Port.objects.all().order_by('switch', 'port') + def __init__(self, *args, **kwargs): + super(EditPortForm, self).__init__(*args, **kwargs) + self.fields['machine_interface'].queryset = Interface.objects.all().select_related('domain__extension') + self.fields['related'].queryset = Port.objects.all().select_related('switch__switch_interface__domain__extension').order_by('switch', 'port') class AddPortForm(ModelForm): class Meta(PortForm.Meta): diff --git a/topologie/views.py b/topologie/views.py index b6c8611e..5ee5f003 100644 --- a/topologie/views.py +++ b/topologie/views.py @@ -42,7 +42,7 @@ from re2o.settings import ASSO_PSEUDO, PAGINATION_NUMBER @login_required @permission_required('cableur') def index(request): - switch_list = Switch.objects.order_by('location') + switch_list = Switch.objects.order_by('location').select_related('switch_interface__domain__extension').select_related('switch_interface__ipv4').select_related('switch_interface__domain') return render(request, 'topologie/index.html', {'switch_list': switch_list}) @login_required @@ -90,7 +90,7 @@ def index_port(request, switch_id): except Switch.DoesNotExist: messages.error(request, u"Switch inexistant") return redirect("/topologie/") - port_list = Port.objects.filter(switch = switch).order_by('port') + port_list = Port.objects.filter(switch = switch).select_related('room').select_related('machine_interface__domain__extension').select_related('related').select_related('switch').order_by('port') return render(request, 'topologie/index_p.html', {'port_list':port_list, 'id_switch':switch_id, 'nom_switch':switch}) @login_required @@ -126,7 +126,7 @@ def new_port(request, switch_id): @permission_required('infra') def edit_port(request, port_id): try: - port_object = Port.objects.select_related('switch__switch_interface__domain__extension').select_related('machine_interface').select_related('room').select_related('related').get(pk=port_id) + port_object = Port.objects.select_related('switch__switch_interface__domain__extension').select_related('machine_interface__domain__extension').select_related('machine_interface__switch').select_related('room').select_related('related').get(pk=port_id) except Port.DoesNotExist: messages.error(request, u"Port inexistant") return redirect("/topologie/")