def get_field_kwargs(form_field):
if isinstance(form_field, BlockFieldWrapper):
return {"text": form_field.block.value.source}
kwargs = OrderedDict()
kwargs = {
"initial": form_field.initial,
"required": form_field.required,
"label": form_field.label,
"label_suffix": form_field.label_suffix,
"help_text": form_field.help_text,
"help_link": form_field.help_link,
}
if isinstance(form_field, forms.CharField):
if hasattr(form_field, "word_limit"):
kwargs["word_limit"] = form_field.word_limit
kwargs["max_length"] = form_field.max_length
kwargs["min_length"] = form_field.min_length
kwargs["empty_value"] = form_field.empty_value
if isinstance(form_field, forms.ChoiceField):
kwargs["choices"] = form_field.choices
if isinstance(form_field, forms.TypedChoiceField):
kwargs["empty_value"] = form_field.empty_value
if isinstance(form_field, forms.IntegerField):
kwargs["max_value"] = form_field.max_value
kwargs["min_value"] = form_field.min_value
if isinstance(form_field, ScoredAnswerField):
fields = [
{
"type": form_field.fields[0].__class__.__name__,
"max_length": form_field.fields[0].max_length,
"min_length": form_field.fields[0].min_length,
"empty_value": form_field.fields[0].empty_value,
},
{
"type": form_field.fields[1].__class__.__name__,
"choices": form_field.fields[1].choices,
},
]
kwargs["fields"] = fields
return kwargs