From e99d0956401ea704315a4100fe63ee972e308396 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Wed, 18 Oct 2017 02:27:42 +0200 Subject: [PATCH] Fix bugs sur infra et nb_machines --- machines/views.py | 3 +-- topologie/models.py | 6 +++++- topologie/views.py | 8 +++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/machines/views.py b/machines/views.py index 48adf44b..41cea7b9 100644 --- a/machines/views.py +++ b/machines/views.py @@ -223,8 +223,7 @@ def new_machine(request, userid): return redirect("/users/profil/" + str(request.user.id)) machine = NewMachineForm(request.POST or None) interface = AddInterfaceForm(request.POST or None, infra=request.user.has_perms(('infra',))) - nb_machine = Interface.objects.filter(machine__user=userid).count() - domain = DomainForm(request.POST or None, user=user, nb_machine=nb_machine) + domain = DomainForm(request.POST or None, user=user) if machine.is_valid() and interface.is_valid(): new_machine = machine.save(commit=False) new_machine.user = user diff --git a/topologie/models.py b/topologie/models.py index 66c8fe94..adcc7a57 100644 --- a/topologie/models.py +++ b/topologie/models.py @@ -145,7 +145,11 @@ class Port(models.Model): ('COMMON', 'COMMON'), ) - switch = models.ForeignKey('Switch', related_name="ports") + switch = models.ForeignKey( + 'Switch', + related_name="ports", + on_delete=models.CASCADE + ) port = models.PositiveIntegerField() room = models.ForeignKey( 'Room', diff --git a/topologie/views.py b/topologie/views.py index f1e8740c..686685e9 100644 --- a/topologie/views.py +++ b/topologie/views.py @@ -50,7 +50,7 @@ from topologie.forms import EditPortForm, NewSwitchForm, EditSwitchForm from topologie.forms import AddPortForm, EditRoomForm, StackForm from users.views import form -from machines.forms import AliasForm, NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm +from machines.forms import DomainForm, NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm from machines.views import generate_ipv4_mbf_param from preferences.models import AssoOption, GeneralOption @@ -344,9 +344,8 @@ def new_switch(request): request.POST or None, infra=request.user.has_perms(('infra',)) ) - domain = AliasForm( + domain = DomainForm( request.POST or None, - infra=request.user.has_perms(('infra',)) ) if switch.is_valid() and machine.is_valid() and interface.is_valid(): options, _created = AssoOption.objects.get_or_create() @@ -410,9 +409,8 @@ def edit_switch(request, switch_id): request.POST or None, instance=switch.switch_interface ) - domain_form = AliasForm( + domain_form = DomainForm( request.POST or None, - infra=request.user.has_perms(('infra',)), instance=switch.switch_interface.domain ) if switch_form.is_valid() and machine_form.is_valid()\