From 32217118e17b15360789baa7ff5f60a9e4a805ef Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Wed, 30 Nov 2016 04:48:47 +0100 Subject: [PATCH] Bricoles, affiche les ip dispo --- machines/forms.py | 9 +++++++-- machines/views.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/machines/forms.py b/machines/forms.py index 6a8d8d27..05f3a1f6 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -1,6 +1,7 @@ from django.forms import ModelForm, Form, ValidationError from django import forms from .models import Alias, Machine, Interface, IpList, MachineType, Extension, Mx, Ns, IpType +from django.db.models import Q class EditMachineForm(ModelForm): class Meta: @@ -41,7 +42,9 @@ class AddInterfaceForm(EditInterfaceForm): self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4" if not infra: self.fields['type'].queryset = MachineType.objects.filter(ip_type=IpType.objects.filter(need_infra=False)) - self.fields['ipv4'].queryset = IpList.objects.filter(ip_type=IpType.objects.filter(need_infra=False)) + self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True).filter(ip_type=IpType.objects.filter(need_infra=False)) + else: + self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True) class NewInterfaceForm(EditInterfaceForm): class Meta(EditInterfaceForm.Meta): @@ -57,7 +60,9 @@ class BaseEditInterfaceForm(EditInterfaceForm): self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4" if not infra: self.fields['type'].queryset = MachineType.objects.filter(ip_type=IpType.objects.filter(need_infra=False)) - self.fields['ipv4'].queryset = IpList.objects.filter(ip_type=IpType.objects.filter(need_infra=False)) + self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True).filter(ip_type=IpType.objects.filter(need_infra=False)) + else: + self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True) class AliasForm(ModelForm): class Meta: diff --git a/machines/views.py b/machines/views.py index fd8e5a93..522b6730 100644 --- a/machines/views.py +++ b/machines/views.py @@ -197,7 +197,7 @@ def new_interface(request, machineid): reversion.set_user(request.user) reversion.set_comment("Création") messages.success(request, "L'interface a été ajoutée") - return redirect("/users/profil/" + str(request.user.id)) + return redirect("/users/profil/" + str(machine.user.id)) return form({'interfaceform': interface_form}, 'machines/machine.html', request) @login_required