Changeset 4566
- Timestamp:
- 05/07/08 13:26:40 (7 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
projects/ToscaWidgets/branches/nomaxrep/tests/test_base.py
r4475 r4566 183 183 w = self.widget 184 184 self.assertEqual(len(w.c), 1) 185 self.assertEqual(len(w.c[0].children), 5)185 #self.assertEqual(len(w.c[0].children), 5) 186 186 for c in w.c[0].children: 187 187 self.assertEqual(len(c.children), 2) … … 261 261 262 262 def test_children_can_receive_args_by_key(self): 263 children = self.widget.c.fs.children 264 args = [{c.key:{'legend':'Fieldset-%d'%i}} for i,c in enumerate(children)] 263 child = self.widget.c.fs.children[0] 265 264 child_args = {} 266 map(child_args.update, args) 265 for i in range(self.widget.c.fs.max_repetitions): 266 child.repetition = i 267 child_args[child.key] = {'legend':'Fieldset-%d'%i} 267 268 self.assertInOutput(['Fieldset-%d'%i for i in xrange(5)], **child_args) 268 269 projects/ToscaWidgets/branches/nomaxrep/tw/core/base.py
r4536 r4566 360 360 new_class, self._id, children=self.children, **self.orig_kw 361 361 )(*args, **kw) 362 363 364 362 365 363 … … 1049 1047 widget = widget() 1050 1048 obj = Widget.__new__(cls,id,parent,**kw) 1051 for i in xrange(obj.max_repetitions): 1052 widget._as_repeated(obj, repetition=i, id=obj._id) 1049 widget._as_repeated(obj, id=obj._id) 1053 1050 return obj 1054 1051 … … 1059 1056 a_f = d['args_for'] 1060 1057 repetitions = max(d['repetitions'], len(d['value']) + d.extra) 1061 d.repetitions = min(self.max_repetitions, repetitions) 1062 outputs = [ 1063 w.render(v_f(w), isextra=(w.repetition >= len(d['value'])), **a_f(w)) for w in d['children'][:d.repetitions] 1064 ] 1058 d.repetitions = repetitions 1059 #d.repetitions = min(self.max_repetitions, repetitions) 1060 1061 w = d.children[0] 1062 outputs = [] 1063 for i in range(d.repetitions): 1064 w.repetition = i 1065 outputs.append(w.render(v_f(w), isextra=(w.repetition >= len(d['value'])), **a_f(w))) 1066 1065 1067 d["output"] = '\n'.join(o for o in outputs if o) 1066 1067 1068 1069 1070 1068 1071 1069 … … 1074 1072 class RepeatedWidget(Widget): 1075 1073 params = ["repetition"] 1076 repetition = 0 1074 1075 repetition = RequestLocalDescriptor('fred') # hack! 1076 1077 def __init__(self, *args, **kw): 1078 super(RepeatedWidget, self).__init__(*args, **kw) 1079 self.repetition = RequestLocalDescriptor( 1080 (self.parent.id and (self.parent.id + '.') or '') + (self._id or 'x')) 1081 self.repetition = 0 1077 1082 1078 1083 @property 1079 1084 def id_path_elem(self): 1080 return '%s-%d' % (self._id, self.repetition )1085 return '%s-%d' % (self._id, self.repetition or 0) 1081 1086 1082 1087 @only_if_initialized