def respondToGet(self, transaction): request = transaction.request() response = transaction.response() try: fields = request.fields() print fields['/comment/body#markup'] # force blacklist constraints in case someone tries to post without # using the comment form. if (not "#blacklist#/comment/body" in fields): fields["#blacklist#/comment/body"] = self.weblog.configValue("/blog/blacklist-message") if (not "#blacklist#/comment/url" in fields): fields["#blacklist#/comment/url"] = self.weblog.configValue("/blog/blacklist-message") # We need to force this to only allow the creation of comment entries fields["#required#/comment"] = "This service can only post comments." update = DocumentBuilder(self.weblog, fields) # Which button was clicked on the form post = request.field('post', "") postID = request.field('/comment/@postID', "") errorText = update.getErrorText() if (errorText == ""): content = update.getDocument().serialize() # If the post button was clicked we should save the entry. if (post == "Post"): self.weblog.db.addRecord(None, content) self.sendRedirect(response, self.weblog.configValue("/blog/base-url") + "/" + postID + "?t=item") # Otherwise we should preview it. else: preview = self.weblog.db.runTransform(content, "comment-preview", "") self.sendResponseText(response, preview) return # We treat an error like a preview, but include the error text. else: self.sendErrorText(response, update, errorText, "comment-preview") except NotFoundError: response.setStatus(404, 'Not Found') response.write("The post being commented on could not be located.")
def run(self): print('Processing', self.job.job_id) job_id = str(self.job.job_id) try: os.mkdir(job_id) except: pass summ = Summarizer(self.job) meta = summ.summarize() docBuilder = DocumentBuilder(meta) doc = docBuilder.build() self.saveToBucket(doc) print('Saved:', self.job.job_id) shutil.rmtree(job_id, ignore_errors=True)
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 respondToPost(self, transaction): request = transaction.request() response = transaction.response() entryType = request.field('type', "") fields = request.fields() try: entryDocument = DocumentBuilder(self.weblog, fields) content = entryDocument.serialize() print content # Convert the rest of the form into an XML form spec. formDocument = self._buildFormDocument(fields) errorText = "" try: # If there was a problem building the initial document we just # want to display an error. errorText = entryDocument.getErrorText() if (errorText != ""): raise ProcessingError() # Otherwise we continue processing the document. else: # Add the entry document into the form specification. formDocument.getDocument().addNode("/form/content", entryDocument.getRootElement()) # Hand the form spec to the action processor for this entry # type. content = formDocument.serialize() # print content result = self.weblog.db.runTransform(content, entryType + "/action", "", "admin/action") print result actionResult = XMLFragment(result) # If there were any errors in processing we send an error # to the user. errors = actionResult.xpathEval("/results/error-text") if (len(errors) > 0): for error in errors: errorText = error.content + "<br/>" raise ProcessingError() # Otherwise we figure ou what button was clicked so that we # forward the user to the proper place. else: button = formDocument.xpathEval("/form/button/node()")[0].name #print button style = self.getStyle(request, actionResult, "/results/action/" + button) #print style self.sendResponse(response, entryDocument, style) except ProcessingError, e: # Make sure the document actually has content and then add the # error message to it. try: root = entryDocument.getRootElement() entryDocument.getDocument().addNode("/node()/error-text", errorText, 1) except: entryDocument.getDocument().addNode("/dummy/error-text", errorText, 1) print entryDocument.serialize() style = self.getStyle(request, formDocument, "/form/action/error") self.sendResponse(response, entryDocument, style) except NotFoundError, e: doc = XMLFragment("<error-text>Document not found</error-text>") self.sendResponse(response, doc, "admin/error")