Beispiel #1
0
 def test_get_all(self):
     Comment(id=5, author=self.user, post=self.post,
             content='New Comment').save()
     new_comment = Comment.objects.get(id=5)
     expected_comments = [self.comment, new_comment]
     comments = Comment.get_all(self.post)
     self.assertEqual(list(comments), expected_comments)
Beispiel #2
0
 def get(self, request, post_id=None):
     if post_id:
         post = Post.get_by_id(post_id)
         comments = Comment.get_all(post)
         if not post:
             return RESPONSE_404_OBJECT_NOT_FOUND
         return render(request, 'post/index.html', {
             'post': post,
             'comments': comments
         })
Beispiel #3
0
    def get_sidebar_content_html(self):
        """”
            直接渲染模板;
            将导入语句写入函数中防止循环引用,因为bog和comment app的models中将来也有可能引用config app的models
        """
        from blog.models import Post
        from comment.models import Comment

        result = ''
        if self.display_type == self.DISPLAY_HTML:
            result = self.content
        elif self.display_type == self.DISPLAY_LATEST:
            context = {"posts": Post.get_lastest_post()}
            result = render_to_string("config/blocks/sidebar_posts.html",
                                      context=context)
        elif self.display_type == self.DISPLAY_HOT:
            context = {"posts": Post.get_hot_posts().only("id", "title")}
            result = render_to_string("config/blocks/sidebar_posts.html",
                                      context=context)
        elif self.display_type == self.DISPLAY_COMMENT:
            context = {"comments": Comment.get_all()}
            result = render_to_string("config/blocks/sidebar_comments.html",
                                      context=context)
        return result
def get_all():
  comments = Comment.get_all()
  data = comment_schema.dump(comments, many=True).data
  return custom_response(data, 200)