def teacher(request): flag, rank = check_cookie(request) if not flag: return render(request, 'login.html') rank = model_to_dict(rank) print(json.dumps(rank)) return render(request, 'teacher.html', rank)
def del_item(request): flag, rank = check_cookie(request) if not flag: return render(request, 'login.html', {'error_msg': ''}) uid = model_to_dict(rank).get('uid') if request.POST: update_item(uid, request.POST.get('name'), 1, request.POST.get('uid')) return render(request, 'search_item.html')
def get_items(request): flag, rank = check_cookie(request) if not flag: return render(request, 'login.html', {'error_msg': ''}) uid = model_to_dict(rank).get('uid') items = search_items(uid) items = items_to_table(items) res = {"code": 0, "msg": "", "count": len(items), "data": items} res = json.dumps(res) return HttpResponse(res)
def get_record_table(request): flag, rank = check_cookie(request) if not flag: return render(request, 'login.html', {'error_msg': ''}) uid = model_to_dict(rank).get('uid') total, table = get_check_record_table(uid, page=int(request.GET.get('page'))-1, limit=int(request.GET.get('limit'))) for obj in table: obj['check_time'] = time.strftime("%Y年%m月%d日 %H:%M:%S", time.localtime(obj['check_time'])) # test_data = {"check_id": 1, "check_item": "计算机171", "check_time": "2021/4/17/15:30", "checked_count": 20, # "total_count": 21, "unchecked_stu": ['石头人']} # table.append(test_data) res = {"code": 0, "msg": "", "count": total, "data": table} res = json.dumps(res) return HttpResponse(res)
def stu_index(request): # 如果当前时间和二维码的时间差距超过15s就当过期处理 flag, rank = check_stu_login_cookie(request) if not flag: return render(request, 'stu_login.html') print(request) if not request.GET.get('time'): return render(request, 'stu_index.html', {'res_msg': '登录后请重新扫描二维码'}) rank = model_to_dict(rank) check_time = int(request.GET.get('time')) t = time.time() t = int(round(t * 1000)) print(f't:{t}, check_time:{check_time}') if t - check_time > 15 * 1000: return render(request, 'stu_index.html', {'res_msg': '二维码已过期'}) res = student_check(rank['uid'], request.GET.get('cls_id'), request.GET.get('check_id')) return render(request, 'stu_index.html', {'res_msg': res})
def check(request): flag, rank = check_cookie(request) if not flag: return render(request, 'login.html', {'error_msg': ''}) uid = model_to_dict(rank).get('uid') keys = request.GET.keys() dt = dict() for key in keys: dt[key] = request.GET[key] print(dt) dt['uid'] = uid dt['time'] = round(time.time()) # 生成签到记录 dt['check_id'] = generate_check_info(t_uid=uid, check_time=dt['time'], item_id=dt['class_list']) if not dt.get('N'): dt['N'] = 181.0 if not dt.get('E'): dt['E'] = 181.0 print(dt) return render(request, 'check.html', dt)