def post(self, request, *args, **kwargs): if not request.user.is_authenticated: return JsonResponse({ "status":"fail", "msg": "用户未登录" }) add_comment = CommentForm(request.POST) if add_comment.is_valid(): comments = add_comment.cleaned_data["comments"] course_id = add_comment.cleaned_data["course"] com = CourseComments() com.course_id = course_id com.comments =comments com.user_id = request.user.id com.add_time = datetime.now() com.save() return JsonResponse( {"status": "success", "msg": "评论成功"} ) else: return JsonResponse( {"status": "fail", "msg": "评论不符合规则"} )
def post(self, request, *args, **kwargs): """ 用户收藏,取消收藏 """ if not request.user.is_authenticated: return JsonResponse({ "status":"fail", "msg":"用户未登录" }) comment_form = CommentsForm(request.POST) if comment_form.is_valid(): course = comment_form.cleaned_data["course"] comments = comment_form.cleaned_data["comments"] comment = CourseComments() comment.user = request.user comment.comments = comments comment.course = course comment.save() return JsonResponse({ "status": "success", }) else: return JsonResponse({ "status": "fail", "msg": "参数错误" })
def post(self, request, *args, **kwargs): if not request.user.is_authenticated: return JsonResponse({ 'status': 'fail', 'msg': '用户未登录', }) comment_form = CommentForm(request.POST) if comment_form.is_valid(): course = comment_form.cleaned_data['course'] comments = comment_form.cleaned_data['comments'] comment = CourseComments() comment.user = request.user comment.comments = comments comment.course = course comment.save() return JsonResponse({ 'status': 'success', }) else: return JsonResponse({ 'status': 'fail', 'msg': '参数错误', })
def post(self, request, *args, **kwargs): ''' 用户评论 ''' # request.user.is_authenticated:用来判断用户是否登陆 if not request.user.is_authenticated: return JsonResponse({ "status": "fail", "msg": "用户未登录", }) comment_form = CommentsForm(request.POST) if comment_form.is_valid(): course = comment_form.cleaned_data['course'] comments = comment_form.cleaned_data['comments'] comment = CourseComments() comment.user = request.user comment.comments = comments comment.course = course comment.save() return JsonResponse({ "status": "success", }) else: return JsonResponse({ "status": "fail", "msg": "参数错误", })
def post(self, request, *args, **kwarg): # ユーザーがログインできているかどうか確認 if not request.user.is_authenticated: return JsonResponse({ "status": "fail", "msg": "用户未登录", }) comment_form = CommentForm(request.POST) if comment_form.is_valid(): course= comment_form.cleaned_data["course"] comments = comment_form.cleaned_data["comments"] # ブックマークしてたかどうか確認 course_comment = CourseComments() course_comment.user = request.user course_comment.course = course course_comment.comments = comments course_comment.save() return JsonResponse({ "status": "success", "msg": "已收藏", }) else: return JsonResponse({ "status": "fail", "msg": "参数错误", })
def post(self, request, *args, **kwargs): ''' 用户收藏,取消收藏 :param request: :param org_id: :param args: :param kwargs: :return: ''' comment_form = CommentsForm(request.POST) # 如果用户未登录 if not request.user.is_authenticated: return JsonResponse({ 'status': 'fail', 'msg': '用户未登录' }) if comment_form.is_valid(): course = comment_form.cleaned_data['course'] comments = comment_form.cleaned_data['comments'] comment = CourseComments() comment.user = request.user comment.comments = comments comment.course = course comment.save() return JsonResponse({ 'status': 'success', }) else: return JsonResponse({ 'status': 'fail', 'msg': '参数错误' })
def post(self, request): if not request.user.is_authenticated(): # 判断用户登录状态 return HttpResponse('{"status":"fail","msg":"用户未登录"}', content_type='application/json') course_id = request.POST.get('course_id', 0) comments = request.POST.get('comments', '') if course_id > 0 and comments: course_comments = CourseComments() course = Course.objects.get(id=int(course_id)) course_comments.course = course course_comments.comments = comments course_comments.user = request.user course_comments.save() return HttpResponse('{"status":"success","msg":"添加成功"}', content_type='application/json') else: return HttpResponse('{"status":"fail","msg":"添加失败"}', content_type='application/json')
def post(self, request, *args, **kwargs): if not request.user.is_authenticated: messages.error(request, "用户未登录!") return JsonResponse({"status": "fail", "msg": "用户未登录"}) course_comment_form = CourseCommentForm(request.POST) if course_comment_form.is_valid(): course = course_comment_form.cleaned_data["course"] user_comment = course_comment_form.cleaned_data["comments"] comment = CourseComments() comment.user = request.user comment.comments = user_comment comment.course = course comment.save() return JsonResponse({"status": "success"}) else: return JsonResponse({ "status": "fail", "msg": "参数错误", })