Example #1
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', '')
        # 判断用户是否品论过

        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')
Example #2
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)
     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')
Example #3
0
    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': '添加失败'})
Example #4
0
    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')
Example #5
0
 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')
Example #6
0
    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')
Example #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", "")
        comments = request.POST.get("comments", "")
        if course_id 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')
Example #8
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)
        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')
Example #9
0
    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')