def checkdata(): cod = request.form['code'].lower() str1 = session.get("str1") if cod != str1: return redirect("/login") phone = request.form['username'] upass = request.form['password'] # sys = request.form['sys'] md5 = hashlib.md5() md5.update(upass.encode()) upass = md5.hexdigest() print(uname, upass) cur.execute("select * from users where uname=%s and upass=%s", (phone, upass)) result = cur.fetchone() print(result) if result: if result['rid'] == 1: cur.execute("select classid from studentes where phone=%s", (phone)) classid = cur.fetchone()['classid'] cur.execute("select * from classes where id=%s", (classid)) data = cur.fetchone() classname = data['name'] fid = data['fid'] elif result['rid'] == 2: cur.execute("select class from teacher where phone=%s", (phone)) classname = cur.fetchone()['class'] cur.execute("select * from classes where name=%s", (classname)) data = cur.fetchone() classid = data['id'] fid = data['fid'] else: classname = '' classid = '' fid = '' if result: session['fid'] = fid session['class'] = classname session['classid'] = classid session['rid'] = result['rid'] session['uid'] = result['uid'] session['login'] = "******" session['name'] = result['name'] # if sys=='0': return redirect('/') # else: # return redirect('/exam') return redirect('/login')
def upload(): UPLOAD_FOLDER = 'upload/exam/' current_app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER if request.method == 'POST': f = request.files['file'] # 从表单的file字段获取文件,myfile为该表单的name值 if f and allowed_file(f.filename): # 判断是否是允许上传的文件类型 fname = secure_filename(f.filename) suf = fname.rsplit('.', 1)[1] #截取文件后缀名 now = int(time.time()) newfile = str(now)+'.'+suf f.save(os.path.join(current_app.config['UPLOAD_FOLDER'],newfile)) book=xlrd.open_workbook('upload/exam/'+newfile) sheet = book.sheet_by_index(0) #定义一个对象 question=[] for i in range(1,sheet.nrows): arr=[] con = sheet.row_values(i) cur.execute("select cid from `cursor` where cname=%s",(con[0])) fid=cur.fetchone()['cid'] cur.execute("select nid from questiontype where name=%s", (con[1])) nid=cur.fetchone()['nid'] sel=con[3].split('|') if nid==1: answer=sel.index(str(int(con[4]))) elif nid==2: answer='' ans = con[4].split('|') for i in range(len(sel)): for j in range(len(ans)): if sel[i] == ans[j]: a=str(i)+'|' answer+=a answer=answer[0:-1] elif nid==3: con[3]=None if con[4]=='错': answer=0 elif con[4]=='对': answer=1 arr+=[fid]+[con[2]]+[con[3]]+[answer]+[int(con[5])]+[nid] question.append(tuple(arr)) cur.executemany("insert into question (fid,con,`option`,answer,point,nid) values (%s,%s,%s,%s,%s,%s)",(question)) db.commit() return 'ok' else: return "error"
def selectonestudent(): name = request.args.get('name') cur.execute("select id from classes where name=%s", (name)) id = cur.fetchone()['id'] cur.execute("select name,phone,school from studentes where classid=%s", (id)) result = cur.fetchall() return json.dumps(result)
def menu(): rid = session.get("rid") cur.execute("select power from role where rid=%s", (rid)) if int(rid) > 1: rid = 0 print(rid) result = cur.fetchone()['power'] + '|' + str(rid) # result="1|2|3|4|5|6|7|8|0" return result
def selectdaily(): rid = session.get('rid') uid = session.get('uid') if rid == '1': cur.execute("select name,date from studaily where uid=%s", (uid)) result = cur.fetchall() for item in result: # 把时间对象转化为字符串 if isinstance(item['date'], object): item['date'] = item['date'].strftime("%Y-%m-%d") return json.dumps(result) elif rid == '2': cur.execute("select phone from users where uid=%s", (uid)) phone = cur.fetchone()['phone'] cur.execute("select class from teacher where phone=%s", (phone)) classname = cur.fetchone()['class'] cur.execute("select id from classes where name=%s", (classname)) id = cur.fetchone()['id'] db1 = pymysql.connect(host="localhost", user="******", password="******", db="lzm", charset="utf8") cur1 = db1.cursor() cur1.execute('select phone from studentes where calssid=%s', (id)) allphone = cur1.fetchall() print(allphone) cur1.executemany('select uid from users where phone=%s', (allphone)) alluid = cur1.fetchall() db1.close() cur.executemany('select * from studaily where uid=%s', (alluid)) result = cur.fetchall() for item in result: if isinstance(item['date'], object): item['date'] = item['date'].strftime("%Y-%m-%d") return json.dumps(result) else: cur.execute("select * from studaily") result = cur.fetchall() for item in result: # 把时间对象转化为字符串 if isinstance(item['date'], object): item['date'] = item['date'].strftime("%Y-%m-%d") return json.dumps(result)
def addjudge(): con=request.args.get('con') answer=request.args.get('answer') nid = 3 point = request.args.get('point') or 3 cname = request.args.get('cname') cur.execute("select cid from `cursor` where cname=%s", (cname)) fid = cur.fetchone()['cid'] cur.execute("insert into question (fid,con,answer,point,nid) values (%s,%s,%s,%s,%s)",(fid, con, answer, point, nid)) db.commit() return 'ok'
def addone(): name = request.args.get('name') f = request.args.get('f') start = request.args.get('start') end = request.args.get('end') cur.execute("select cid from `cursor` where cname=%s", (f)) cid = cur.fetchone()['cid'] cur.execute( "insert into classes (name,start,end,fid) values (%s,%s,%s,%s)", (name, start, end, cid)) db.commit() return "ok"
def addstudaily(): uid = session.get('uid') # classid=session.get('classid') cur.execute("select phone from users where uid=%s", (uid)) phone = cur.fetchone()['phone'] name = session.get('name') motto = request.args.get('motto') con = request.args.get('con') heart = request.args.get('heart') suggest = request.args.get('suggest') date = request.args.get('date') cur.execute( "insert into studaily (uid,name,motto,con,heart,suggest,date,phone) values (%s,%s,%s,%s,%s,%s,%s,%s)", (uid, name, motto, con, heart, suggest, date, phone)) db.commit() return 'ok'
def getquestion(fid, name, question): cur.execute("select * from questiontype where name=%s", (name)) onenid = cur.fetchone()['nid'] cur.execute("select id from question where fid=%s and nid=%s", (fid, onenid)) oneid = cur.fetchall() onearr = [] for i in oneid: onearr.append(i['id']) arr = [] while len(question) < 4: i = random.randint(0, len(onearr) - 1) if i not in arr: arr.append(i) question.append(onearr[i]) return question
def addone(): name = request.args.get('name') f = request.args.get('f') phone = request.args.get('phone') classes = request.args.get('classes') md5 = hashlib.md5() md5.update(b'111111') up = md5.hexdigest() cur.execute("select cid from `cursor` where cname=%s", (f)) fid = cur.fetchone()['cid'] cur.execute( "insert into teacher (name,phone,class,fid) values (%s,%s,%s,%s)", (name, phone, classes, fid)) cur.execute( "insert into users (name,uname,upass,phone,rid) values (%s,%s,%s,%s,%s)", (name, phone, up, phone, 2)) db.commit() return "ok"
def addone(): name = request.args.get('name') school = request.args.get('school') phone = request.args.get('phone') classes = request.args.get('classes') md5 = hashlib.md5() md5.update(b'111111') up = md5.hexdigest() cur.execute("select id from classes where name=%s", (classes)) classid = cur.fetchone()['id'] cur.execute( "insert into studentes (name,phone,school,classid) values (%s,%s,%s,%s)", (name, phone, school, classid)) cur.execute( "insert into users (name,uname,upass,phone,rid) values (%s,%s,%s,%s,%s)", (name, phone, up, phone, 1)) db.commit() return "ok"
def selectonecursor(): cid = request.args.get('cid') cname = request.args.get('cname') cur.execute( "select GROUP_CONCAT(step) from `cursor` inner join dircursor where `cursor`.cid=%s and dircursor.cid=%s group by cname", (cid, cid)) step = cur.fetchone()['GROUP_CONCAT(step)'] step = step.split(",") cur.execute( "select part from `cursor` inner join dircursor where `cursor`.cid=%s and dircursor.cid=%s", (cid, cid)) part = cur.fetchall() result = [] for i in range(len(step)): obj = {'cname': cname} obj['step'] = step[i] obj['part'] = part[i]['part'] result.append(obj) # result[0]['cname']=cname return json.dumps(result)
def total(): cur.execute("select count(*) from question") result = cur.fetchone()['count(*)'] return str(result)
def selectitems(): rid = request.cookies.get("rid") cur.execute("select power from role where rid=%s",(rid)) result = cur.fetchone()['power'] return 'ok'
def editrole(): rid=request.args.get("rid") cur.execute("select power from role where rid=%s",(rid)) result = cur.fetchone()['power'] return result
def time1(): fid = session.get('fid') or 32 cur.execute("select * from exam1 where fid=%s", (str(fid))) time = cur.fetchone()['alltime'] return str(time)