Ejemplo n.º 1
0
    def getItem(self, ctx, sysConfig, baseURL, id, index):
        try:
            db = self._getDatabase(sysConfig)

            if not isinstance(id, str):
                node = libxml2.xmlNode(_obj=id[0])
                id = node.content

            if id != "":
                if index == 0:
                    content = db.xpathQuery(None, "/item[@id > " + str(id) + "]")
                else:
                    content = db.xpathQuery(None, "/item[@id < " + str(id) + "]")
                ids = libxml2.parseDoc(content).xpathEval("/results/item/@id")

                idList = []
                for id in ids:
                    idList.append(int(id.content))

                if len(ids) > 0:
                    idList.sort()

                    previousID = idList[index]

                    previous = XMLFragment(db.getRecord(None, previousID))
                    title = previous.getValue("/item/title")

                    return self.itemLink(ctx, baseURL, title, previousID)
                else:
                    return ""
            else:
                return ""
        except Exception, err:
            db.log.exception("DbXslExtension: Error getting previous item")
Ejemplo n.º 2
0
 def testDeleteRecord(self):
     # Add an entry and the remove it
     id = self.db.addRecord(None, testEntry)    
     
     self.db.deleteRecord(None, id)
     
     # We shouldn't be able to find it now.
     self.assertRaises(BaseDatabase.NotFoundError, self.db.getRecord, None, id)
     
     # Test deleteing a non-existent entry
     self.assertRaises(BaseDatabase.NotFoundError, self.db.deleteRecord, None, -1)
     
     # Test cascading deletes.
     # add an item entry
     id = self.db.addRecord(None, "<item/>")  
     
     # add two comments that reference the item
     comment1 = self.db.addRecord(None, "<comment postID='" + str(id) + "'/>")    
     comment2 = self.db.addRecord(None, "<comment postID='" + str(id) + "'/>")    
     print "comment 1 " + str(comment1)
     print "comment 2 " + str(comment2)
     # Check to see if comment-count = 2 on the item entry tests increment
     # triggers
     entry = XMLFragment(self.db.getRecord(None, id))
     
     self.assertEqual(entry.getValue("/item/comment-count"), "2")
     
     # Add another comment and then remove it again to check proper counting
     comment3 = self.db.addRecord(None, "<comment postID='" + str(id) + "'/>")
     
     entry = XMLFragment(self.db.getRecord(None, id))
     # count should now be three
     self.assertEqual(entry.getValue("/item/comment-count"), "3") 
     # remove the comment and the count should drop back to two
     self.db.deleteRecord(None, comment3)
     entry = XMLFragment(self.db.getRecord(None, id))
     self.assertEqual(entry.getValue("/item/comment-count"), "2")
     
     # Deleting the item should also delete the comments.
     self.db.deleteRecord(None, id)
    
     self.assertRaises(BaseDatabase.NotFoundError, self.db.getRecord, None, id)
     self.assertRaises(BaseDatabase.NotFoundError, self.db.getRecord, None, comment1)
     self.assertRaises(BaseDatabase.NotFoundError, self.db.getRecord, None, comment2)