Merge branch 'data_migrations' of gimli.ms.mff.cuni.cz:/akce/mam/git/mamweb into data_migrations
This commit is contained in:
commit
1cec286697
1 changed files with 46 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
|||
from django.core.exceptions import ObjectDoesNotExist
|
||||
# NOTE: node.prev a node.succ jsou implementovány přímo v models.TreeNode
|
||||
# TODO: Všechny tyto funkce se naivně spoléhají na to, že jako parametr dostanou nějaký TreeNode (některé možná zvládnou i None)
|
||||
# TODO: Chceme, aby všechno nějak zvládlo None jako parametr.
|
||||
|
||||
# Slouží k debugování pro rychlé získání představy o podobě podstromu pod tímto TreeNode.
|
||||
def print_tree(node,indent=0):
|
||||
|
@ -106,6 +107,12 @@ def all_children(node):
|
|||
yield br
|
||||
|
||||
# Generátor následníků v "the-right-order"
|
||||
# Bez tohoto vrcholu
|
||||
def all_following(node):
|
||||
current = general_next(node)
|
||||
while current is not None:
|
||||
yield current
|
||||
current = general_next(current)
|
||||
|
||||
## Filtrační hledání
|
||||
# Najdi dalšího bratra nějakého typu, nebo None.
|
||||
|
@ -114,26 +121,57 @@ def get_next_brother_of_type(node, type):
|
|||
for current in right_brothers(node):
|
||||
if isinstance(current, type):
|
||||
return current
|
||||
return None
|
||||
|
||||
def get_prev_brother_of_type(node, type):
|
||||
pass
|
||||
# Na tohle není rozumný generátor, ani ho asi nechceme, prostě to implementujeme cyklem.
|
||||
current = node
|
||||
while safe_pred(current) is not None:
|
||||
current = safe_pred(current)
|
||||
if isinstance(current, type):
|
||||
return current
|
||||
return None
|
||||
|
||||
# Totéž pro "the-right-order" pořadí
|
||||
def get_next_node_of_type(current, type):
|
||||
pass
|
||||
def get_next_node_of_type(current, type):
|
||||
pass
|
||||
def get_next_node_of_type(node, type):
|
||||
for cur in all_folowing(node):
|
||||
if isinstance(cur, type):
|
||||
return cur
|
||||
return None
|
||||
|
||||
def get_prev_node_of_type(node, type):
|
||||
# Na tohle není rozumný generátor, ani ho asi nechceme, prostě to implementujeme cyklem.
|
||||
current = node
|
||||
while general_prev(current) is not None:
|
||||
current = general_prev(current)
|
||||
if isinstance(current, type):
|
||||
return current
|
||||
return None
|
||||
|
||||
|
||||
|
||||
|
||||
# Editace stromu:
|
||||
def create_node_after(predecessor, type, **kwargs):
|
||||
pass
|
||||
new_node = type.objects.create(**kwargs)
|
||||
new_node.save()
|
||||
succ = predecessor.succ
|
||||
predecessor.succ = new_node
|
||||
predecessor.save()
|
||||
new_node.succ = succ
|
||||
new_node.save()
|
||||
|
||||
# Vyrábí prvního syna, ostatní nalepí za (existují-li)
|
||||
def create_child(parent, type, **kwargs):
|
||||
pass
|
||||
new_node = type.objects.create(**kwargs)
|
||||
new_node.save()
|
||||
orig_child = parent.first_child
|
||||
parent.first_child = new_node
|
||||
parent.save()
|
||||
if orig_child is not None:
|
||||
# Přidáme původního prvního syna jako potomka nového vrcholu
|
||||
new_node.succ = orig_child
|
||||
new_node.save()
|
||||
|
||||
def create_node_before(some, arguments, but, i, dont, know, which, yet):
|
||||
pass
|
||||
|
@ -141,7 +179,7 @@ def create_node_before(some, arguments, but, i, dont, know, which, yet):
|
|||
|
||||
# ValueError, pokud je (aspoň) jeden parametr None
|
||||
def swap(node, other):
|
||||
pass
|
||||
raise NotImplementedError("YAGNI (You aren't gonna need it).")
|
||||
|
||||
def swap_pred(node):
|
||||
pass
|
||||
|
|
Loading…
Reference in a new issue