50 rfields_kwargs = uicfg.autoform_field_kwargs |
50 rfields_kwargs = uicfg.autoform_field_kwargs |
51 |
51 |
52 # class methods mapping schema relations to fields in the form ############ |
52 # class methods mapping schema relations to fields in the form ############ |
53 |
53 |
54 @iclassmethod |
54 @iclassmethod |
55 def field_by_name(cls_or_self, name, role='subject', eschema=None): |
55 def field_by_name(cls_or_self, name, role=None, eschema=None): |
56 """return field with the given name and role. If field is not explicitly |
56 """return field with the given name and role. If field is not explicitly |
57 defined for the form but `eclass` is specified, guess_field will be |
57 defined for the form but `eclass` is specified, guess_field will be |
58 called. |
58 called. |
59 """ |
59 """ |
60 try: |
60 try: |
61 return super(AutomaticEntityForm, cls_or_self).field_by_name(name, role) |
61 return super(AutomaticEntityForm, cls_or_self).field_by_name(name, role) |
62 except form.FieldNotFound: |
62 except form.FieldNotFound: |
63 if eschema is None or not name in eschema.schema: |
63 if eschema is None or role is None or not name in eschema.schema: |
64 raise |
64 raise |
65 rschema = eschema.schema.rschema(name) |
65 rschema = eschema.schema.rschema(name) |
66 # XXX use a sample target type. Document this. |
66 # XXX use a sample target type. Document this. |
67 tschemas = rschema.targets(eschema, role) |
67 tschemas = rschema.targets(eschema, role) |
68 fieldcls = cls_or_self.rfields.etype_get(eschema, rschema, role, |
68 fieldcls = cls_or_self.rfields.etype_get(eschema, rschema, role, |