Пример #1
0
def index(request):
    if 'Email' in request.COOKIES:
        # if user has logged in, it has Email in cookies
        email = request.COOKIES.get('Email', '')
        if email:
            # initialize some result
            status = ''
            imagePath = ''
            message = ''
            completeData = []
            ret = {}
            completeCount = 0
            rectCount = 0
            bookName = ''
            volume = ''
            page = ''
            # get the imagePath and complete situation
            # imagePath = getNextPhoto(email)
            completeData = getComplete(email)
            completeCount = completeData[0]
            rectCount = completeData[1]
            imagePath = completeData[2]
            if imagePath == BUSY_FLAG:
                # no effective imagePath
                # distribute again and update
                imagePath = distributePhoto(email)
            if imagePath[0] == '-':
                # there is no new image need to be labeled
                status = imagePath
            else:
                message = getMessage(imagePath)
                bookName, volume, page = getBookInfo(imagePath)

            # set the return result
            imagePath = datapath + imagePath
            ret = {
                'completeCount': completeCount,
                'rectCount': rectCount,
                'status': status,
                'imagePath': imagePath,
                'message': message,
                'bookName': bookName,
                'volume': volume,
                'page': page,
                'Email': email
            }
            # set cookies which will expires 3 days later and return
            # response
            response = render(request, 'index.html', {'ret': ret})
            response.set_cookie('Email',
                                email,
                                expires=datetime.datetime.now() +
                                datetime.timedelta(days=3))
            return response
            # return render(request, 'index.html', {'ret': ret})
        else:
            return redirect('error')
    else:
        # if user has not logged in, redirect to the login page
        return redirect('login_with_args', state='0')
Пример #2
0
def selfCheck(request):
    if 'Email' in request.COOKIES:
        email = request.COOKIES.get('Email', '')
        storeFlagCookie = request.COOKIES.get('storeFlag', '')
        completeData = getComplete(email)
        completeCount = completeData[0]
        ret = {}
        if completeCount == 0:
            # the user has not labeled any data
            ret = {
                'checkStatus': '-1'
            }
            return render(request, 'selfCheck.html', {'ret': ret})
        checkedNum = completeData[3]
        toMarkNum = completeCount - checkedNum
        if storeFlagCookie == '1':
            # "0" for using the data from front end
            ret = {
                'checkStatus': '0'
            }
            return render(request, 'selfCheck.html', {'ret': ret})
        mesData_set = MessageDatas.objects.filter(Email=email, IsChecked=False)
        if mesData_set.count() == 0:
            # the user has finished checking his data
            ret = {
                'checkStatus': '-2'
            }
            return render(request, 'selfCheck.html', {'ret': ret})
        cnt = 0
        todoList = ''
        for rec in mesData_set:
            if cnt == 0:
                ret_photopath = datapath + rec.PhotoPath
                ret_message = rec.Message
                ret_language = rec.Language
                ret_scene = rec.Scene
                ret_rectCount = rec.RectCount
                ret_quality = rec.Quality
                cnt = 1
            else:
                todoList += "_" + datapath + rec.PhotoPath + ',' +\
                    rec.Quality + ',' + rec.Language + ',' +\
                    rec.Scene + ',' + rec.Message
        ret = {
            'checkStatus': 1,
            'Email': email,
            'photoPath': ret_photopath,
            'Message': ret_message,
            'Language': ret_language,
            'Scene': ret_scene,
            'RectCount': ret_rectCount,
            'Quality': ret_quality,
            'checkedNum': checkedNum,
            'toMarkNum': toMarkNum
        }
        if todoList != '':
            ret["todoList"] = todoList[1:]
            response = render(request, 'selfCheck.html', {'ret': ret})
            response.set_cookie('storeFlag', '1',
                                expires=datetime.datetime.now() +
                                datetime.timedelta(hours=6))
        else:
            ret["todoList"] = todoList
            response = render(request, 'selfCheck.html', {'ret': ret})
            response.set_cookie('storeFlag', '0',
                                expires=datetime.datetime.now() +
                                datetime.timedelta(hours=6))
        return response
    else:
        return redirect('login_with_args', state='0')
Пример #3
0
def setCheckMessage(request):
    # check the email first
    if 'Email' in request.COOKIES:
        # get the data and update the database
        email = request.COOKIES.get('Email', '')
        if email:
            # extract data
            message = request.POST.get("Message", '')
            photoPath = request.POST.get('PhotoPath', '')
            language = request.POST.get('Language', '')
            scene = request.POST.get('Scene', '')
            quality = request.POST.get('Quality', '')
            # check complete datas
            if CompleteDatas.objects.filter(Email=email).exists():
                completeData = getComplete(email)
                checkedNum = completeData[3]
                toCheckedNum = completeData[0] - checkedNum
                # update database
                if MessageDatas.objects.filter(PhotoPath=photoPath).exists():
                    rec = MessageDatas.objects.get(PhotoPath=photoPath)
                    rec.Email = email
                    rec.Message = message.encode('utf8')
                    rec.Language = language
                    rec.Scene = scene
                    rec.RectCount = len(message.split(';'))
                    rec.Quality = quality
                    rec.Status = '11'
                    print "Email, Message, Language, Scene, RectCount, Quality"
                    print email, rec.Message, language, scene,\
                        len(message.split(';')), quality
                    # print type(rec.Message)
                    if rec.IsChecked:
                        rec.save()
                        ret = {
                            "status": 0,
                            "checkedNum": checkedNum,
                            "toCheckedNum": toCheckedNum
                        }
                    else:
                        # update and return
                        rec.IsChecked = True
                        rec.save()
                        usrComplt = CompleteDatas.objects.get(Email=email)
                        usrComplt.CheckedCount += 1
                        usrComplt.save()
                        ret = {
                            "status": "0",
                            "checkedNum": checkedNum + 1,
                            "toCheckedNum": toCheckedNum - 1
                        }
                    # return result
                    return HttpResponse(json.dumps(ret),
                                        content_type='text/json')
                else:
                    return HttpResponse(json.dumps({"status": "-4"}),
                                        content_type='text/json')
            else:
                return HttpResponse(json.dumps({"status": "-3"}),
                                    content_type='text/json')
        else:
            return HttpResponse(json.dumps({"status": "-2"}),
                                content_type='text/json')
    else:
        return redirect('login_with_args', state='0')