def set_parent(self, p=None, i=None):
        """
            Set a parent for this item, base method for tree construction

            @param p: the parent
            @param i: the list index where to insert the item
        """

        if p is None:
            p = self.parent
        if p is None:
            return
        parent = self.parent
        if parent is not None and parent !=p:
            while self in parent.components:
                parent.components.remove(self)
        if i is not None:
            p.component.insert(i, self)
        else:
            p.components.append(self)
        self.parent = p
        return

    # -------------------------------------------------------------------------
dataset/ETHPy150Open sahana/eden/modules/s3/s3navigation.py/S3NavigationItem.set_parent/original