55 def iterchildren(self, _done=None): |
55 def iterchildren(self, _done=None): |
56 if _done is None: |
56 if _done is None: |
57 _done = set() |
57 _done = set() |
58 for child in self.children(): |
58 for child in self.children(): |
59 if child.eid in _done: |
59 if child.eid in _done: |
60 self.error('loop in %s tree', self.id.lower()) |
60 self.error('loop in %s tree', self.__regid__.lower()) |
61 continue |
61 continue |
62 yield child |
62 yield child |
63 _done.add(child.eid) |
63 _done.add(child.eid) |
64 |
64 |
65 def prefixiter(self, _done=None): |
65 def prefixiter(self, _done=None): |
81 """returns the list of eids from the root object to this object""" |
81 """returns the list of eids from the root object to this object""" |
82 path = [] |
82 path = [] |
83 parent = self |
83 parent = self |
84 while parent: |
84 while parent: |
85 if parent.eid in path: |
85 if parent.eid in path: |
86 self.error('loop in %s tree', self.id.lower()) |
86 self.error('loop in %s tree', self.__regid__.lower()) |
87 break |
87 break |
88 path.append(parent.eid) |
88 path.append(parent.eid) |
89 try: |
89 try: |
90 # check we are not leaving the tree |
90 # check we are not leaving the tree |
91 if (parent.tree_attribute != self.tree_attribute or |
91 if (parent.tree_attribute != self.tree_attribute or |
218 return done, entity |
218 return done, entity |
219 |
219 |
220 |
220 |
221 class TreeViewMixIn(object): |
221 class TreeViewMixIn(object): |
222 """a recursive tree view""" |
222 """a recursive tree view""" |
223 id = 'tree' |
223 __regid__ = 'tree' |
224 item_vid = 'treeitem' |
224 item_vid = 'treeitem' |
225 __select__ = implements(ITree) |
225 __select__ = implements(ITree) |
226 |
226 |
227 def call(self, done=None, **kwargs): |
227 def call(self, done=None, **kwargs): |
228 if done is None: |
228 if done is None: |
236 self.w(u'<li class="badcontent">%s</li>' % entity) |
236 self.w(u'<li class="badcontent">%s</li>' % entity) |
237 return |
237 return |
238 self.open_item(entity) |
238 self.open_item(entity) |
239 entity.view(vid or self.item_vid, w=self.w, **kwargs) |
239 entity.view(vid or self.item_vid, w=self.w, **kwargs) |
240 relatedrset = entity.children(entities=False) |
240 relatedrset = entity.children(entities=False) |
241 self.wview(self.id, relatedrset, 'null', done=done, **kwargs) |
241 self.wview(self.__regid__, relatedrset, 'null', done=done, **kwargs) |
242 self.close_item(entity) |
242 self.close_item(entity) |
243 |
243 |
244 def open_item(self, entity): |
244 def open_item(self, entity): |
245 self.w(u'<li class="%s">\n' % entity.id.lower()) |
245 self.w(u'<li class="%s">\n' % entity.__regid__.lower()) |
246 def close_item(self, entity): |
246 def close_item(self, entity): |
247 self.w(u'</li>\n') |
247 self.w(u'</li>\n') |
248 |
248 |
249 |
249 |
250 class TreePathMixIn(object): |
250 class TreePathMixIn(object): |
264 # entity is actually an error message |
264 # entity is actually an error message |
265 self.w(u'<span class="badcontent">%s</span>' % entity) |
265 self.w(u'<span class="badcontent">%s</span>' % entity) |
266 return |
266 return |
267 parent = entity.parent() |
267 parent = entity.parent() |
268 if parent: |
268 if parent: |
269 parent.view(self.id, w=self.w, done=done) |
269 parent.view(self.__regid__, w=self.w, done=done) |
270 self.w(self.separator) |
270 self.w(self.separator) |
271 entity.view(vid or self.item_vid, w=self.w) |
271 entity.view(vid or self.item_vid, w=self.w) |
272 |
272 |
273 |
273 |
274 class ProgressMixIn(object): |
274 class ProgressMixIn(object): |