network_inventory/computers/forms.py

34 lines
881 B
Python
Raw Normal View History

import floppyforms.__future__ as forms
2020-02-29 15:18:29 +01:00
from core import utils
2020-02-29 15:18:29 +01:00
from computers.models import Computer
class ComputerCreateForm(forms.ModelForm):
class Meta:
model = Computer
fields = (
'name',
'customer',
)
2020-02-29 15:18:29 +01:00
def __init__(self, user=None, *args, **kwargs):
2020-05-01 16:11:47 +02:00
"""
If the user is not a superuser it's always assigned to a customer which
we can use to assign to the field.
"""
super(ComputerCreateForm, self).__init__(*args, **kwargs)
if not user.is_superuser:
2020-02-29 15:18:29 +01:00
self.fields['customer'].queryset = utils.get_customers(user)
2020-02-27 22:01:07 +01:00
class ComputerUpdateForm(forms.ModelForm):
"""
Basic form class to use crispies HTML5 forms.
"""
2020-02-27 22:01:07 +01:00
class Meta:
model = Computer
fields = '__all__'
exclude = ('net', 'cpu', 'ram', 'gpu', 'disks', 'software')