def respondToPost(self, transaction): request = transaction.request() response = transaction.response() # The post the trackback applies to. postID = request.extraURLPath().split('/')[1] try: spec = { '/trackback/@postID': postID, '/trackback/title': request.field('title', ""), '/trackback/url': request.field('url', ""), '#required#/trackback/url': 'The URL for the linking entry is required', '#blacklist#/trackback/url': self.weblog.configValue("/blog/blacklist-message"), '/trackback/excerpt': request.field('excerpt', ""), '#blacklist#/trackback/excerpt': self.weblog.configValue("/blog/blacklist-message"), '/trackback/blog_name': request.field('blog_name', "") } update = DocumentBuilder(self.weblog, spec) errorText = update.getErrorText() if (errorText == ""): content = update.getDocument().serialize() self.weblog.db.addRecord(None, content) doc = XMLFragment() doc.addNode("/response/error", "0") self.sendResponseText(response, doc.serialize()) else: doc = XMLFragment() doc.addNode("/response/error", "1") doc.addNode("/response/message", errorText) self.sendResponseText(response, doc.serialize()) except NotFoundError: response.setStatus(404, 'Not Found') response.write("The post being commented on could not be located.")
def updateRecord(self, txn, recordID, record): if (record == None): raise ParseError try: fileName = self.dbPath + str(recordID) + ".xml" if (not os.path.exists(fileName)): raise NotFoundError # Make sure the ID is set on the new content doc = XMLFragment(record) root = doc.getRootElement() root.setProp("id", str(recordID)) # Update the document file = open(fileName, "w") file.write(doc.serialize()) file.close() self._applyTriggers(txn, "update", doc) except libxml2.parserError, e: raise ParseError(e)