@@ -181,7 +181,7 @@ def member_from_model(cls, model, factory_lookup, defaults_factory, factory_look
181181 factory_lookup = factory_lookup ,
182182 defaults_factory = defaults_factory ,
183183 factory_lookup_register_function = factory_lookup_register_function ,
184- field_name = sub_field_name ,
184+ field_name = field_path_rest ,
185185 ** kwargs )
186186 result .name = field_name
187187 result .attr = field_name
@@ -191,6 +191,7 @@ def member_from_model(cls, model, factory_lookup, defaults_factory, factory_look
191191 kwargs ,
192192 defaults_factory (model_field ),
193193 name = field_name ,
194+ call_target__cls = cls ,
194195 )
195196
196197 factory = factory_lookup .get (type (model_field ), MISSING )
@@ -207,16 +208,9 @@ def member_from_model(cls, model, factory_lookup, defaults_factory, factory_look
207208 message += ' Register a factory with %s, you can also register one that returns None to not handle this field type' % factory_lookup_register_function .__name__
208209 raise AssertionError (message )
209210
210- def call_target (* call_target_args , ** call_target_kwargs ):
211- class_call_target = call_target_kwargs .pop ('class_call_target' , None )
212- if class_call_target :
213- return getattr (cls , class_call_target )(* call_target_args , ** call_target_kwargs )
214- else :
215- return cls (* call_target_args , ** call_target_kwargs )
216-
217211 if factory :
218212 factory = evaluate (factory , model_field = model_field , field_name = field_name )
219- return factory (call_target = call_target , model_field = model_field , model = model , ** kwargs ) if factory else None
213+ return factory (model_field = model_field , model = model , ** kwargs ) if factory is not None else None
220214
221215
222216@dispatch (
@@ -967,7 +961,7 @@ def _choice_post_validation(form, field):
967961
968962 @classmethod
969963 @class_shortcut (
970- class_call_target = "choice" ,
964+ call_target__attribute = "choice" ,
971965 choices = [True , False ],
972966 parse = choice_parse ,
973967 choice_to_option = lambda form , field , choice , ** _ : (
@@ -983,7 +977,7 @@ def boolean_tristate(cls, call_target=None, **kwargs):
983977
984978 @classmethod
985979 @class_shortcut (
986- class_call_target = "choice" ,
980+ call_target__attribute = "choice" ,
987981 parse = choice_queryset_parse ,
988982 choice_to_option = choice_queryset_choice_to_option ,
989983 endpoint_path = choice_queryset_endpoint_path ,
@@ -1011,7 +1005,7 @@ def choice_queryset(cls, choices, call_target=None, **kwargs):
10111005
10121006 @classmethod
10131007 @class_shortcut (
1014- class_call_target = "choice" ,
1008+ call_target__attribute = "choice" ,
10151009 attrs__multiple = True ,
10161010 choice_to_option = multi_choice_choice_to_option ,
10171011 is_list = True ,
@@ -1021,7 +1015,7 @@ def multi_choice(cls, call_target=None, **kwargs):
10211015
10221016 @classmethod
10231017 @class_shortcut (
1024- class_call_target = "choice_queryset" ,
1018+ call_target__attribute = "choice_queryset" ,
10251019 attrs__multiple = True ,
10261020 choice_to_option = multi_choice_queryset_choice_to_option ,
10271021 is_list = True ,
@@ -1031,7 +1025,7 @@ def multi_choice_queryset(cls, call_target=None, **kwargs):
10311025
10321026 @classmethod
10331027 @class_shortcut (
1034- class_call_target = "choice" ,
1028+ call_target__attribute = "choice" ,
10351029 input_template = 'tri_form/radio.html' ,
10361030 )
10371031 def radio (cls , call_target = None , ** kwargs ):
@@ -1131,7 +1125,7 @@ def phone_number(cls, call_target=None, **kwargs):
11311125
11321126 @classmethod
11331127 @class_shortcut (
1134- class_call_target = 'choice_queryset' ,
1128+ call_target__attribute = 'choice_queryset' ,
11351129 )
11361130 def foreign_key (cls , model_field , model , call_target , ** kwargs ):
11371131 del model
@@ -1143,7 +1137,7 @@ def foreign_key(cls, model_field, model, call_target, **kwargs):
11431137
11441138 @classmethod
11451139 @class_shortcut (
1146- class_call_target = 'multi_choice_queryset' ,
1140+ call_target__attribute = 'multi_choice_queryset' ,
11471141 )
11481142 def many_to_many (cls , call_target , model_field , ** kwargs ):
11491143 setdefaults_path (
@@ -1156,50 +1150,6 @@ def many_to_many(cls, call_target, model_field, **kwargs):
11561150 kwargs ['model' ] = model_field .remote_field .model
11571151 return call_target (model_field = model_field , ** kwargs )
11581152
1159- @classmethod
1160- @class_shortcut (
1161- nested = EMPTY ,
1162- )
1163- def comma_separated (cls , call_target , nested , ** kwargs ):
1164- """
1165- Shortcut to create a comma separated list of something. You can use this to create a comma separated text input that gives nice validation errors easily. Example:
1166-
1167- .. code:: python
1168-
1169- Field.comma_separated(nested=Field.email)
1170- """
1171- if 'call_target' in nested :
1172- nested = nested ()
1173- else :
1174- nested = nested (class_call_target_class = cls )
1175-
1176- def parse_comma_separated (form , field , string_value ):
1177- errors = []
1178- result = []
1179- for x in string_value .split (',' ):
1180- x = x .strip ()
1181- try :
1182- result .append (nested .parse (form = form , field = field , string_value = x .strip ()))
1183- except ValueError as e :
1184- errors .append ('Invalid value "%s": %s' % (x , e ))
1185- except ValidationError as e :
1186- for message in e .messages :
1187- errors .append ('Invalid value "%s": %s' % (x , message ))
1188- if errors :
1189- raise ValidationError (errors )
1190- return ', ' .join (result )
1191-
1192- def is_valid_comma_separated (form , field , parsed_data ):
1193- errors = set ()
1194- for x in parsed_data .split (',' ):
1195- x = x .strip ()
1196- is_valid , error = nested .is_valid (form = form , field = field , parsed_data = x )
1197- if not is_valid :
1198- errors .add ('Invalid value "%s": %s' % (x , error ))
1199- return errors == set (), errors
1200-
1201- return call_target (is_valid = is_valid_comma_separated , parse = parse_comma_separated , ** kwargs )
1202-
12031153
12041154def get_fields (model ):
12051155 # noinspection PyProtectedMember
0 commit comments