Esempio n. 1
0
    def moveNode(self, userID, nodeID, newParentID, newIndex=None):
        """move a node to newParent, at newIndex"""
        user = self.checkUser(userID)
        node = self.checkNode(user, nodeID)
        parent = self.checkNode(user, newParentID)
        assert isinstance(parent, models.Section), "parent must be Section"

        nb = node.notebook
        isroot = nb.root is node
        if not isroot:  # have parent, update head/tail links
            if node.parent.head is node:
                node.parent.head = node.next
            if node.parent.tail is node:
                node.parent.tail = node.previous
            self.session.flush()
            # self.session.refresh(node.parent)
        # update next/previous links
        p = node.previous
        n = node.next
        if p is not None:
            p.next = None
            self.session.flush()
            p.next = n
        elif n is not None:
            n.previous = None
        node.next = node.previous = None
        self.session.flush()
        n = self.addNode(userID, newParentID, node, newIndex)
        self.session.refresh(nb)
        if isroot:  # check this
            dbutil.dropObject(self.session, nb)
        return n
Esempio n. 2
0
 def dropNotebook(self, userID, nbID):
     user = self.checkUser(userID)
     nb = self.checkNotebook(user, nbID)
     dbutil.dropObject(self.session, nb)
Esempio n. 3
0
 def dropNode(self, userID, nodeID):
     user = self.checkUser(userID)
     node = self.checkNode(user, nodeID)
     dbutil.dropObject(self.session, node)
Esempio n. 4
0
 def dropUser(self, userID):
     assert userID not in self.users, "You cannot drop an active user!"
     user = self.userQuery.selectone_by(userID=userID)
     dbutil.dropObject(self.session, user)