8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-25 16:33:47 +00:00
re2o/machines/forms.py

93 lines
3.5 KiB
Python
Raw Normal View History

2016-07-06 20:49:16 +00:00
from django.forms import ModelForm, Form, ValidationError
2016-07-07 11:19:03 +00:00
from django import forms
from .models import Machine, Interface, IpList, MachineType, Extension
2016-07-06 20:49:16 +00:00
class EditMachineForm(ModelForm):
class Meta:
model = Machine
fields = '__all__'
def __init__(self, *args, **kwargs):
super(EditMachineForm, self).__init__(*args, **kwargs)
self.fields['name'].label = 'Nom de la machine'
class NewMachineForm(EditMachineForm):
class Meta(EditMachineForm.Meta):
2016-07-18 17:14:48 +00:00
fields = ['name']
2016-07-06 20:49:16 +00:00
class BaseEditMachineForm(EditMachineForm):
class Meta(EditMachineForm.Meta):
2016-07-18 17:14:48 +00:00
fields = ['name','active']
2016-07-06 20:49:16 +00:00
class EditInterfaceForm(ModelForm):
class Meta:
model = Interface
fields = '__all__'
def __init__(self, *args, **kwargs):
super(EditInterfaceForm, self).__init__(*args, **kwargs)
self.fields['dns'].label = 'Nom dns de la machine'
self.fields['mac_address'].label = 'Adresse mac'
2016-07-18 17:14:48 +00:00
self.fields['type'].label = 'Type de machine'
self.fields['type'].empty_label = "Séléctionner un type de machine"
2016-07-06 20:49:16 +00:00
class AddInterfaceForm(EditInterfaceForm):
class Meta(EditInterfaceForm.Meta):
2016-07-18 17:14:48 +00:00
fields = ['ipv4','mac_address','dns','type','details']
2016-07-06 20:49:16 +00:00
def __init__(self, *args, **kwargs):
infra = kwargs.pop('infra')
super(AddInterfaceForm, self).__init__(*args, **kwargs)
self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4"
if not infra:
self.fields['type'].queryset = MachineType.objects.filter(need_infra=False)
self.fields['ipv4'].queryset = IpList.objects.filter(ip_type=MachineType.objects.filter(need_infra=False))
2016-07-06 20:49:16 +00:00
class NewInterfaceForm(EditInterfaceForm):
class Meta(EditInterfaceForm.Meta):
2016-07-18 17:14:48 +00:00
fields = ['mac_address','dns','type','details']
2016-07-06 20:49:16 +00:00
class BaseEditInterfaceForm(EditInterfaceForm):
class Meta(EditInterfaceForm.Meta):
2016-07-18 17:14:48 +00:00
fields = ['ipv4','mac_address','dns','type','details']
def __init__(self, infra=False, *args, **kwargs):
infra = kwargs.pop('infra')
super(BaseEditInterfaceForm, self).__init__(*args, **kwargs)
self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4"
if not infra:
self.fields['type'].queryset = MachineType.objects.filter(need_infra=False)
self.fields['ipv4'].queryset = IpList.objects.filter(ip_type=MachineType.objects.filter(need_infra=False))
2016-07-07 11:19:03 +00:00
class MachineTypeForm(ModelForm):
class Meta:
model = MachineType
fields = ['type','extension','need_infra']
2016-07-07 11:19:03 +00:00
def __init__(self, *args, **kwargs):
super(MachineTypeForm, self).__init__(*args, **kwargs)
self.fields['type'].label = 'Type de machine à ajouter'
class DelMachineTypeForm(ModelForm):
machinetypes = forms.ModelMultipleChoiceField(queryset=MachineType.objects.all(), label="Types de machines actuelles", widget=forms.CheckboxSelectMultiple)
class Meta:
2016-07-08 15:54:06 +00:00
exclude = ['type','extension']
2016-07-07 11:19:03 +00:00
model = MachineType
2016-07-08 15:54:06 +00:00
class ExtensionForm(ModelForm):
class Meta:
model = Extension
fields = ['name']
def __init__(self, *args, **kwargs):
super(ExtensionForm, self).__init__(*args, **kwargs)
self.fields['name'].label = 'Exstension à ajouter'
class DelExtensionForm(ModelForm):
extensions = forms.ModelMultipleChoiceField(queryset=Extension.objects.all(), label="Extensions actuelles", widget=forms.CheckboxSelectMultiple)
class Meta:
exclude = ['name']
model = Extension