def post(self, request): if not request.user.is_authenticated: return JsonResponse({"status": "fail", "msg": "用户未登录"}) course_id = request.POST.get('course_id', 0) comments = request.POST.get('comments', '') if int(course_id) > 0 and comments: course = Course.objects.get(id=course_id) course_comment = CourseComment(user=request.user, course=course, comments=comments) course_comment.save() return JsonResponse({"status": "success", "msg": "添加失败"}) else: return JsonResponse({"status": "success", "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', '') # 判断用户是否品论过 is_comment = CourseComment.objects.filter(course_id=course_id, user=request.user) if is_comment: return HttpResponse('{"status":"fail","msg":"您已经评论过该课程"}', content_type='application/json') else: if course_id > 0 and comments: course_comment = CourseComment() course = Course.objects.get(id=int(course_id)) course_comment.course = course course_comment.comment = comments course_comment.user = request.user course_comment.save() return HttpResponse('{"status":"success","msg":"添加成功"}', content_type='application/json') else: return HttpResponse('{"status":"fail","msg":"添加失败"}', content_type='application/json')
def post(self, request): 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 = CourseComment() 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: #用户未登录时返回给前台ajax的json数据 return HttpResponse("{'status': 'fail', 'msg':'用户未登录'}", content_type='application/json') course_id = request.POST.get('course_id', '0') comment = request.POST.get('comments', '') if course_id > '0' and comment: course_comment = CourseComment( course=Course.objects.get(id=int(course_id)), comments=comment, user=request.user) course_comment.save() return HttpResponse("{'status': 'success', 'msg':'评论成功'}", content_type='application/json') else: return HttpResponse("{'status': 'fail', 'msg':'评论失败'}", content_type='application/json')
def post(self, request): if request.user.is_authenticated: course_id = request.POST.get('course_id', '') comments = request.POST.get('comments', '') CourseComment(user=request.user, course_id=course_id, comments=comments).save() return JsonResponse({'status': 'success'}) else: return JsonResponse({'status': 'fail'})
def post(self, request, course_id): user = request.user try: course = Course.objects.get(id=int(course_id)) except Course.DoesNotExist: return render(request, '404.html') if user.is_authenticated(): comment = request.POST.get('comments', '') data = { "status": "success", } course_comment = CourseComment(user=user, course=course, comment=comment) course_comment.save() return HttpResponse(json.dumps(data), content_type="application/json") else: data = {"status": "fail", "msg": u"用户未登陆"} return HttpResponse(json.dumps(data), content_type="application/json")
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) comment = request.POST.get("comments", "") if int(course_id) > 0 and comment: course = Course.objects.get(id=int(course_id)) course_comment = CourseComment() course_comment.user = request.user course_comment.course = course course_comment.comment = comment course_comment.save() return HttpResponse('{"status":"success","msg":"评论成功"}', content_type='application/json') else: return HttpResponse('{"status":"fail","msg":"出现了很意外的事故"}', content_type='application/json')
def post(self,request): #首先判断是否登陆 if not request.user.is_authenticated(): return HttpResponse(json.dumps({'status':'fail','msg':'用户未登录'}),content_type='application/json') #返回form的errors信息,跳转在Ajax中完成 course_id = request.POST.get('course_id',0) user = request.user comment = request.POST.get('comments',0) if int(course_id)>0 and comment: course_comment = CourseComment() course = Course.objects.get(id=course_id) course_comment.Course = course course_comment.User = user course_comment.Comment = comment course_comment.save() return HttpResponse(json.dumps({'status':'success','msg':'评论成功'}),content_type='application/json') #返回form的errors信息,跳转在Ajax中完成
def post(self, request): if not request.user.is_authenticated(): return HttpResponse(dumps({'status': 'fail', 'msg': u'用户未登录'}), content_type="application/json") course_id = request.POST.get('course_id', 0) comments = request.POST.get('comments', "") if int(course_id) > 0 and comments: course_comment = CourseComment() course_comment.comments = comments course = Course.objects.get(id = int(course_id)) course_comment.course = course course_comment.user = request.user course_comment.save() return HttpResponse(dumps({'status':'success', 'msg':u'添加成功'}), content_type="application/json")
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 bool(course_id) and bool(comments): course_comment = CourseComment() course = Course.objects.get(id=int(course_id)) course_comment.course = course course_comment.comments = comments course_comment.user = request.user course_comment.save() return HttpResponse('{"status":"success", "msg":"添加成功"}', content_type='application/json') else: return HttpResponse('{"status":"fail", "msg":"添加失败"}', content_type='application/json')
def post(self, request): if not request.user.is_authenticated: return JsonResponse({'status': '0', 'msg': '用户未登录'}) course_id = int(request.POST.get('course_id', 0)) comments = request.POST.get('comments', '') if course_id > 0 and comments: course_comment = CourseComment() course = Course.objects.get(id=course_id) course_comment.course = course course_comment.comment = comments course_comment.user = request.user course_comment.save() return JsonResponse({'status': '1', 'msg': '添加成功'}) else: return JsonResponse({'status': '0', 'msg': '添加失败'})
def post(self,request): # 判断用户登录状态 if not request.user.is_authenticated(): return render(request,'index.html',{'msg':'请先登录!','msg_status':'danger'}) course_id = request.POST.get('course_id',0) comments = request.POST.get('text','') if course_id > 0 and comments: course_comments = CourseComment() course = Course.objects.get(id=int(course_id)) course_comments.course = course course_comments.comment = 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): 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 = CourseComment() 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): 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_comment = CourseComment() course = Course.objects.get(id=int(course_id)) course_comment.course = course course_comment.comments = comments course_comment.user = request.user course_comment.save() return HttpResponse("{'status':'success','msg':'评论成功'}", content_type='application/json') else: return HttpResponse("{'status':'fail','msg':'评论失败'}", content_type='application/json')
def post(self, request): if not request.user.is_authenticated: return HttpResponse('{"status": "fail", "msg": "用户未登陆"}', content_type='application/json') else: course_id = request.POST.get('course_id', 0) comment = request.POST.get('comments', '') if int(course_id) > 0 and comment: course_comment = CourseComment() course = Course.objects.get(pk=course_id) course_comment.course = course course_comment.user = request.user course_comment.comment = comment course_comment.save() return HttpResponse('{"status": "success", "msg": "评论成功"}', content_type='application/json') else: return HttpResponse('{"status": "fail", "msg": "评论失败"}', content_type='application/json')
def post(self,request): # 先监测是否登录 if not request.user.is_authenticated(): return HttpResponse(json.dumps({'status':'fail','msg':'用户未登录'}),content_type='application/json') course_id = request.POST.get('course_id',0) comments = request.POST.get('comments','') # 如果id和评论存在获取到了,把各项内容插入到数据库中 if int(course_id) >0 and comments: course_comments = CourseComment() # 课程必须是对应id 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(json.dumps({'status':'success','msg':'发表评论成功'}),content_type='application/json') else: return HttpResponse(json.dumps({'status':'fail','msg':'评论失败'}),content_type='application/json')
def post(self, request): if not request.user.is_authenticated: return HttpResponse('{"status":"fail","msg":"Not logged in"}', content_type='application/json') course_id = request.POST.get('course_id', '0') comment = request.POST.get('comment', '') if int(course_id) > 0 and comment: course_comment = CourseComment() course = Course.objects.get(id=int(course_id)) course_comment.course = course course_comment.user = request.user course_comment.comment = comment course_comment.save() return HttpResponse( '{"status":"success","msg":"Commented Successfully"}', content_type='application/json') else: return HttpResponse('{"status":"fail","msg":"Comment failed"}', content_type='application/json')
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) comment = request.POST.get('comment', '') if course_id and comment: # 评论和对应课程都不能为空 course_comment = CourseComment() course = Course.objects.get(id=int(course_id)) course_comment.course = course course_comment.user = request.user course_comment.comment = comment course_comment.save() return HttpResponse('{"status": "success", "msg": "发表成功"}', content_type='application/json') else: return HttpResponse('{"status": "fail", "msg": "发表失败"}', content_type='application/json')
def post(self, request): ret_msg = {} if not request.user.is_authenticated(): ret_msg["status"] = "fail" ret_msg["msg"] = "用户未登录" return HttpResponse(json.dumps(ret_msg)) course_id = request.POST.get("course_id", 0) comments = request.POST.get("comments", "") if course_id > 0 and comments: course_comments = CourseComment() course = Course.objects.get(id=int(course_id)) course_comments.course = course course_comments.comments = comments course_comments.user = request.user course_comments.save() ret_msg["status"] = "success" ret_msg["msg"] = "添加成功" return JsonResponse(ret_msg) else: ret_msg["status"] = "fail" ret_msg["msg"] = "添加失败" return HttpResponse(json.dumps(ret_msg))
def post(request): if not request.user.is_authenticated(): # 判断用户是否登录 return HttpResponse('{"status":"fail", "msg":"用户未登录"}', content_type='application/json') course_id = int(request.POST.get('curid', 0)) comment = request.POST.get('comment', "") if comment == '': return HttpResponse('{"status":"fail", "msg":"评论不能为空"}', content_type='application/json') if course_id > 0: ccts = CourseComment() ccts.course = Course.objects.get(id=course_id) ccts.comment = comment ccts.user = request.user ccts.save() return HttpResponse('{"status":"success", "msg":"添加成功"}', content_type='application/json') else: return HttpResponse('{"status":"fail", "msg":"添加失败"}', content_type='application/json')