Skip to content

Commit

Permalink
One more fix
Browse files Browse the repository at this point in the history
  • Loading branch information
goerch committed Nov 10, 2023
1 parent 7b3fb14 commit c2bf1a8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
6 changes: 5 additions & 1 deletion flask_appbuilder/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ def __init__(
def convert(self):
for type_marker, field in self.conversion_table:
if getattr(self.datamodel, type_marker)(self.colname):
col_type = self.datamodel.list_columns[self.colname].type
col_type = (
self.datamodel.list_columns[self.colname].type
if type_marker in ["is_enum", "is_numeric"]
else None
)
return field(self, col_type)
log.error("Column %s Type not supported", self.colname)

Expand Down
30 changes: 24 additions & 6 deletions tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,18 @@ def test_model_without_context(self):
self.assertTrue(form.field_float.field_class is FloatField)
self.assertTrue(form.field_integer.field_class is IntegerField)
print(form.field_numeric_scale0.kwargs["places"])
self.assertTrue(form.field_numeric_scale0.field_class is DecimalField and not form.field_numeric_scale0.kwargs["places"])
self.assertTrue(form.field_numeric_scale2.field_class is DecimalField and form.field_numeric_scale2.kwargs["places"] == 2)
self.assertTrue(form.field_numeric_scale4.field_class is DecimalField and form.field_numeric_scale4.kwargs["places"] == 4)
self.assertTrue(
form.field_numeric_scale0.field_class is DecimalField
and not form.field_numeric_scale0.kwargs["places"]
)
self.assertTrue(
form.field_numeric_scale2.field_class is DecimalField
and form.field_numeric_scale2.kwargs["places"] == 2
)
self.assertTrue(
form.field_numeric_scale4.field_class is DecimalField
and form.field_numeric_scale4.kwargs["places"] == 4
)
self.assertTrue(form.field_string.field_class is StringField)
self.assertTrue(form.field_text.field_class is TextAreaField)

Expand Down Expand Up @@ -114,8 +123,17 @@ def test_model_with_context(self):
# self.assertTrue(isinstance(form.field_enum, EnumField))
self.assertTrue(isinstance(form.field_float, FloatField))
self.assertTrue(isinstance(form.field_integer, IntegerField))
self.assertTrue(isinstance(form.field_numeric_scale0, DecimalField) and not form.field_numeric_scale0.places)
self.assertTrue(isinstance(form.field_numeric_scale2, DecimalField) and form.field_numeric_scale2.places == 2)
self.assertTrue(isinstance(form.field_numeric_scale4, DecimalField) and form.field_numeric_scale4.places == 4)
self.assertTrue(
isinstance(form.field_numeric_scale0, DecimalField)
and not form.field_numeric_scale0.places
)
self.assertTrue(
isinstance(form.field_numeric_scale2, DecimalField)
and form.field_numeric_scale2.places == 2
)
self.assertTrue(
isinstance(form.field_numeric_scale4, DecimalField)
and form.field_numeric_scale4.places == 4
)
self.assertTrue(isinstance(form.field_string, StringField))
self.assertTrue(isinstance(form.field_text, TextAreaField))

0 comments on commit c2bf1a8

Please sign in to comment.