예제 #1
0
def create_feedback(request):
    '''
    创建反馈,接受的是form-data
    目前图片处理尚未完成
    :param request:
    :return:
    '''
    params = request.POST
    img = request.FILES.get('img')
    ok, message = check_html_content(params['content'])
    if not ok:
        return JsonResponse({"message": message}, status=400)
    ok, feedback_id = Feedback.create_feedback({
        "user_id":
        int(params['user_id']),
        "stars":
        int(params['stars']),
        "content":
        params["content"],
        "img":
        img,
        "reservation_id":
        int(params['reservation_id'])
    })

    if ok:
        return JsonResponse({"message": "ok", "feedback_id": feedback_id})
    else:
        return JsonResponse({"message": feedback_id}, status=500)
예제 #2
0
def update_feedback(request):
    # 目前上传新的图片会更改图片的名字,但是原来的图片没有删除。删除反馈的图片时候也没有删除
    try:
        params = request.POST
        ok, message = check_html_content(params['content'])
        if not ok:

            return JsonResponse({"message": message}, status=400)
        feedback = Feedback.objects(
            feedback_id=int(params['feedback_id'])).first()
        feedback.content = params['content']
        feedback.stars = int(params['stars'])
        img = request.FILES.get("img")
        if img:
            assert img.name.endswith(('.bmp', '.dib', '.png', '.jpg', '.jpeg',
                                      '.pbm', '.pgm', '.ppm', '.tif', '.tiff'))
            img_name = "static/feedback/" + str(
                feedback.feedback_id) + '.' + img.name.split('.')[-1]
            feedback.img = img_name
            feedback.save()
            with open(img_name, 'wb+') as img_file:
                for chunk in img:
                    img_file.write(chunk)
        feedback.time = datetime.datetime.now()
        feedback.save()
        return JsonResponse({"message": "ok"})
    except Exception:
        return JsonResponse({"message": "服务器内部错误"}, status=500)
예제 #3
0
def create_share(request):
    '''
    创建拼场通知,一个成功订单才能对应一个拼场信息,必须检查
    '''

    params = json.loads(request.body)
    ok,message=check_html_content(params['content'])
    if not ok:
        return JsonResponse({'message':message},status=400)

    ok, message = Share_notification.create(params)
    if ok:
        return JsonResponse(message)
    else:
        return JsonResponse(message, status=400)
예제 #4
0
def update_share(request):
    '''
    更新拼场通知,同时会更新拼场通知的时间
     :param request:
    :return:
    '''
    try:
        params = json.loads(request.body)
        share = Share_notification.objects(share_id=params['share_id']).first()
        if share.user_id!=request.session.get('user_id'):
            return JsonResponse({"message": "没有更改权限"}, status=403)
        ok, message = check_html_content(params['content'])
        if not ok:
            return JsonResponse({'message': message}, status=400)
        share.content = params['content']
        share.time = datetime.datetime.now()
        share.save()
        return JsonResponse({"message": "ok"})
    except Exception:
        return JsonResponse({"message": "服务器内部错误"}, status=500)
예제 #5
0
 def test_right(self):
     for content in self.right_content:
         self.assertEqual(check_html_content(content), (True,"ok"))
     for content in self.wrong_length:
         self.assertEqual(check_html_content(content,9,101),(True,"ok"))
예제 #6
0
 def test_type(self):
     for content in self.wrong_type:
         self.assertEqual(check_html_content(content),(False,"wrong type"))
예제 #7
0
    def test_length(self):

        self.assertEqual(check_html_content(self.wrong_length[0]),(False,"too short"))
        self.assertEqual(check_html_content(self.wrong_length[1]), (False, "too long"))