From 92e6ae45ad22413f370008f5fb5a83b81a77e9ee Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sun, 30 Dec 2018 00:34:17 +0100 Subject: [PATCH] Refactor aussi la fonction du views pour la route --- topologie/views.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/topologie/views.py b/topologie/views.py index a4db2dc6..d852177d 100644 --- a/topologie/views.py +++ b/topologie/views.py @@ -533,19 +533,14 @@ def create_ports(request, switchid): except Switch.DoesNotExist: messages.error(request, _("Nonexistent switch")) return redirect(reverse('topologie:index')) - - s_begin = s_end = 0 - nb_ports = switch.ports.count() - if nb_ports > 0: - ports = switch.ports.order_by('port').values('port') - s_begin = ports.first().get('port') - s_end = ports.last().get('port') - + + first_port = getattr(switch.ports.order_by('port').first(), 'port', 1) + s_begin = first_port + s_end = switch.number + first_port - 1 port_form = CreatePortsForm( request.POST or None, initial={'begin': s_begin, 'end': s_end} ) - if port_form.is_valid(): begin = port_form.cleaned_data['begin'] end = port_form.cleaned_data['end']