mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Refactor aussi la fonction du views pour la route
This commit is contained in:
parent
e172923578
commit
92e6ae45ad
1 changed files with 4 additions and 9 deletions
|
@ -533,19 +533,14 @@ def create_ports(request, switchid):
|
||||||
except Switch.DoesNotExist:
|
except Switch.DoesNotExist:
|
||||||
messages.error(request, _("Nonexistent switch"))
|
messages.error(request, _("Nonexistent switch"))
|
||||||
return redirect(reverse('topologie:index'))
|
return redirect(reverse('topologie:index'))
|
||||||
|
|
||||||
s_begin = s_end = 0
|
first_port = getattr(switch.ports.order_by('port').first(), 'port', 1)
|
||||||
nb_ports = switch.ports.count()
|
s_begin = first_port
|
||||||
if nb_ports > 0:
|
s_end = switch.number + first_port - 1
|
||||||
ports = switch.ports.order_by('port').values('port')
|
|
||||||
s_begin = ports.first().get('port')
|
|
||||||
s_end = ports.last().get('port')
|
|
||||||
|
|
||||||
port_form = CreatePortsForm(
|
port_form = CreatePortsForm(
|
||||||
request.POST or None,
|
request.POST or None,
|
||||||
initial={'begin': s_begin, 'end': s_end}
|
initial={'begin': s_begin, 'end': s_end}
|
||||||
)
|
)
|
||||||
|
|
||||||
if port_form.is_valid():
|
if port_form.is_valid():
|
||||||
begin = port_form.cleaned_data['begin']
|
begin = port_form.cleaned_data['begin']
|
||||||
end = port_form.cleaned_data['end']
|
end = port_form.cleaned_data['end']
|
||||||
|
|
Loading…
Reference in a new issue