Exemple #1
0
def comment_like(request):
    try:
        requestUser = get_user(request)
        commentId = request.POST.get('commentId', '')
        commentType = request.POST.get('commentType', '')
        if commentType == '1':
            comment = LightBlogComment.objects.get(id=commentId)
            like_all = comment.comment_like.all()
            is_like = requestUser in like_all
            if is_like:
                comment.comment_like.remove(requestUser)
                return HttpResponse(json.dumps({"success": True, "like_count": comment.comment_like.count()}))
            else:
                comment.comment_like.add(requestUser)
                return HttpResponse(json.dumps({"success": True, "like_count": comment.comment_like.count()}))
        else:
            comment = LightBlogComment_reply.objects.get(id=commentId)
            like_all = comment.comment_like.all()
            is_like = requestUser in like_all
            if is_like:
                comment.comment_like.remove(requestUser)
                return HttpResponse(json.dumps({"success": True, "like_count": comment.comment_like.count()}))
            else:
                comment.comment_like.add(requestUser)
                return HttpResponse(json.dumps({"success": True, "like_count": comment.comment_like.count()}))
    except Exception as e:
        return HttpResponse(json.dumps({"success": False, "tips": str(e)}))
Exemple #2
0
def comment_repy_more(request):
    try:
        commentId = request.POST.get('commentId', '')
        comment = LightBlogComment.objects.get(id=commentId)
        comment_reply_all = comment.lightblogcomment_reply.all()[2:]
        user = get_user(request)
        list_data = []
        for item in comment_reply_all:
            if item.reply_type == 0:
                list_data.append({'from': item.comment_user.username,'from_img_url':item.comment_user.userinfo.photo_150x150.url, 'to':comment.commentator.username , 'id': item.id, 'comment_text': comment_text(item),
                                'created': time.mktime(item.created.timetuple()),
                                  'comment_like': item.comment_like.count(),
                                  'is_liked': is_reply_liked(user, item),
                                  'is_deleted': item.is_deleted
                                  })
            else:
                list_data.append(
                    {'from': item.comment_user.username,'from_img_url':item.comment_user.userinfo.photo_150x150.url, 'to': item.commented_user.username,'id': item.id, 'comment_text': comment_text(item),
                     'created': time.mktime(item.created.timetuple()),
                     'comment_like': item.comment_like.count(),
                     'is_liked': is_reply_liked(user, item),
                     'is_deleted': item.is_deleted
                     })
        return HttpResponse(json.dumps({'success': True, "data": list_data}))
    except Exception as e:
        return HttpResponse(json.dumps({"success": False, "tips": str(e)}))
Exemple #3
0
def comment_del(request):
    try:
        commentId = request.POST.get('commentId', '')
        commentType = request.POST.get('commentType', '') # 1为主评论, 2为子评论
        requestUser = get_user(request)
        if commentType == '1':
            comment = LightBlogComment.objects.get(id=commentId)
            if requestUser != comment.commentator and requestUser.is_superuser is False:
                return HttpResponse(json.dumps({"success": False, "tips": "您没有权限删除"}))
        else:
            comment = LightBlogComment_reply.objects.get(id=commentId)
            if requestUser != comment.comment_user and requestUser.is_superuser is False:
                return HttpResponse(json.dumps({"success": False, "tips": "您没有权限删除"}))
        comment.is_deleted = True
        comment.save()
        return HttpResponse(json.dumps({"success": True, "tips": "该评论已被删除"}))
    except Exception as e:
        return HttpResponse(json.dumps({"success": False, "tips": str(e)}))
Exemple #4
0
def comment_reply_post(request):
    try:
        commentType = request.POST.get('commentType', '')
        commentId = request.POST.get('commentId', '')
        comment_text = request.POST.get('commentText', '')
        user = get_user(request)
        if commentType == '1':
            comment = LightBlogComment.objects.get(id=commentId)
            if user == comment.commentator:
                return HttpResponse(json.dumps({'success': False, 'tips': '您不能对自己的评论进行评论'}))
            new_comment = LightBlogComment_reply(comment_reply=comment,comment_user=user,commented_user=comment.commentator,comment_text=comment_text)
            new_comment.save()
            comment_info = {
                "from": user.username,
                "from_img_url": user.userinfo.photo_150x150.url,
                "to": comment.commentator.username,
                "id": new_comment.id,
                "comment_text": new_comment.comment_text,
                "created": time.mktime(new_comment.created.timetuple()),
                "comment_like": 0,
                "is_like": False,
                "is_deleted": False
            }
            return HttpResponse(json.dumps({"success": True, "data": comment_info}))
        else:
            comment_reply = LightBlogComment_reply.objects.get(id=commentId)
            if user == comment_reply.comment_user:
                return HttpResponse(json.dumps({'success': False, 'tips': '您不能对自己的评论进行评论'}))
            new_comment = LightBlogComment_reply(comment_reply=comment_reply.comment_reply,reply_type=1,comment_user=user,commented_user=comment_reply.comment_user,comment_text=comment_text,reply_comment=commentId)
            new_comment.save()
            comment_info = {
                "from": user.username,
                "from_img_url": user.userinfo.photo_150x150.url,
                "to": comment_reply.comment_user.username,
                "id": new_comment.id,
                "comment_text": new_comment.comment_text,
                "created": time.mktime(new_comment.created.timetuple()),
                "comment_like": 0,
                "is_like": False,
                "is_deleted": False
            }
            return HttpResponse(json.dumps({"success": True, "data": comment_info}))
    except Exception as e:
        return HttpResponse(json.dumps({"success": False, "tips": str(e)}))
Exemple #5
0
def comment_report(request):
    try:
        type = request.POST.get('type', '')
        id = request.POST.get('commentId', '')
        reportId = request.POST.get('reportId', '')
        reportText = request.POST.get('reportText', '')
        LightBlogComment_report.objects.create(reply_type=type,commentId=id,report_type=LightBlog_report.objects.get(id=reportId),reported_text=reportText,report_user=get_user(request))
        return HttpResponse(json.dumps({"success": True, "tips": "OK"}))
    except Exception as e:
        return HttpResponse(json.dumps({"success": False, "tips": str(e)}))