proper field's role handling: may be 'subject' / 'object' *in case
of entity's relation*, but None in other case. So you should correctly
specify it to field_by_name
--- a/web/form.py Mon Dec 21 20:21:56 2009 +0100
+++ b/web/form.py Mon Dec 21 20:23:56 2009 +0100
@@ -101,7 +101,7 @@
return fields
@iclassmethod
- def field_by_name(cls_or_self, name, role='subject'):
+ def field_by_name(cls_or_self, name, role=None):
"""return field with the given name and role.
Raise FieldNotFound if the field can't be found.
"""
@@ -111,7 +111,7 @@
raise FieldNotFound(name)
@iclassmethod
- def fields_by_name(cls_or_self, name, role='subject'):
+ def fields_by_name(cls_or_self, name, role=None):
"""return a list of fields with the given name and role"""
return [field for field in cls_or_self._fieldsattr()
if field.name == name and field.role == role]
--- a/web/formfields.py Mon Dec 21 20:21:56 2009 +0100
+++ b/web/formfields.py Mon Dec 21 20:23:56 2009 +0100
@@ -433,7 +433,7 @@
try:
return req.data[self]
except KeyError:
- fkwargs = {'eidparam': self.eidparam}
+ fkwargs = {'eidparam': self.eidparam, 'role': self.role}
if self.use_fckeditor(form):
# if fckeditor is used and format field isn't explicitly
# deactivated, we want an hidden field for the format
@@ -823,6 +823,7 @@
card = rdef.role_cardinality(role)
kwargs['required'] = card in '1+'
kwargs['name'] = rschema.type
+ kwargs['role'] = role
if role == 'object':
kwargs.setdefault('label', (eschema.type, rschema.type + '_object'))
else:
@@ -858,7 +859,6 @@
kwargs['%s_field' % metadata] = guess_field(eschema, metaschema,
skip_meta_attr=False)
return fieldclass(**kwargs)
- kwargs['role'] = role
return RelationField.fromcardinality(card, **kwargs)
--- a/web/views/autoform.py Mon Dec 21 20:21:56 2009 +0100
+++ b/web/views/autoform.py Mon Dec 21 20:23:56 2009 +0100
@@ -52,7 +52,7 @@
# class methods mapping schema relations to fields in the form ############
@iclassmethod
- def field_by_name(cls_or_self, name, role='subject', eschema=None):
+ def field_by_name(cls_or_self, name, role=None, eschema=None):
"""return field with the given name and role. If field is not explicitly
defined for the form but `eclass` is specified, guess_field will be
called.
@@ -60,7 +60,7 @@
try:
return super(AutomaticEntityForm, cls_or_self).field_by_name(name, role)
except form.FieldNotFound:
- if eschema is None or not name in eschema.schema:
+ if eschema is None or role is None or not name in eschema.schema:
raise
rschema = eschema.schema.rschema(name)
# XXX use a sample target type. Document this.