forked from CGM_Public/pretix_original
Show initial values in form
This commit is contained in:
committed by
johan12345
parent
3483c522da
commit
8e22c0f3a4
@@ -173,6 +173,7 @@ class BaseQuestionsForm(forms.Form):
|
|||||||
initial = None
|
initial = None
|
||||||
tz = pytz.timezone(event.settings.timezone)
|
tz = pytz.timezone(event.settings.timezone)
|
||||||
help_text = rich_text(q.help_text)
|
help_text = rich_text(q.help_text)
|
||||||
|
default = q.default_value
|
||||||
label = escape(q.question) # django-bootstrap3 calls mark_safe
|
label = escape(q.question) # django-bootstrap3 calls mark_safe
|
||||||
required = q.required and not self.all_optional
|
required = q.required and not self.all_optional
|
||||||
if q.type == Question.TYPE_BOOLEAN:
|
if q.type == Question.TYPE_BOOLEAN:
|
||||||
@@ -185,6 +186,8 @@ class BaseQuestionsForm(forms.Form):
|
|||||||
|
|
||||||
if initial:
|
if initial:
|
||||||
initialbool = (initial.answer == "True")
|
initialbool = (initial.answer == "True")
|
||||||
|
elif default:
|
||||||
|
initialbool = (default == "True")
|
||||||
else:
|
else:
|
||||||
initialbool = False
|
initialbool = False
|
||||||
|
|
||||||
@@ -197,21 +200,21 @@ class BaseQuestionsForm(forms.Form):
|
|||||||
field = forms.DecimalField(
|
field = forms.DecimalField(
|
||||||
label=label, required=required,
|
label=label, required=required,
|
||||||
help_text=q.help_text,
|
help_text=q.help_text,
|
||||||
initial=initial.answer if initial else None,
|
initial=initial.answer if initial else default if default else None,
|
||||||
min_value=Decimal('0.00'),
|
min_value=Decimal('0.00'),
|
||||||
)
|
)
|
||||||
elif q.type == Question.TYPE_STRING:
|
elif q.type == Question.TYPE_STRING:
|
||||||
field = forms.CharField(
|
field = forms.CharField(
|
||||||
label=label, required=required,
|
label=label, required=required,
|
||||||
help_text=help_text,
|
help_text=help_text,
|
||||||
initial=initial.answer if initial else None,
|
initial=initial.answer if initial else default if default else None,
|
||||||
)
|
)
|
||||||
elif q.type == Question.TYPE_TEXT:
|
elif q.type == Question.TYPE_TEXT:
|
||||||
field = forms.CharField(
|
field = forms.CharField(
|
||||||
label=label, required=required,
|
label=label, required=required,
|
||||||
help_text=help_text,
|
help_text=help_text,
|
||||||
widget=forms.Textarea,
|
widget=forms.Textarea,
|
||||||
initial=initial.answer if initial else None,
|
initial=initial.answer if initial else default if default else None,
|
||||||
)
|
)
|
||||||
elif q.type == Question.TYPE_CHOICE:
|
elif q.type == Question.TYPE_CHOICE:
|
||||||
field = forms.ModelChoiceField(
|
field = forms.ModelChoiceField(
|
||||||
@@ -243,21 +246,21 @@ class BaseQuestionsForm(forms.Form):
|
|||||||
field = forms.DateField(
|
field = forms.DateField(
|
||||||
label=label, required=required,
|
label=label, required=required,
|
||||||
help_text=help_text,
|
help_text=help_text,
|
||||||
initial=dateutil.parser.parse(initial.answer).date() if initial and initial.answer else None,
|
initial=dateutil.parser.parse(initial.answer).date() if initial and initial.answer else dateutil.parser.parse(default).date() if default else None,
|
||||||
widget=DatePickerWidget(),
|
widget=DatePickerWidget(),
|
||||||
)
|
)
|
||||||
elif q.type == Question.TYPE_TIME:
|
elif q.type == Question.TYPE_TIME:
|
||||||
field = forms.TimeField(
|
field = forms.TimeField(
|
||||||
label=label, required=required,
|
label=label, required=required,
|
||||||
help_text=help_text,
|
help_text=help_text,
|
||||||
initial=dateutil.parser.parse(initial.answer).time() if initial and initial.answer else None,
|
initial=dateutil.parser.parse(initial.answer).time() if initial and initial.answer else dateutil.parser.parse(default).time() if default else None,
|
||||||
widget=TimePickerWidget(time_format=get_format_without_seconds('TIME_INPUT_FORMATS')),
|
widget=TimePickerWidget(time_format=get_format_without_seconds('TIME_INPUT_FORMATS')),
|
||||||
)
|
)
|
||||||
elif q.type == Question.TYPE_DATETIME:
|
elif q.type == Question.TYPE_DATETIME:
|
||||||
field = SplitDateTimeField(
|
field = SplitDateTimeField(
|
||||||
label=label, required=required,
|
label=label, required=required,
|
||||||
help_text=help_text,
|
help_text=help_text,
|
||||||
initial=dateutil.parser.parse(initial.answer).astimezone(tz) if initial and initial.answer else None,
|
initial=dateutil.parser.parse(initial.answer).astimezone(tz) if initial and initial.answer else dateutil.parser.parse(default).astimezone(tz) if default else None,
|
||||||
widget=SplitDateTimePickerWidget(time_format=get_format_without_seconds('TIME_INPUT_FORMATS')),
|
widget=SplitDateTimePickerWidget(time_format=get_format_without_seconds('TIME_INPUT_FORMATS')),
|
||||||
)
|
)
|
||||||
field.question = q
|
field.question = q
|
||||||
|
|||||||
Reference in New Issue
Block a user