def insert(self, ctx, id, title, author, category, content): newPost = Post(store=IStore(ctx), id=int(id), author=unicode(author), title=unicode(title), category=unicode(category), content=unicode(content)) IBlog(IStore(ctx)).addNewPost(newPost) inevow.IRequest(ctx).setComponent(iformless.IRedirectAfterPost, '/thx')
def xmlrpc_publish(self, author, title, category, content): newid = IBlog(self.store).getNextId() newPost = Post(store=self.store, id=newid, author=unicode(author), title=unicode(title), category=unicode(category), content=unicode(content)) IBlog(self.store).addNewPost(newPost) return 'Successfully added post number %s' % newid
def eomReceived(self): post = {} isContent = False ctnt_buff = [] recipients = self.lines[0] addrs = [] for recipient in recipients: if '@' not in recipient.orig.addrstr: # Avoid answering to bounches if not recipient.orig.addrstr == '<>': addrs.append(recipient.orig.addrstr[:-1] + '@' + recipient.orig.domain + '>') else: # Avoid answering to bounches if not recipient.orig.addrstr == '<#@[]>': addrs.append(recipient.orig.addrstr) for line in self.lines[1:]: if not isContent: try: field, value = line.split(':', 1) except ValueError: continue if field.lower() != 'content': post[field.lower()] = value.strip() else: isContent = True ctnt_buff.append(value.strip()) else: ctnt_buff.append(line.strip()) post['content'] = '\n'.join(ctnt_buff) for header in 'content author category title'.split(): if not post.has_key(header): self.lines = [] return defer.fail(None) if post.has_key('id'): oldpost = IBlog(self.store).getOne(int(post['id'])) oldpost.author = unicode(post['author']) oldpost.title = unicode(post['title']) oldpost.category = unicode(post['category']) oldpost.content = unicode(post['content']) oldpost.setModified() action = 'modified' id = post['id'] else: newid = IBlog(self.store).getNextId() newPost = Post(store=self.store, id=newid, author=unicode(post['author']), title=unicode(post['title']), category=unicode(post['category']), content=unicode(post['content'])) IBlog(self.store).addNewPost(newPost) action = 'added' id = newid self.lines = [] msg = """From: <%s> Subject: Successfull Post Post number %s successfully %s """ % (FROM, id, action) return self.sendNotify(addrs, msg)