1. Sylvain Hellegouarch
  2. CherryPy Recipes

Source

CherryPy Recipes / testing / load / myapp / blog.py

# -*- coding: utf-8 -*-
import cherrypy

from model import Post, Comment

__all__ = ['Blog']

class Blog(object):
    def __init__(self):
        self.post = BlogPost()
        
    @cherrypy.expose
    @cherrypy.tools.template(template='index.html')
    def index(self):
        session = cherrypy.request.db
        posts = Post.all_(session)
        return {'posts': posts}

class BlogPost(object):
    @cherrypy.expose
    def default(self, id):
        session = cherrypy.request.db
        post = Post.get_by_id(session, int(id))
        
    @cherrypy.expose
    def comment(self, id, author, text):
        session = cherrypy.request.db
        post = Post.get_by_id(session, int(id))
        post.comments.append(Comment(author=author, text=text))