2016-07-06 22:49:16 +02:00
from django . forms import ModelForm , Form , ValidationError
2016-07-07 13:19:03 +02:00
from django import forms
2016-11-01 02:14:06 +01:00
from . models import Alias , Machine , Interface , IpList , MachineType , Extension , IpType
2016-07-06 22:49:16 +02: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 19:14:48 +02:00
fields = [ ' name ' ]
2016-07-06 22:49:16 +02:00
2016-07-09 19:51:37 +02:00
class BaseEditMachineForm ( EditMachineForm ) :
class Meta ( EditMachineForm . Meta ) :
2016-07-18 19:14:48 +02:00
fields = [ ' name ' , ' active ' ]
2016-07-09 19:51:37 +02:00
2016-07-06 22:49:16 +02: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 19:14:48 +02:00
self . fields [ ' type ' ] . label = ' Type de machine '
self . fields [ ' type ' ] . empty_label = " Séléctionner un type de machine "
2016-07-06 22:49:16 +02:00
class AddInterfaceForm ( EditInterfaceForm ) :
class Meta ( EditInterfaceForm . Meta ) :
2016-07-18 19:14:48 +02:00
fields = [ ' ipv4 ' , ' mac_address ' , ' dns ' , ' type ' , ' details ' ]
2016-07-06 22:49:16 +02:00
2016-07-07 19:15:33 +02:00
def __init__ ( self , * args , * * kwargs ) :
2016-10-13 02:11:23 +02:00
infra = kwargs . pop ( ' infra ' )
2016-07-07 19:15:33 +02:00
super ( AddInterfaceForm , self ) . __init__ ( * args , * * kwargs )
self . fields [ ' ipv4 ' ] . empty_label = " Assignation automatique de l ' ipv4 "
2016-10-13 02:11:23 +02:00
if not infra :
2016-10-23 00:55:58 +02:00
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 ) )
2016-07-07 19:15:33 +02:00
2016-07-06 22:49:16 +02:00
class NewInterfaceForm ( EditInterfaceForm ) :
class Meta ( EditInterfaceForm . Meta ) :
2016-07-18 19:14:48 +02:00
fields = [ ' mac_address ' , ' dns ' , ' type ' , ' details ' ]
2016-07-06 22:49:16 +02:00
2016-07-09 19:51:37 +02:00
class BaseEditInterfaceForm ( EditInterfaceForm ) :
class Meta ( EditInterfaceForm . Meta ) :
2016-07-18 19:14:48 +02:00
fields = [ ' ipv4 ' , ' mac_address ' , ' dns ' , ' type ' , ' details ' ]
2016-07-09 19:51:37 +02:00
2016-10-24 19:52:29 +02:00
def __init__ ( self , * args , * * kwargs ) :
2016-10-13 02:11:23 +02:00
infra = kwargs . pop ( ' infra ' )
2016-07-09 19:51:37 +02:00
super ( BaseEditInterfaceForm , self ) . __init__ ( * args , * * kwargs )
self . fields [ ' ipv4 ' ] . empty_label = " Assignation automatique de l ' ipv4 "
2016-10-13 02:11:23 +02:00
if not infra :
2016-10-24 19:52:29 +02:00
self . fields [ ' type ' ] . queryset = MachineType . objects . filter ( ip_type = IpType . objects . filter ( need_infra = False ) )
2016-10-23 00:55:58 +02:00
self . fields [ ' ipv4 ' ] . queryset = IpList . objects . filter ( ip_type = IpType . objects . filter ( need_infra = False ) )
2016-07-09 19:51:37 +02:00
2016-11-01 02:14:06 +01:00
class NewAliasForm ( ModelForm ) :
class Meta :
model = Alias
fields = [ ' alias ' ]
class EditAliasFullForm ( NewAliasForm ) :
class Meta ( NewAliasForm . Meta ) :
fields = ' __all__ '
2016-07-07 13:19:03 +02:00
class MachineTypeForm ( ModelForm ) :
class Meta :
model = MachineType
2016-10-23 00:55:58 +02:00
fields = [ ' type ' , ' ip_type ' ]
2016-07-07 13:19:03 +02:00
def __init__ ( self , * args , * * kwargs ) :
super ( MachineTypeForm , self ) . __init__ ( * args , * * kwargs )
self . fields [ ' type ' ] . label = ' Type de machine à ajouter '
2016-10-23 00:55:58 +02:00
self . fields [ ' ip_type ' ] . label = " Type d ' ip relié "
2016-07-07 13:19:03 +02:00
class DelMachineTypeForm ( ModelForm ) :
machinetypes = forms . ModelMultipleChoiceField ( queryset = MachineType . objects . all ( ) , label = " Types de machines actuelles " , widget = forms . CheckboxSelectMultiple )
class Meta :
2016-10-23 00:55:58 +02:00
exclude = [ ' type ' , ' ip_type ' ]
2016-07-07 13:19:03 +02:00
model = MachineType
2016-07-08 17:54:06 +02:00
2016-10-23 00:55:58 +02:00
class IpTypeForm ( ModelForm ) :
class Meta :
model = IpType
2016-11-15 15:25:27 +01:00
fields = [ ' type ' , ' extension ' , ' need_infra ' , ' domaine_ip ' , ' domaine_range ' ]
2016-10-23 00:55:58 +02:00
def __init__ ( self , * args , * * kwargs ) :
super ( IpTypeForm , self ) . __init__ ( * args , * * kwargs )
self . fields [ ' type ' ] . label = ' Type ip à ajouter '
class DelIpTypeForm ( ModelForm ) :
iptypes = forms . ModelMultipleChoiceField ( queryset = IpType . objects . all ( ) , label = " Types d ' ip actuelles " , widget = forms . CheckboxSelectMultiple )
class Meta :
2016-11-15 15:25:27 +01:00
exclude = [ ' type ' , ' extension ' , ' need_infra ' , ' domaine_ip ' , ' domaine_range ' ]
2016-10-23 00:55:58 +02:00
model = IpType
2016-07-08 17:54:06 +02:00
class ExtensionForm ( ModelForm ) :
class Meta :
model = Extension
fields = [ ' name ' ]
def __init__ ( self , * args , * * kwargs ) :
super ( ExtensionForm , self ) . __init__ ( * args , * * kwargs )
2016-10-26 14:05:40 +02:00
self . fields [ ' name ' ] . label = ' Extension à ajouter '
2016-07-08 17:54:06 +02:00
class DelExtensionForm ( ModelForm ) :
extensions = forms . ModelMultipleChoiceField ( queryset = Extension . objects . all ( ) , label = " Extensions actuelles " , widget = forms . CheckboxSelectMultiple )
class Meta :
exclude = [ ' name ' ]
model = Extension