示例#1
0
    def new(self, action, post_id=None):

        try:
            post_id = int(post_id)
        except:
            abort(400)
            
        post_q = meta.Session.query(model.Post)
        c.post = post_id and post_q.filter_by(id=int(post_id)).first() or None
        if c.post is None:
            abort(404)
        return h.comment_form('/derived/comment/new.html')
示例#2
0
文件: post.py 项目: leveille/blog.v1
    def view(self, year, month, slug):        
        @app_globals.cache.region('short_term', 'post.view.load_post')
        def load_post(year, month, slug):
            import calendar
            return meta.Session.query(model.Post).filter(
                and_(model.Post.posted_on >= d.datetime(year, month, 1), 
                     model.Post.posted_on <= d.datetime(year, month, calendar.monthrange(year, month)[1]),
                     model.Post.draft == False,
                     model.Post.slug == slug)
            ).first()

        try:
            c.post = load_post(int(year), int(month), slug)
        except:
            abort(400)
                                 
        if c.post is None:
            abort(404)
            
        return h.comment_form('/derived/post/view.html')