예제 #1
0
파일: models.py 프로젝트: Mark-Jordan/blog
    def content_html(self):
        """直接渲染模板"""
        from main.models import Post  # 避免循环引用
        from comment.models import Comment

        result=''
        show_items_num=5
        if self.display_type==self.DISPLAY_HTML:
            result=self.content
        elif self.display_type==self.DISPLAY_LATEST:
            context={
                'posts':Post.latest_posts()[:show_items_num]
            }
            tes=render_to_string('config/blocks/sidebar_posts.html',context=context)
            result=render_to_string('config/blocks/sidebar_posts.html',context=context)
        elif self.display_type==self.DISPLAY_HOT:
            context={
                'posts': Post.hot_posts()[:show_items_num],
            }
            result=render_to_string('config/blocks/sidebar_posts.html',context=context)
        elif self.display_type==self.DISPLAY_COMMENT:
            context={
                'comments': Comment.objects.filter(status=Comment.STATUS_NORMAL)[:show_items_num]
            }
            result=render_to_string('config/blocks/sidebar_comments.html',context=context)

        return result
예제 #2
0
    def content_html(self):
        """直接渲染模板"""
        from main.models import Post
        from comment.models import Comment
        from django.template.loader import render_to_string

        result = ''
        if self.display_type == self.DISPLAY_HTML:
            result = self.content
        elif self.display_type == self.DISPLAY_LATEST:
            context = {'posts': Post.latest_posts()}
            result = render_to_string('config/blocks/siderbar_posts.html',
                                      context)
        elif self.display_type == self.DISPLAY_HOT:
            context = {'posts': Post.hot_post()}
            result = render_to_string('config/blocks/siderbar_posts.html',
                                      context)
        elif self.display_type == self.DISPLAY_COMMENT:
            context = {
                'comments': Comment.objects.filter(
                    status=Comment.STATUS_NORMAL)  #此处为什么是用Comment类来调用??
            }
            result = render_to_string('config/blocks/siderbar_comments.html',
                                      context)
        return result