Example #1
0
 def post(self, request):
     user_id = request.user.id
     article_code = request.data.get("article_code")
     content = request.data.get("content")
     comment_code, article_id = ArticleComment.add_article_comment_by_code(
         user_id=user_id, article_code=article_code, content=content)
     article_comment_add.delay(article_id=article_id)
     return Response(data={"created": comment_code})
Example #2
0
    def delete(self, request):
        user_id = request.user.id
        comment_code = request.GET.get("comment_code")

        deleted_number, article_id = ArticleComment.delete_comment_by_code(
            user_id=user_id, comment_code=comment_code)
        article_comment_reduce.delay(article_id=article_id,
                                     number=deleted_number)
        return Response(data={"deleted": deleted_number})
Example #3
0
def get_article_comments(request):
    article_code = request.GET.get("article_code")
    page = request.GET.get("page")
    page_sum, page, one_page_max, article_comment_set, reply_dict = ArticleComment.get_article_comment_by_code(
        article_code=article_code,
        page=page,
        max_size=article_constant.ARTICLE_COMMENT_PAGE_SIZE_MAX)
    article_comment_ser = []
    if page_sum > 0:
        article_comment_ser = ArticleCommentItemsSerializers(
            article_comment_set, many=True, content=reply_dict).data
    data = {
        "items": article_comment_ser,
        "page_sum": page_sum,
        "page": page,
        "one_page_max": one_page_max
    }
    return Response(data=data)
Example #4
0
def add_comment(request):
    if request.method == 'POST':
        # 获取post数据
        article_id = request.POST.get('article_id')
        comment = request.POST.get('comment')
        commentator_id = request.POST.get('commentator_id')
        # 创建外键实例
        user_ins = User.objects.get(id=commentator_id)
        article_ins = Article.objects.get(id=article_id)
        # 保存数据
        article_comment = ArticleComment(content=comment)
        article_comment.commentator = user_ins
        article_comment.article = article_ins
        article_comment.save()
        return JsonResponse({'code':200})
    else:
        return JsonResponse({'errmsg':'提交评论失败'})
Example #5
0
 def get_comment(self, comment_id):
     comment = ArticleComment.get_and_confirm_article(self, comment_id)
     if not comment.is_usable():
         raise CommentNotExsit
     return comment
Example #6
0
 def delete_comment(self, user, comment_id):
     ArticleComment.delete_comment(self, user, comment_id)
     Article.objects(id=str(self.id)).update_one(dec__comments_count=1)
Example #7
0
 def get_comments(self, count, read_tag):
     return ArticleComment.get_usable_comments(self, count, read_tag)
Example #8
0
 def add_comment(self, user, content):
     comment = ArticleComment.create(self, user, content)
     Article.objects(id=str(self.id)).update_one(inc__comments_count=1)
     return comment
Example #9
0
 def get_base_comments(self):
     return ArticleComment.get_usable_comments(self, 10)