def getProgessInfo(request): token = request.META['HTTP_X_ACCESS_TOKEN'] json_result = Auth.decode_auth_token(token) user_name = json_result['data']['id'] json_result = json.loads(request.body) arr = getProgess({'bookid': json_result['id']}) return JsonResponse({"list": arr})
def userinfo(request): json_result = '' try: token = request.META['HTTP_X_ACCESS_TOKEN'] json_result = Auth.decode_auth_token(token) except: print('token获取失败') return JsonResponse({'status': json_result})
def getBookList(request): token = request.META['HTTP_X_ACCESS_TOKEN'] json_result = Auth.decode_auth_token(token) user_name = json_result['data']['id'] data = {} result = bookApi.queryBookList(user_name) data["list"] = result return JsonResponse(data)
def getReviewInfo(request): token = request.META['HTTP_X_ACCESS_TOKEN'] json_result = Auth.decode_auth_token(token) user_name = json_result['data']['id'] data = {} r_date = review_date() result = bookApi.getReviewInfo(user_name, r_date) data["list"] = result return JsonResponse(data)
def queryRank(request): token = request.META['HTTP_X_ACCESS_TOKEN'] json_result = Auth.decode_auth_token(token) user_name = json_result['data']['id'] data = {} try: list = Rank.queryRank(user_name)[0]['rank'] status = 0 except: list = 0 status = 1 return JsonResponse({'status': status, 'list': list})
def deleteBook(request): token = request.META['HTTP_X_ACCESS_TOKEN'] json_result = Auth.decode_auth_token(token) user_name = json_result['data']['id'] json_result = json.loads(request.body) try: bookApi.deleteBook(json_result, user_name) status = '删除成功!' except: status = '删除失败!' return JsonResponse({"msg": status})
def queryTask(request): token = request.META['HTTP_X_ACCESS_TOKEN'] json_result = Auth.decode_auth_token(token) user_name = json_result['data']['id'] params = json.loads(request.body) params['begin'] += ' 00:00:00' params['end'] += ' 23:59:59' print(params) data = {} result = Task.queryTask(user_name, params) data["list"] = result return JsonResponse(data)
def completeTask(request): token = request.META['HTTP_X_ACCESS_TOKEN'] json_result = Auth.decode_auth_token(token) user_name = json_result['data']['id'] params = json.loads(request.body) print(params) params['complete_time'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') result = Task.completeTask(user_name, params) data = {} data["list"] = result print(data) return JsonResponse(data)
def addTask(request): token = request.META['HTTP_X_ACCESS_TOKEN'] json_result = Auth.decode_auth_token(token) user_name = json_result['data']['id'] params = json.loads(request.body) params['task_create_time'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') if 0 == params['task_repeat_end']: params['task_repeat_end'] = '2100-01-01' print(params) data = {} result = Task.addTask(user_name, params) data["list"] = result return JsonResponse(data)
def addReadInfo(request): token = request.META['HTTP_X_ACCESS_TOKEN'] json_result = Auth.decode_auth_token(token) user_name = json_result['data']['id'] json_result = json.loads(request.body) json_result['today'] = datetime.datetime.now().strftime('%Y-%m-%d') try: bookApi.addReadInfo(json_result, user_name) status = '新增成功!' Rank.addRank(user_name, json_result['reading_rank']) updateProgess(json_result) except: status = '新增失败!' return JsonResponse({"msg": status})
def addBook(request): token = request.META['HTTP_X_ACCESS_TOKEN'] json_result = Auth.decode_auth_token(token) user_name = json_result['data']['id'] params = json.loads(request.body) print(user_name) bookIsRepeat = bookApi.bookIsRepeat(user_name, params["bookName"]) if bookIsRepeat != 0: return JsonResponse({"status": 1, "msg": "书籍已存在!"}) else: filed = { "user_name": user_name, "book_name": params["bookName"], "book_number": params["bookNumber"], "read_type": params["readType"] } result = bookApi.addBook(filed) msg = "书籍新增成功!" if result == 0 else "书籍新增失败!" return JsonResponse({"status": result, "msg": msg})
def index(request): key = "ztj_" json_result = json.loads(request.body) userName = json_result["userName"] password = json_result["password"] u_pass = hashlib.md5((password + key).encode("UTF8")).hexdigest() dbPassword = userApi.queryPassword(userName) m = 1 token = '' if dbPassword: if u_pass == dbPassword[0]["user_password"]: m = 0 token = Auth.encode_auth_token(userName, time.time()).decode() else: m = 1 return JsonResponse({'status': m, 'token': token})
def checkReview(request): try: token = request.META['HTTP_X_ACCESS_TOKEN'] json_result = Auth.decode_auth_token(token) user_name = json_result['data']['id'] json_result = json.loads(request.body) r_date = {'0': 1, '1': 2, '2': 4, '3': 7, '4': 15} num = json_result['num'] fixnum = -r_date[num] now_time = datetime.datetime.now() fix_time = now_time + datetime.timedelta(days=fixnum) fixday = fix_time.strftime('%Y-%m-%d') bookApi.checkReview(fixday, json_result['id']) Rank.addRank(user_name, 10) status = 0 except: status = 1 return JsonResponse({"status": status})