gpp/port/forms.py

255 lines
5.6 KiB
Python

from django.forms import Form, ModelForm, \
CharField, IntegerField, DecimalField, ChoiceField,\
BooleanField, EmailField, DateTimeField, ImageField, \
formset_factory, SelectDateWidget, TextInput, \
HiddenInput, \
RadioSelect
from django_countries.fields import CountryField
from phonenumber_field.formfields import PhoneNumberField
from .models import Address, Person, Company, Insurance, Boat, \
SailsOn, BoatInsurance, Port, Employee, Dock, Plug, Tap, \
Payment, Service, Bill, BillLine, BillPayment, Stay, Mooring
class AddressForm(ModelForm):
class Meta:
model = Address
fields = [
'address',
'zip_code',
'city',
'country'
]
class PersonForm(ModelForm):
class Meta:
model = Person
fields = [
'name',
'surname',
'nationality',
'email',
'phone'
]
"""
name = CharField(label='Name', max_length=50)
surname = CharField(label='Surname', max_length=50)
nationality = CountryField().formfield(label='Nationality')
email = EmailField(label='E-Mail')
phone = PhoneNumberField(label='Phone Number')
"""
class CompanyForm(ModelForm):
class Meta:
model = Company
fields = [
'name',
'email',
'phone',
'registration_num']
class InsuranceSearchForm(Form):
search_name = CharField(
label='Name',
required=False
)
search_results = ChoiceField(
label='Insurances',
widget=RadioSelect
)
def __init__(self, name='', choices=[]):
super(Form, self).__init__()
self.fields['search_name'].initial = name
if choices == [] and len(name) < 3:
self.fields.pop('search_results')
else:
self.fields['search_results'].choices = choices
class InsuranceForm(CompanyForm):
class Meta:
model = Insurance
fields = [
'name']
class BoatSearchForm(Form):
search_name = CharField(
label='Name'
)
search_results = ChoiceField(
label='Boats',
widget=RadioSelect
)
def __init__(self, name='', choices=[]):
super(Form, self).__init__()
self.fields['search_name'].initial = name
if choices == [] and len(name) < 3:
self.fields.pop('search_results')
else:
self.fields['search_results'].choices = choices
class BoatForm(ModelForm):
class Meta:
model = Boat
fields = ['name',
'registration_num',
'length',
'beam',
'water_draught',
'tonnage',
'water_tank',
'model',
'heating',
'passenger_capacity',
'company',
'picture']
class SailorsForm(ModelForm):
class Meta:
model = SailsOn
fields = [
'person',
'is_captain',
'is_crew',
'is_owner',
'is_guest',
'is_pet',
'present'
]
widgets = {
'person': HiddenInput()
}
SailorsFormSet = formset_factory(SailorsForm, extra=0)
class PortForm(ModelForm):
class Meta:
model = Port
fields = [
'name',
'address',
'company']
class EmployeeForm(ModelForm):
class Meta:
model = Employee
fields = [
'port',
'position'
]
class DockForm(ModelForm):
class Meta:
model = Dock
fields = [
'name',
'length',
'width',
'depth_min',
'depth_max']
"""
name = CharField(label='Name', max_length=10)
length = DecimalField(
label='Length', min_value=0,
max_digits=7,
decimal_places=2)
width = DecimalField(
label='Width', min_value=0,
max_digits=7,
decimal_places=2)
depth_min = DecimalField(
label='Depth (min.)', min_value=0,
max_digits=7,
decimal_places=2)
depth_max = DecimalField(
label='Depth (max.)', min_value=0,
max_digits=7,
decimal_places=2)
"""
DockFormSet = formset_factory(DockForm)
class PlugForm(ModelForm):
class Meta:
model = Plug
fields = [
'name',
'amperage',
'voltage',
]
"""
name = CharField(label='Name', max_length=10)
amperage = DecimalField(
label='Amperage',
min_value=0,
max_digits=3,
decimal_places=0)
voltage = DecimalField(
label='Voltage',
min_value=0,
max_digits=3,
decimal_places=0)
"""
PlugFormSet = formset_factory(PlugForm)
class TapForm(ModelForm):
class Meta:
model = Tap
fields = [
'name']
"""
name = CharField(label='Name', max_length=10)
"""
TapFormSet = formset_factory(TapForm)
class StayForm(ModelForm):
class Meta:
model = Stay
fields = ['arrival',
'departure',
'coming_from',
'going_to',
'no_mooring']
widgets = {
'arrival': SelectDateWidget(),
'departure': SelectDateWidget()
}
class MooringForm(ModelForm):
class Meta:
model = Mooring
fields = ['date',
'dock',
'tap',
'plug']
MooringFormSet = formset_factory(MooringForm)