(user, source, target)
return False
Return True if moving post from one to another is valid.
Return True if moving post from one to another is valid.
Return True if moving post from one to another is valid .
def validate_move(user, source, target):
    """
    Return True if moving post from one to another is valid.
    """

    if not source or not target:
        return False

    # cond 1: user is a moderator or author
    valid_user = user.profile.is_moderator or source.author == user

    # cond 2: source and target share the same root
    same_root = source.root.uid == target.root.uid

    # cond 3: source and target are different posts
    is_diff = source.uid != target.uid

    # cond 4: target is not a descendant of source.
    children = set()
    try:
        walk_down_thread(parent=source, collect=children)
        not_desc = (target not in children)
    except Exception as exc:
        logger.error(exc)
        not_desc = False

    # cond 5: source is not top level
    not_toplevel = not source.is_toplevel

    # All conditions need to be met for valid move.
    valid = same_root and is_diff and not_desc and not_toplevel and valid_user

    # Conditions needed to be classified as
    if valid:
        return True

    return False
def validate_move ( user , source , target ) : if not source or not target : return False # cond 1: user is a moderator or author valid_user = user . profile . is_moderator or source . author == user # cond 2: source and target share the same root same_root = source . root . uid == target . root . uid # cond 3: source and target are different posts is_diff = source . uid != target . uid # cond 4: target is not a descendant of source. children = set ( ) try : walk_down_thread ( parent = source , collect = children ) not_desc = ( target not in children ) except Exception as exc : logger . error ( exc ) not_desc = False # cond 5: source is not top level not_toplevel = not source . is_toplevel # All conditions need to be met for valid move. valid = same_root and is_diff and not_desc and not_toplevel and valid_user # Conditions needed to be classified as if valid : return True return False