Browse Source

Vyrábíme TNLData podle filtru

export_seznamu_prednasek
Pavel 'LEdoian' Turinsky 5 years ago
parent
commit
b57fcc9b25
  1. 22
      seminar/views/views_all.py

22
seminar/views/views_all.py

@ -104,7 +104,29 @@ class TNLData(object):
out.children.append(outitem)
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):
model = s.TreeNode

Loading…
Cancel
Save