def childFactory(self, ctx, segment): id = segment.isdigit() and segment or '-1' if int(id) >= 0: return IBlog(IStore(ctx)).getOne(int(id)) elif segment == 'rpc2': return BlogRPC(IStore(ctx)) elif segment == 'atom.xml': return Atom()
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 data_getEntries(self, ctx, data): num = ctx.arg('num', '60') return IBlog(IStore(ctx)).getPosts(int(num))
def locateChild(self, ctx, segments): return IStore(ctx).transact(rend.Page.locateChild, self, ctx, segments)
def renderHTTP(self, ctx): return IStore(ctx).transact(rend.Page.renderHTTP, self, ctx)
def data_get_posts(self, ctx, data): return IBlog(IStore(ctx)).getPosts(15)
def data_getFirstPost(self, ctx, data): for post in IBlog(IStore(ctx)).getPosts(1): return post
def render_forms(self, ctx, data): d = iformless.IFormDefaults(ctx).getAllDefaults('insert') d['author'] = 'Anonymous' d['id'] = IBlog(IStore(ctx)).getNextId() return webform.renderForms()