mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-23 03:43:12 +00:00
Deplace les models forms dans forms
This commit is contained in:
parent
78a466808a
commit
aba2d73f39
3 changed files with 38 additions and 34 deletions
36
machines/forms.py
Normal file
36
machines/forms.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
from django.forms import ModelForm, Form, ValidationError
|
||||||
|
from .models import Machine, Interface
|
||||||
|
|
||||||
|
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'
|
||||||
|
self.fields['type'].label = 'Type de machine'
|
||||||
|
self.fields['type'].empty_label = "Séléctionner un type de machine"
|
||||||
|
|
||||||
|
class NewMachineForm(EditMachineForm):
|
||||||
|
class Meta(EditMachineForm.Meta):
|
||||||
|
fields = ['type','name']
|
||||||
|
|
||||||
|
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'
|
||||||
|
|
||||||
|
class AddInterfaceForm(EditInterfaceForm):
|
||||||
|
class Meta(EditInterfaceForm.Meta):
|
||||||
|
fields = ['ipv4','mac_address','dns','details']
|
||||||
|
|
||||||
|
class NewInterfaceForm(EditInterfaceForm):
|
||||||
|
class Meta(EditInterfaceForm.Meta):
|
||||||
|
fields = ['mac_address','dns','details']
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.forms import ModelForm, Form, ValidationError
|
from django.forms import ValidationError
|
||||||
from macaddress.fields import MACAddressField
|
from macaddress.fields import MACAddressField
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -64,35 +64,3 @@ class IpList(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.ipv4
|
return self.ipv4
|
||||||
|
|
||||||
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'
|
|
||||||
self.fields['type'].label = 'Type de machine'
|
|
||||||
self.fields['type'].empty_label = "Séléctionner un type de machine"
|
|
||||||
|
|
||||||
class NewMachineForm(EditMachineForm):
|
|
||||||
class Meta(EditMachineForm.Meta):
|
|
||||||
fields = ['type','name']
|
|
||||||
|
|
||||||
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'
|
|
||||||
|
|
||||||
class AddInterfaceForm(EditInterfaceForm):
|
|
||||||
class Meta(EditInterfaceForm.Meta):
|
|
||||||
fields = ['ipv4','mac_address','dns','details']
|
|
||||||
|
|
||||||
class NewInterfaceForm(EditInterfaceForm):
|
|
||||||
class Meta(EditInterfaceForm.Meta):
|
|
||||||
fields = ['mac_address','dns','details']
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ from django.core.context_processors import csrf
|
||||||
from django.template import Context, RequestContext, loader
|
from django.template import Context, RequestContext, loader
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
|
||||||
from .models import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm, NewInterfaceForm
|
from .forms import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm, NewInterfaceForm
|
||||||
from .models import Machine, Interface, IpList
|
from .models import Machine, Interface, IpList
|
||||||
from users.models import User
|
from users.models import User
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue