Ejemplo n.º 1
0
    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': '参数错误',
            })
Ejemplo n.º 2
0
    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")
Ejemplo n.º 3
0
 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')
Ejemplo n.º 4
0
    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")
Ejemplo n.º 5
0
 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')
Ejemplo n.º 6
0
    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')
Ejemplo n.º 7
0
    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 int(course_id) > 0 and comments:
            course_comment = CourseComment()
            course = Course.objects.get(id=int(course_id))
            course_comment.course = course
            course_comment.user = request.user
            course_comment.comments = comments
            course_comment.save()
            return HttpResponse('{"status":"success","msg":"添加成功"}',
                                content_type='application/json')
        else:
            return HttpResponse('{"status":"fail","msg":"添加出错"}',
                                content_type='application/json')
Ejemplo n.º 8
0
 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))