Пример #1
0
    def addChildToNode(self, node, childName, label, app, itemId, level):
        # Need to check whether the childName already exists,
        # Ideally this should be done on the database (and there is a
        # risk that someone else may add the same childName after I've
        # checked). But pgasync currently closes the connection on error
        # and it's not easy to get a sensible error message out of the
        # stored procedure with it erroring.
        curs = self.storeSession.curs

        d = defer.waitForDeferred( hierarchyutil.isUniquePath( curs,
            'sitemap', 'path', node.path, childName ) )
        yield d

        if not d.getResult():
            raise error.NotUniqueError()

        d = curs.callproc('insert_node_under', ('sitemap', node.path, childName, childName, label))
        d.addCallback(lambda ignore: curs.fetchone())
        d = defer.waitForDeferred(d)
        yield d
        nodeId = d.getResult()[0]

        d = curs.execute(
            "update sitemap set level=%(level)s where id=%(id)s",
            {'level': level, 'id': nodeId}
            )
        d.addCallback(lambda ignore: curs.execute(
            "insert into sitemap_item (sitemap_id,item_id,app) values (%s, %s,%s)",
            (nodeId, itemId, app)
            ))
        d = defer.waitForDeferred(d)
        yield d
        d.getResult()
        yield None
Пример #2
0
    def addChildToNode(self, node, textid, label):
        curs = self.sess.curs
        d = defer.waitForDeferred(hierarchyutil.isUniquePath(curs, "categories", "path", node.path, textid))
        yield d

        if not d.getResult():
            raise error.NotUniqueError()
        d = curs.callproc("insert_node_under", ("categories", node.path, textid, textid, label))
        d = defer.waitForDeferred(d)
        yield d
        d.getResult()
        yield None