2020-02-27 22:00:17 +01:00
|
|
|
import floppyforms.__future__ as forms
|
|
|
|
|
2020-02-29 15:18:29 +01:00
|
|
|
from core import utils
|
2020-02-29 12:25:14 +01:00
|
|
|
|
2020-02-29 15:18:29 +01:00
|
|
|
from computers.models import Computer
|
2020-02-27 22:00:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
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-02-29 11:44:16 +01:00
|
|
|
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-29 11:44:16 +01:00
|
|
|
|
2020-02-27 22:00:17 +01:00
|
|
|
|
2020-02-27 22:01:07 +01:00
|
|
|
class ComputerUpdateForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = Computer
|
|
|
|
fields = (
|
|
|
|
'name',
|
|
|
|
'description',
|
|
|
|
'serialnumber',
|
|
|
|
'category',
|
|
|
|
'owner',
|
|
|
|
'customer',
|
|
|
|
'manufacturer',
|
|
|
|
'model',
|
|
|
|
'location',
|
|
|
|
'user',
|
|
|
|
'installation_date',
|
2020-02-29 12:25:14 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, user=None, *args, **kwargs):
|
|
|
|
super(ComputerUpdateForm, 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-29 19:00:47 +01:00
|
|
|
self.fields['user'].queryset = utils.get_objects("User", user)
|