Permalink
Browse files

Use first the widget defined in the hint

  • Loading branch information...
1 parent e97c342 commit 168811e9b8724225e16198bdbaca735295162a6c @LeResKP LeResKP committed Sep 5, 2013
Showing with 24 additions and 6 deletions.
  1. +21 −3 tests/test_widgets.py
  2. +3 −3 tw2/sqla/factory.py
View
24 tests/test_widgets.py
@@ -36,6 +36,8 @@ def setUp(self):
pass
+class InfoField(twf.InputField): pass
+
class ElixirBase(object):
def setUp(self):
el.metadata = sa.MetaData('sqlite:///:memory:')
@@ -117,6 +119,11 @@ class DbTestCls12(el.Entity):
def __unicode__(self):
return self.name
+ class DbTestCls13(el.Entity):
+ name = el.Field(el.String, info={'edit_widget': InfoField})
+ def __unicode__(self):
+ return self.name
+
self.DbTestCls1 = DbTestCls1
self.DbTestCls2 = DbTestCls2
@@ -130,6 +137,7 @@ def __unicode__(self):
self.DbTestCls10 = DbTestCls10
self.DbTestCls11 = DbTestCls11
self.DbTestCls12 = DbTestCls12
+ self.DbTestCls13 = DbTestCls13
el.setup_all()
el.metadata.create_all()
@@ -263,6 +271,13 @@ class DbTestCls12(Base):
def __unicode__(self):
return self.name
+ class DbTestCls13(Base):
+ __tablename__ = 'Test13'
+ id = sa.Column(sa.Integer, primary_key=True)
+ name = sa.Column(sa.String(50), info={'edit_widget': InfoField})
+ def __unicode__(self):
+ return self.name
+
self.DbTestCls1 = DbTestCls1
self.DbTestCls2 = DbTestCls2
@@ -276,6 +291,7 @@ def __unicode__(self):
self.DbTestCls10 = DbTestCls10
self.DbTestCls11 = DbTestCls11
self.DbTestCls12 = DbTestCls12
+ self.DbTestCls13 = DbTestCls13
Base.metadata.create_all()
@@ -1096,15 +1112,18 @@ class AwesomePolicy(tws.WidgetPolicy):
assert(False)
def test_info_on_prop(self):
- class AwesomePolicy(tws.WidgetPolicy):
+ """Test we use first the data defined in the hint
+ """
+ class AwesomePolicy(tws.EditPolicy):
name_widgets = { 'name' : twf.LabelField, }
props = filter(
lambda x : x.key == 'name',
- sa.orm.class_mapper(self.DbTestCls1).iterate_properties)
+ sa.orm.class_mapper(self.DbTestCls13).iterate_properties)
assert(len(props) == 1)
try:
w = AwesomePolicy.factory(props[0])
+ assert(issubclass(w, InfoField))
except twc.WidgetError, e:
assert(False)
@@ -1192,7 +1211,6 @@ def test_request_get(self):
</td></tr>
</table></body></html>""")
-
if el:
class TestAutoListPageElixir(ElixirBase, AutoListPageT): pass
View
6 tw2/sqla/factory.py
@@ -197,12 +197,12 @@ def factory(cls, prop):
reverse_property_name=get_reverse_property_name(prop),
required_on_parent=(not required),
)
- elif prop.key in cls.name_widgets:
- widget = cls.name_widgets[prop.key]
elif cols and cls.hint_name and cls.hint_name in cols[0].info:
if not issubclass(cols[0].info[cls.hint_name], NoWidget):
widget = cols[0].info[cls.hint_name]
- else:
+ elif prop.key in cls.name_widgets:
+ widget = cls.name_widgets[prop.key]
+ else:
for t, c in product(cls.type_widgets, cols):
if isinstance(c.type, t):
widget = cls.type_widgets[t]

0 comments on commit 168811e

Please sign in to comment.