You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
3.1 KiB
104 lines
3.1 KiB
from django import forms
|
|
from django.forms import DateInput
|
|
|
|
from ugssim.models import *
|
|
from ugssim.models import Address
|
|
from django import forms
|
|
|
|
|
|
class UGSModelForm(forms.ModelForm):
|
|
|
|
heading = "Neuer Abschnitt"
|
|
description = "To Fill"
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(forms.ModelForm, self).__init__(*args, **kwargs)
|
|
# 'description should be the first field
|
|
# value = self.fields.pop('description')
|
|
# copy = self.fields.copy()
|
|
# new_pos = self.fields.keyOrder.index('b')
|
|
# self.fields = {'description': value}
|
|
# self.fields.update(copy)
|
|
# set 'form-control' as standard calls
|
|
for name, field in self.fields.items():
|
|
# if field.widget.__class__ == forms.widgets.TextInput:
|
|
if 'class' in field.widget.attrs:
|
|
field.widget.attrs['class'] += 'form-control'
|
|
else:
|
|
field.widget.attrs.update({'class': 'form-control'})
|
|
|
|
|
|
class AddressForm(UGSModelForm):
|
|
|
|
heading = "Mandantendaten"
|
|
description = ""
|
|
class Meta:
|
|
model = Address
|
|
# die ID muss hier wieder rein, weil sonst die Zuordnung nicht klappt oder die user ID muss primaery key werden
|
|
fields = ['user', 'first_name', 'surname', 'birthday', 'street', 'number', 'postcode', 'city']
|
|
widgets = {
|
|
'birthday': forms.DateInput(
|
|
format='%Y-%m-%d',
|
|
attrs={
|
|
'type': 'date'
|
|
}
|
|
),
|
|
}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
# Fügt onchange zu allen Formularfeldern hinzu.
|
|
for field in self.fields:
|
|
self.fields[field].widget.attrs.update({'onchange': 'savePlanningparameter(this.form)'})
|
|
|
|
|
|
class SummaryForm(UGSModelForm):
|
|
heading = "Zusammenfassung"
|
|
description = ""
|
|
class Meta:
|
|
model = Summary
|
|
fields = '__all__'
|
|
widgets = {
|
|
'text': forms.Textarea(attrs={'rows': 10})
|
|
}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
# Fügt onchange zu allen Formularfeldern hinzu.
|
|
for field in self.fields:
|
|
self.fields[field].widget.attrs.update({'onchange': 'savePlanningparameter(this.form)'})
|
|
|
|
|
|
class SalesAreaTypeForm(UGSModelForm):
|
|
class Meta:
|
|
model = SalesAreaType
|
|
fields = '__all__'
|
|
|
|
|
|
class SalesAreaForm(UGSModelForm):
|
|
class Meta:
|
|
model = SalesArea
|
|
fields = '__all__'
|
|
|
|
|
|
class CompanyForm(UGSModelForm):
|
|
|
|
heading = "Firmendaten"
|
|
description = ""
|
|
class Meta:
|
|
model = Company
|
|
fields = '__all__'
|
|
widgets = {
|
|
'startDate': forms.DateInput(
|
|
format='%Y-%m-%m',
|
|
attrs={
|
|
'type': 'date'
|
|
}
|
|
)
|
|
}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
# Fügt onchange zu allen Formularfeldern hinzu.
|
|
for field in self.fields:
|
|
self.fields[field].widget.attrs.update({'onchange': 'savePlanningparameter(this.form)'})
|
|
|