|
@ -10,23 +10,26 @@ def print_tree(node,indent=0): |
|
|
if node.succ: |
|
|
if node.succ: |
|
|
print_tree(node.succ, indent=indent) |
|
|
print_tree(node.succ, indent=indent) |
|
|
|
|
|
|
|
|
|
|
|
# Django je trošku hloupé, takže node.prev nevrací None, ale hází django.core.exceptions.ObjectDoesNotExist |
|
|
|
|
|
def safe_pred(node): |
|
|
|
|
|
try: |
|
|
|
|
|
return node.prev |
|
|
|
|
|
except ObjectDoesNotExist: |
|
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
# A to samé pro .father_of_first |
|
|
|
|
|
def safe_father_of_first(node): |
|
|
|
|
|
return node.prev |
|
|
|
|
|
except ObjectDoesNotExist: |
|
|
|
|
|
return None |
|
|
|
|
|
|
|
|
## Rodinné vztahy |
|
|
## Rodinné vztahy |
|
|
def get_parent(node): |
|
|
def get_parent(node): |
|
|
pass |
|
|
|
|
|
# Nejdřív získáme prvního potomka... |
|
|
# Nejdřív získáme prvního potomka... |
|
|
# Django je trošku hloupé, takže node.prev nevrací None, ale hází django.core.exceptions.ObjectDoesNotExist |
|
|
while safe_pred(node) is not None: |
|
|
while True: |
|
|
node = safe_pred(node) |
|
|
try: |
|
|
|
|
|
node = node.prev |
|
|
|
|
|
except ObjectDoesNotExist: |
|
|
|
|
|
# We rely here on the fact that the assignment will not happen if RHS throws an exception |
|
|
|
|
|
break |
|
|
|
|
|
# ... a z prvního potomka umíme najít rodiče |
|
|
# ... a z prvního potomka umíme najít rodiče |
|
|
# Django je pořád hloupé... |
|
|
return safe_father_of_first(node) |
|
|
try: |
|
|
|
|
|
return node.father_of_first |
|
|
|
|
|
except ObjectDoesNotExist: |
|
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
# Obecný next: další Node v "the-right-order" pořadí (já, pak potomci, pak sousedé) |
|
|
# Obecný next: další Node v "the-right-order" pořadí (já, pak potomci, pak sousedé) |
|
|
def general_next(node): |
|
|
def general_next(node): |
|
|