From 7cf2e525410fcdee26ab49c31ab5234768ef7288 Mon Sep 17 00:00:00 2001 From: Dalahro Date: Mon, 9 Jan 2017 16:01:10 +0100 Subject: [PATCH] Autocompletion du dns basique --- machines/forms.py | 5 +++++ machines/views.py | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/machines/forms.py b/machines/forms.py index 822c5faa..a0172763 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -70,6 +70,11 @@ class AliasForm(ModelForm): def __init__(self, *args, **kwargs): infra = kwargs.pop('infra') + name_user = kwargs.pop('name_user') + nb_machine = kwargs.pop('nb_machine') + initial = kwargs.get('initial', {}) + initial['name'] = name_user.lower()+str(nb_machine) + kwargs['initial'] = initial super(AliasForm, self).__init__(*args, **kwargs) if not infra: self.fields['extension'].queryset = Extension.objects.filter(need_infra=False) diff --git a/machines/views.py b/machines/views.py index 61e18628..bd09cd84 100644 --- a/machines/views.py +++ b/machines/views.py @@ -99,7 +99,8 @@ 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',))) - domain = AliasForm(request.POST or None, infra=request.user.has_perms(('infra',))) + nb_machine = Interface.objects.filter(machine__user=userid).count() + domain = AliasForm(request.POST or None, infra=request.user.has_perms(('infra',)), name_user=request.user.surname, nb_machine=nb_machine) if machine.is_valid() and interface.is_valid(): new_machine = machine.save(commit=False) new_machine.user = user