From 740746febdbb7ed68afa06ae57655a7e498660dc Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Fri, 24 Jan 2020 23:49:43 +0100 Subject: [PATCH] Fix bug nomage machine -> referencement utilisateur cible --- machines/forms.py | 5 ----- machines/views.py | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/machines/forms.py b/machines/forms.py index 7217c4d7..629538e0 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -160,11 +160,6 @@ class DomainForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): fields = ["name", "ttl"] def __init__(self, *args, **kwargs): - if "user" in kwargs: - user = kwargs["user"] - initial = kwargs.get("initial", {}) - initial["name"] = user.get_next_domain_name() - kwargs["initial"] = initial prefix = kwargs.pop("prefix", self.Meta.model.__name__) super(DomainForm, self).__init__(*args, prefix=prefix, **kwargs) diff --git a/machines/views.py b/machines/views.py index 8f70d187..403389d2 100644 --- a/machines/views.py +++ b/machines/views.py @@ -228,7 +228,7 @@ def new_machine(request, user, **_kwargs): machine = NewMachineForm(request.POST or None, user=request.user) interface = AddInterfaceForm(request.POST or None, user=request.user) - domain = DomainForm(request.POST or None, user=user) + domain = DomainForm(request.POST or None, user=user, initial={'name': user.get_next_domain_name()}) if machine.is_valid() and interface.is_valid(): new_machine_obj = machine.save(commit=False) new_machine_obj.user = user @@ -325,7 +325,7 @@ def new_interface(request, machine, **_kwargs): """ Ajoute une interface et son domain associé à une machine existante""" interface_form = AddInterfaceForm(request.POST or None, user=request.user) - domain_form = DomainForm(request.POST or None, user=request.user) + domain_form = DomainForm(request.POST or None, user=request.user, initial={'name': machine.user.get_next_domain_name()}) if interface_form.is_valid(): new_interface_obj = interface_form.save(commit=False) domain_form.instance.interface_parent = new_interface_obj