You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.3 KiB
Python
65 lines
2.3 KiB
Python
from django.forms import ModelForm, TextInput, CharField, Form
|
|
|
|
from containers.models import Container
|
|
|
|
|
|
class ContainerBaseForm(ModelForm):
|
|
class Meta:
|
|
model = Container
|
|
fields = '__all__'
|
|
widgets = {
|
|
'number': TextInput(attrs={
|
|
'oninput': 'validateContainerNumber(this)',
|
|
'class': 'form-control'
|
|
})
|
|
}
|
|
class ContainerReceiveForm(ContainerBaseForm):
|
|
"""
|
|
Form for creating a new Container instance.
|
|
Inherits from ContainerBaseForm.
|
|
"""
|
|
class Meta(ContainerBaseForm.Meta):
|
|
fields = ['number', 'receive_vehicle', 'damages', 'heavy_damaged', 'position',]
|
|
|
|
def __init__(self, *args, preinfo=None, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
|
|
# Add form-control class to all fields
|
|
for field in self.fields.values():
|
|
field.widget.attrs.update({'class': 'form-control'})
|
|
|
|
# Checkbox specific styling
|
|
self.fields['heavy_damaged'].widget.attrs.update({'class': 'form-check-input'})
|
|
|
|
# If preinfo is provided, set initial values and make fields readonly
|
|
if preinfo:
|
|
...
|
|
# self.fields['preinfo'].initial = preinfo.container_number
|
|
# self.fields['number'].initial = preinfo.number
|
|
# self.fields['container_number'].widget.attrs['readonly'] = True
|
|
# self.fields['number'].widget.attrs['readonly'] = True
|
|
# self.fields['booking'].disabled = True
|
|
# self.fields['number'].disabled = True
|
|
|
|
|
|
class ContainerExpeditionForm(ContainerBaseForm):
|
|
class Meta(ContainerBaseForm.Meta):
|
|
fields = ['number', 'expedition_vehicle', 'position', 'line', 'container_type', 'damages', 'heavy_damaged']
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
readonly_fields = ['number', 'position', 'line', 'container_type', 'damages', 'heavy_damaged']
|
|
for field in readonly_fields:
|
|
self.fields[field].widget.attrs['readonly'] = True
|
|
# self.fields[field].disabled = True
|
|
|
|
|
|
class ContainerSearchForm(Form):
|
|
container_number = CharField(
|
|
max_length=11,
|
|
required=True,
|
|
widget=TextInput(attrs={
|
|
'class': 'form-control',
|
|
'placeholder': 'Enter container number'
|
|
})
|
|
) |