[form] refactor meta-attributes handling: hide them by default using uicfg.afs instead of returning None (or not, according to skip_meta_attr flag argument) in guess_field
--- a/web/formfields.py Thu Jun 10 10:18:34 2010 +0200
+++ b/web/formfields.py Thu Jun 10 14:16:47 2010 +0200
@@ -1084,18 +1084,13 @@
_AFF_KWARGS = uicfg.autoform_field_kwargs
-def guess_field(eschema, rschema, role='subject', skip_meta_attr=True, **kwargs):
+def guess_field(eschema, rschema, role='subject', **kwargs):
"""This function return the most adapted field to edit the given relation
(`rschema`) where the given entity type (`eschema`) is the subject or object
(`role`).
The field is initialized according to information found in the schema,
though any value can be explicitly specified using `kwargs`.
-
- The `skip_meta_attr` flag is used to specify wether this function should
- return a field for attributes considered as a meta-attributes
- (e.g. describing an other attribute, such as the format or file name of a
- file (`Bytes`) attribute).
"""
fieldclass = None
rdef = eschema.rdef(rschema, role)
@@ -1117,8 +1112,6 @@
kwargs.setdefault('label', (eschema.type, rschema.type))
kwargs.setdefault('help', rdef.description)
if rschema.final:
- if skip_meta_attr and rschema in eschema.meta_attributes():
- return None
fieldclass = FIELDS[targetschema]
if fieldclass is StringField:
if eschema.has_metadata(rschema, 'format'):
@@ -1144,7 +1137,6 @@
if metaschema is not None:
metakwargs = _AFF_KWARGS.etype_get(eschema, metaschema, 'subject')
kwargs['%s_field' % metadata] = guess_field(eschema, metaschema,
- skip_meta_attr=False,
**metakwargs)
return fieldclass(**kwargs)
return RelationField.fromcardinality(card, **kwargs)
--- a/web/test/unittest_formfields.py Thu Jun 10 10:18:34 2010 +0200
+++ b/web/test/unittest_formfields.py Thu Jun 10 14:16:47 2010 +0200
@@ -15,9 +15,7 @@
#
# You should have received a copy of the GNU Lesser General Public License along
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
-"""unittests for cw.web.formfields
-
-"""
+"""unittests for cw.web.formfields"""
from logilab.common.testlib import TestCase, unittest_main, mock_object as mock
@@ -53,10 +51,10 @@
self.assertEquals(description_field.required, False)
self.assertEquals(description_field.format_field, None)
+ # description_format_field = guess_field(schema['State'], schema['description_format'])
+ # self.assertEquals(description_format_field, None)
+
description_format_field = guess_field(schema['State'], schema['description_format'])
- self.assertEquals(description_format_field, None)
-
- description_format_field = guess_field(schema['State'], schema['description_format'], skip_meta_attr=False)
self.assertEquals(description_format_field.internationalizable, True)
self.assertEquals(description_format_field.sort, True)
@@ -88,12 +86,12 @@
def test_file_fields(self):
- data_format_field = guess_field(schema['File'], schema['data_format'])
- self.assertEquals(data_format_field, None)
- data_encoding_field = guess_field(schema['File'], schema['data_encoding'])
- self.assertEquals(data_encoding_field, None)
- data_name_field = guess_field(schema['File'], schema['data_name'])
- self.assertEquals(data_name_field, None)
+ # data_format_field = guess_field(schema['File'], schema['data_format'])
+ # self.assertEquals(data_format_field, None)
+ # data_encoding_field = guess_field(schema['File'], schema['data_encoding'])
+ # self.assertEquals(data_encoding_field, None)
+ # data_name_field = guess_field(schema['File'], schema['data_name'])
+ # self.assertEquals(data_name_field, None)
data_field = guess_field(schema['File'], schema['data'])
self.assertIsInstance(data_field, FileField)
--- a/web/uicfg.py Thu Jun 10 10:18:34 2010 +0200
+++ b/web/uicfg.py Thu Jun 10 14:16:47 2010 +0200
@@ -218,6 +218,12 @@
sectdict.setdefault('main', 'hidden')
sectdict.setdefault('muledit', 'hidden')
sectdict.setdefault('inlined', 'hidden')
+ elif role == 'subject' and rschema in sschema.meta_attributes():
+ # meta attribute, usually embeded by the described attribute's field
+ # (eg RichTextField, FileField...)
+ sectdict.setdefault('main', 'hidden')
+ sectdict.setdefault('muledit', 'hidden')
+ sectdict.setdefault('inlined', 'hidden')
# ensure we have a tag for each form type
if not 'main' in sectdict:
if not rschema.final and (