def idc(): role = session.get('role') idcs = utils.select_one('idc',idc_fields)['result'] user = utils.select_one('user',['username','phone'],id=idcs[0]['userid'])['result'] idcs=[dict(k,**v) for k in idcs for v in user] print(idcs) return render_template("idclist.html",idcs = idcs,role = role)
def userlist(): role = session.get('role') if role: users = utils.select_one('user', user_fields) return render_template("userlist.html", users=users['result'], role=role) else: user = utils.select_one('user', user_fields, session.get('id')) return render_template("userinfo.html", user=user[0], role=role)
def userinfo(): if request.args.get('id'): user = utils.select_one('user', user_fields,id=request.args.get('id') ) return json.dumps({'result':user['result'][0]}) else: role = session.get('role') user = utils.select_one('user', user_fields, **session) if user['code']: res = user['result'][0] return render_template("userinfo.html", user = res, role=role)
def book_return(ISBN, student_id): result1, student_information = utils.select_one("Student", student_id) result2, ISBN_information = utils.select_one("Book", ISBN) result3, rent_information = utils.select_rent_book(ISBN) is_return = True is_rent = False book_number = student_information.book_number - 1 if not result1 or not result2 or not result3: return False else: if student_information.book_number <= 0: return False else: result = utils.show_book_return(ISBN, student_id, is_return, is_rent, book_number) return result
def idcadd(): if request.method == 'GET': users = utils.select_one('user', user_fields)['result'] return render_template('idcadd.html',users=users, info=session, role=session.get('role')) data = {k:v[0] for k,v in dict(request.form).items()} if utils.add('idc',data): return json.dumps({'code':1,'result':'add user success'})
def book_borrow(ISBN, student_id): result1, student_information = utils.select_one("Student", student_id) result2, ISBN_information = utils.select_one("Book", ISBN) result3, rent_information = utils.select_rent_book(ISBN) book_name = ISBN_information.book_name student_name = student_information.student_name begin_date = datetime.date.today() end_date = datetime.date.today() + relativedelta(months=+1) is_return = False is_rent = True book_number = student_information.book_number + 1 if not result1 or not result2 or result3: return False else: if student_information.book_number >= 10: return False else: result = utils.show_book_borrow(ISBN, book_name, student_id, student_name, begin_date, end_date, is_return, is_rent, book_number) return result
def login_checking(user_id, password, user_type): try: if user_type == "admin": is_presence, result = utils.select_one("Admin", user_id) if is_presence and result.password == password: return result.admin_id, result.admin_name, result.password elif not is_presence: return "none" else: return "error" elif user_type == "student": is_presence, result = utils.select_one("Student", user_id) if is_presence and result.password == password: return result.student_id, result.student_name, result.password else: return "error" else: return "error" except Exception as e: print(e) return "error"
def login(): if request.method == 'GET': return render_template('login.html') user = {k:v[0] for k,v in dict(request.form).items()} if user.get('username') and user.get('password'): result = utils.select_one('user',user_fields,**user)['result'] if result: session['role'] = result[0]['role'] session['id'] = result[0]['id'] session['username'] = result[0]['username'] return json.dumps({'code': '1', 'result': 'login success'}) else: return json.dumps({'code': '0', 'result': 'name or password wrong'}) else: return json.dumps({'code':'0','result':'username or password not be null'})