Przeglądaj źródła

Fix form field iteration

theenglishway (time) 6 lat temu
rodzic
commit
1524238205
2 zmienionych plików z 5 dodań i 6 usunięć
  1. 1 1
      pydantic_form/iterators.py
  2. 4 5
      tests/conftest.py

+ 1 - 1
pydantic_form/iterators.py

@@ -6,7 +6,7 @@ from .utils import *
 
 def iter_field(field, leafs_only=True, path=(), parent=None):
     if issubclass(field.field_class, FormField):
-        field_class = field.kwargs['form_class']
+        field_class = field.kwargs.get('form_class', None) or field.args[0]
         if path and not leafs_only:
             yield path, field_class, parent
 

+ 4 - 5
tests/conftest.py

@@ -2,7 +2,6 @@ import pytest
 import factory
 from collections import namedtuple
 from wtforms import Form, fields
-from werkzeug.datastructures import ImmutableMultiDict
 from pydantic_form import PydanticForm
 from pydantic import BaseModel, ValidationError
 from pydantic.types import StrictStr
@@ -226,7 +225,7 @@ class NestedWTForm(Form):
     _schema = NestedSchema
 
     integer = fields.IntegerField()
-    nested = fields.FormField(form_class=SimpleForm)
+    nested = fields.FormField(SimpleForm)
 
 
 class NestedForm(NestedWTForm, PydanticForm):
@@ -312,7 +311,7 @@ class NestedListWTForm(Form):
     _schema = NestedListSchema
 
     integer = fields.IntegerField()
-    nested_list = fields.FieldList(fields.FormField(form_class=SimpleForm), min_entries=2)
+    nested_list = fields.FieldList(fields.FormField(SimpleForm), min_entries=2)
 
 
 class NestedListForm(NestedListWTForm, PydanticForm):
@@ -414,12 +413,12 @@ class DoubleNestedWTForm(Form):
     _schema = DoubleNestedSchema
 
     integer = fields.IntegerField()
-    double_nested = fields.FormField(form_class=NestedWTForm)
+    double_nested = fields.FormField(NestedWTForm)
 
 
 class DoubleNestedForm(DoubleNestedWTForm, PydanticForm):
     _schema = DoubleNestedSchema
-    double_nested = fields.FormField(form_class=NestedForm)
+    double_nested = fields.FormField(NestedForm)
 
 
 class DoubleNestedDataFactory(factory.Factory):