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-06-15 21:38:21 +02:00
|
|
|
from computers.models import ComputerCpuRelation
|
2020-06-15 21:39:58 +02:00
|
|
|
from computers.models import ComputerDiskRelation
|
2020-06-15 21:39:31 +02:00
|
|
|
from computers.models import ComputerGpuRelation
|
2020-06-09 21:59:20 +02:00
|
|
|
from computers.models import ComputerRamRelation
|
2020-06-28 19:04:55 +02:00
|
|
|
from computers.models import ComputerSoftwareRelation
|
2020-06-29 22:43:39 +02:00
|
|
|
from computers.models import Raid
|
2020-02-27 22:00:17 +01:00
|
|
|
|
2021-12-24 12:55:34 +01:00
|
|
|
from customers.models import Customer
|
2021-12-30 14:57:47 +01:00
|
|
|
from customers.models import Location
|
|
|
|
|
|
|
|
from users.models import User
|
2021-12-24 12:55:34 +01:00
|
|
|
|
2020-02-27 22:00:17 +01:00
|
|
|
|
|
|
|
class ComputerCreateForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = Computer
|
|
|
|
fields = (
|
2022-03-27 14:50:44 +02:00
|
|
|
"name",
|
|
|
|
"customer",
|
2020-02-27 22:00:17 +01:00
|
|
|
)
|
|
|
|
|
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.
|
|
|
|
"""
|
2020-02-29 11:44:16 +01:00
|
|
|
super(ComputerCreateForm, self).__init__(*args, **kwargs)
|
2022-03-27 14:50:44 +02:00
|
|
|
customers = utils.objects_for_allowed_customers(Customer, user=user)
|
|
|
|
self.fields["customer"].queryset = customers
|
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):
|
2020-05-26 23:25:21 +02:00
|
|
|
"""
|
|
|
|
Basic form class to use crispies HTML5 forms.
|
|
|
|
"""
|
2021-12-30 14:57:47 +01:00
|
|
|
|
|
|
|
def __init__(self, request, *args, **kwargs):
|
|
|
|
super(ComputerUpdateForm, self).__init__(*args, **kwargs)
|
2022-03-27 14:50:44 +02:00
|
|
|
customers = utils.objects_for_allowed_customers(
|
|
|
|
Customer, user=request.user
|
|
|
|
)
|
|
|
|
locations = utils.objects_for_allowed_customers(
|
|
|
|
Location, user=request.user
|
|
|
|
)
|
|
|
|
hosts = utils.objects_for_allowed_customers(
|
|
|
|
Computer, user=request.user
|
|
|
|
)
|
|
|
|
users = utils.objects_for_allowed_customers(User, user=request.user)
|
|
|
|
self.fields["customer"].queryset = customers
|
|
|
|
self.fields["location"].queryset = locations
|
|
|
|
self.fields["host"].queryset = hosts
|
|
|
|
self.fields["user"].queryset = users
|
2021-12-30 14:57:47 +01:00
|
|
|
|
2020-02-27 22:01:07 +01:00
|
|
|
class Meta:
|
|
|
|
model = Computer
|
2022-03-27 14:50:44 +02:00
|
|
|
fields = "__all__"
|
|
|
|
exclude = ("net", "cpu", "ram", "gpu", "disks", "software")
|
2020-06-09 21:59:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ComputerRamRelationCreateForm(forms.ModelForm):
|
|
|
|
"""
|
|
|
|
Basic form class to use crispies HTML5 forms.
|
|
|
|
"""
|
2022-03-27 14:50:44 +02:00
|
|
|
|
2020-06-09 21:59:20 +02:00
|
|
|
class Meta:
|
|
|
|
model = ComputerRamRelation
|
2022-03-27 14:50:44 +02:00
|
|
|
fields = "__all__"
|
2020-06-15 21:38:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ComputerCpuRelationCreateForm(forms.ModelForm):
|
|
|
|
"""
|
|
|
|
Basic form class to use crispies HTML5 forms.
|
|
|
|
"""
|
2022-03-27 14:50:44 +02:00
|
|
|
|
2020-06-15 21:38:21 +02:00
|
|
|
class Meta:
|
|
|
|
model = ComputerCpuRelation
|
2022-03-27 14:50:44 +02:00
|
|
|
fields = "__all__"
|
2020-06-15 21:38:21 +02:00
|
|
|
|
|
|
|
|
2020-06-15 21:39:31 +02:00
|
|
|
class ComputerGpuRelationCreateForm(forms.ModelForm):
|
|
|
|
"""
|
|
|
|
Basic form class to use crispies HTML5 forms.
|
|
|
|
"""
|
2022-03-27 14:50:44 +02:00
|
|
|
|
2020-06-15 21:39:31 +02:00
|
|
|
class Meta:
|
|
|
|
model = ComputerGpuRelation
|
2022-03-27 14:50:44 +02:00
|
|
|
fields = "__all__"
|
2020-06-15 21:39:31 +02:00
|
|
|
|
|
|
|
|
2020-06-15 21:39:58 +02:00
|
|
|
class ComputerDiskRelationCreateForm(forms.ModelForm):
|
|
|
|
"""
|
|
|
|
Basic form class to use crispies HTML5 forms.
|
|
|
|
"""
|
2022-03-27 14:50:44 +02:00
|
|
|
|
2020-06-15 21:39:58 +02:00
|
|
|
class Meta:
|
|
|
|
model = ComputerDiskRelation
|
2022-03-27 14:50:44 +02:00
|
|
|
fields = "__all__"
|
2020-06-28 19:04:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ComputerSoftwareRelationCreateForm(forms.ModelForm):
|
|
|
|
"""
|
|
|
|
Basic form class to use crispies HTML5 forms.
|
|
|
|
"""
|
2022-03-27 14:50:44 +02:00
|
|
|
|
2020-06-28 19:04:55 +02:00
|
|
|
class Meta:
|
|
|
|
model = ComputerSoftwareRelation
|
2022-03-27 14:50:44 +02:00
|
|
|
fields = "__all__"
|
2020-06-29 22:43:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
class RaidCreateForm(forms.ModelForm):
|
|
|
|
"""
|
|
|
|
Basic form class to use crispies HTML5 forms.
|
|
|
|
"""
|
2022-03-27 14:50:44 +02:00
|
|
|
|
2020-06-29 22:43:39 +02:00
|
|
|
class Meta:
|
|
|
|
model = Raid
|
2022-03-27 14:50:44 +02:00
|
|
|
fields = "__all__"
|