Browse files

compound_key was ignoring key for RepeatingWidget

  • Loading branch information...
amol- committed Nov 15, 2013
1 parent 85af595 commit ed09461460775b9d8034ecfcb8cb8680a43c9fee
Showing with 23 additions and 13 deletions.
  1. +9 −0 tests/
  2. +14 −13 tw2/core/
@@ -589,6 +589,15 @@ class T(wd.RepeatingWidget):
children = [wd.Widget(id="foo")]
self.assert_(len(T().req().child.children) == 1)
def testRepeatingWithKeyDifferentFromId(self):
class T(wd.RepeatingWidget):
id = 'foo'
key = 'bar'
child = wd.Widget
w = T().req(value=['1', '2', '3'])
self.assertEquals(w.children[0].compound_key, 'bar:0')
def testNonWidgetChild(self):
should throw an error if child is not a widget
@@ -257,7 +257,7 @@ def post_define(cls):
setattr(cls,, p.default)
def _gen_compound_id(cls, for_url):
def _gen_compound_name(cls, attr, for_url):
ancestors = []
cur = cls
while cur:
@@ -266,34 +266,35 @@ def _gen_compound_id(cls, for_url):
cur = cur.parent
elems = reversed(list(filter(None, [
a._compound_id_elem(for_url) for a in ancestors
a._compound_name_elem(attr, for_url) for a in ancestors
if getattr(cls, 'id', None) or \
if getattr(cls, attr, None) or \
(cls.parent and issubclass(cls.parent, RepeatingWidget)):
return ':'.join(elems)
return None
def _compound_id_elem(cls, for_url):
def _compound_name_elem(cls, attr, for_url):
if cls.parent and issubclass(cls.parent, RepeatingWidget):
if for_url:
return None
return str(getattr(cls, 'repetition', None))
return getattr(cls, 'id', None)
return getattr(cls, attr, None)
def _gen_compound_key(cls):
if not cls.key:
return cls.compound_id
def _compound_id_elem(cls, for_url):
return cls._compound_name_elem('id', for_url)
parent_key = getattr(cls.parent, 'compound_key', None)
if parent_key:
return ':'.join([parent_key, cls.key])
return cls.key
def _gen_compound_id(cls, for_url):
return cls._gen_compound_name('id', for_url)
def _gen_compound_key(cls):
return cls._gen_compound_name('key', False)
def get_link(cls):

0 comments on commit ed09461

Please sign in to comment.