TreeLib | přepsaný is_orphan
This commit is contained in:
parent
548852c83c
commit
b43a9d142b
1 changed files with 15 additions and 7 deletions
|
@ -13,13 +13,6 @@ def print_tree(node,indent=0):
|
|||
if node.succ:
|
||||
print_tree(node.succ, indent=indent)
|
||||
|
||||
def is_orphan(node):
|
||||
""" Zjišťuje, jestli už je daný Node někde pověšený či nikoli. """
|
||||
if safe_father_of_first(node) is None and safe_pred(node) is None:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
# Django je trošku hloupé, takže node.prev nevrací None, ale hází django.core.exceptions.ObjectDoesNotExist
|
||||
def safe_pred(node):
|
||||
try:
|
||||
|
@ -63,6 +56,21 @@ def get_last_child(node):
|
|||
else:
|
||||
return last_brother(first)
|
||||
|
||||
def is_orphan(node):
|
||||
""" Zjišťuje, jestli už je daný Node někde pověšený či nikoli. """
|
||||
# None jsem se rozhodl, že sirotek není
|
||||
if node is None:
|
||||
return False
|
||||
if get_parent(node) is None:
|
||||
if node.succ is not None or safe_pred(node) is not None or safe_father_of_first(node) is not None or node.root is not None:
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
# Error = pošle mail :-)
|
||||
logger.error(f"Node-sirotek s id {node.id} má rodinné vztahy (Node: {node})")
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
# Obecný next: další Node v "the-right-order" pořadí (já, pak potomci, pak sousedé)
|
||||
def general_next(node):
|
||||
# Máme potomka?
|
||||
|
|
Loading…
Reference in a new issue