Vyrábíme TNLData podle filtru

This commit is contained in:
Pavel 'LEdoian' Turinsky 2020-04-22 23:46:18 +02:00
parent 6846f20898
commit b57fcc9b25

View file

@ -103,8 +103,30 @@ class TNLData(object):
outitem = cls.from_treenode(ch,out,idx) outitem = cls.from_treenode(ch,out,idx)
out.children.append(outitem) out.children.append(outitem)
return out return out
@classmethod
def filter_treenode(cls, treenode, predicate):
tnll = cls._filter_treenode_recursive(treenode, predicate) # TreeNodeList List :-)
# Teď vyrobíme virtuální TNL, který nemá obsah, ale má za potomky všecny nalezené TNLData
result = cls(None)
for idx, tnl in enumerate(tnll):
result.children.append(tnl)
tnl.parent = result
tnl.index = idx
return result
@classmethod
def _filter_treenode_recursive(cls, treenode, predicate):
if predicate(treenode):
return [cls.from_treenode(treenode)]
else:
found = []
for tn in all_children(treenode):
result = cls.filter_treenode(tn, predicate)
# Result by v tuhle chvíli měl být seznam TNLDat odpovídající treenodům, jež matchnuly predikát.
for tnl in result:
found.append(tnl)
return found
class TreeNodeView(generic.DetailView): class TreeNodeView(generic.DetailView):
model = s.TreeNode model = s.TreeNode