def POST(self): mydata = web.input() print mydata web.header("Access-Control-Allow-Origin", "*") must_params = set({ 'cl_name', 'currentPage', }) if (util.paramsok(must_params, mydata) == 2): response = util.Response(status=util.Status.__params_not_ok__) return util.objtojson(response) else: print 222 currentPage = int(mydata.currentPage) - 1 print mydata.cl_name result = orm.db.query( 'select * from Class where cl_name like \'%%%s%%\'\ order by cl_id limit %s,%s' % (mydata.cl_name, currentPage * 10, 10)) result = [Class_model(**item) for item in result] Class = Class_model() result1 = Class.query( 'select count(*) from Class where cl_name like \'%%%s%%\'' % (mydata.cl_name)) count = result1[0]['count(*)'] page = util.Page(data=result, totalRow=count, currentPage=int(mydata.currentPage), pageSize=10, status=util.Status.__success__, message="未知") response = util.Response(status=util.Status.__success__, body=page) return util.objtojson(response)
def POST(self): mydata = web.input() qb = model.Questions_bank_model() must_params = set (['qb_id']) web.header("Access-Control-Allow-Origin", "*") if(util.paramsok(must_params,mydata) == 2): response = util.Response(status = util.Status.__params_not_ok__) return util.objtojson(response) elif str(mydata.deletepassword) == '123456': qb.qb_id = mydata.qb_id result = model.Questions_bank_has_question_model.getByArgs( \ questions_bank_qb_id = qb.qb_id) for item in result: questions_bank_has_question = model.Questions_bank_has_question_model() questions_bank_has_question.qbhq_id = item.qbhq_id questions_bank_has_question.delete() if qb.delete(): response = util.Response(status=util.Status.__success__) return util.objtojson(response) else: response = util.Response(status=util.Status.__error__) return util.objtojson(response) response = util.Response(status=util.Status.__error__) return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin", "*") # 接收参数 params = web.input() # str=os.path.abspath("test.docx") # str = str.decode('gbk') # print str classname = model.Class_model.getByPK(params.class_cl_id) examname = model.Exam_model.getByPK(params.ex_id) try: os.mkdir('%s/%s_%s' % (exampage_source, params.class_cl_id, params.ex_id)) except: shutil.rmtree('%s/%s_%s' % (exampage_source, params.class_cl_id, params.ex_id)) try: student = model.Student_has_class_model.getByArgs( class_cl_id=params.class_cl_id) for student_id in student: filepath = str('%s/%s_%s/%s.docx' % (exampage_source, params.class_cl_id, params.ex_id, student_id.student_st_id)) # print filepath util.word(student_id.student_st_id, params.ex_id, filepath) util.zip_path( '%s/%s_%s' % (exampage_source, params.class_cl_id, params.ex_id), '%s' % (exampage_source), u'%s_%s.zip' % (params.class_cl_id, params.ex_id)) except: response = util.Response(status=util.Status.__error__, ) return util.objtojson(response) response = util.Response(status=util.Status.__success__, message=str) return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin", "*") params = web.input() exam = model.Exam_model() must_params = exam.__notnull__ if (util.paramsok(must_params, params) == 2): response = util.Response(status=util.Status.__params_not_ok__) return util.objtojson(response) else: exam = model.Exam_model(**params) if exam.insert(): result = exam.query("select max(ex_id) from exam") lastExamId = int(result[0]['max(ex_id)']) # 获取教务班学生id stuHasClass = model.Student_has_class_model() classId = params['class_cl_id'].encode('utf-8') classId = classId.split(',') for k in range(1, len(classId) - 1): listStuid = stuHasClass.getByArgs(class_cl_id=classId[k]) for stuID in listStuid: informationArgs = dict( student_st_id=stuID.student_st_id, exam_ex_id=lastExamId, class_cl_id=classId[k], sg_id=exam.strategy_sg_id) information = model.Information_model( **informationArgs) information.insert() response = util.Response(status=util.Status.__success__) return util.objtojson(response) else: response = util.Response(status=util.Status.__error__) return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin", "*") params = web.input() information = model.Information_model() information_data = information.query('SELECT * FROM information WHERE \ class_cl_id=%s and exam_ex_id=%s' % (params.class_cl_id, params.ex_id)) information_data = [model.Information_model(**item) for item in information_data] exam = model.Exam_model.getByPK(params.ex_id) if exam.ex_type=="0": for information in information_data: information.in_endtime = datetime.datetime.now() information.in_state = '2' information.in_temp_ip = None db.update('exam_question', where="information_in_id = %s" % (information.in_id), eq_get_score='-2', ) information.update() response = util.Response(status=util.Status.__success__, ) return util.objtojson(response) else: if exam.ex_auto =="1": for information in information_data: information.in_endtime = datetime.datetime.now() if information.in_state=='1': information.in_state = '2' information.in_temp_ip = None db.update('exam_question', where="information_in_id = %s" % (information.in_id), eq_get_score='-2', ) information.update() thread.start_new(util.GetScore, (1,information.in_id)) response = util.Response(status=util.Status.__success__, ) return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin", "*") # 接收参数 params = web.input() print(params) db = pymysql.connect("localhost", port=3306, user="******", passwd="123456", db="examdb", charset='utf8') cursor = db.cursor() sql = "select * from teacher \ where tc_id = '{}'".format(params) try: # 执行SQL语句 cursor.execute(sql) # 获取所有记录列表 results = cursor.fetchall() except: # 发生错误时回滚 db.rollback() cursor.close() db.close() jsonResults = [] for row in results: data = {} data["tc_id"] = row[0] data["tc_name"] = row[1] data["tc_password"] = row[2] data["tc_level"] = row[3] data["lenth"] = len(results) jsonResults.append(data) print(util.objtojson(jsonResults)) return util.objtojson(jsonResults)
def POST(self): web.header("Access-Control-Allow-Origin", "*") params = web.input() class_ = model.Class_model.getByPK(params.class_cl_id) exam = model.Exam_model.getByPK(params.ex_id) ex, cl = exam.ex_id, class_.cl_id ex_cl = u'%s_%s' % (ex, cl) examDir = u'%s/%s' % (exampage_source, ex_cl) try: os.mkdir(examDir) except: shutil.rmtree(examDir) os.mkdir(examDir) try: student = model.Student_has_class_model.getByArgs( class_cl_id=params.class_cl_id) for student_id in student: filepath = examDir + u'/%s.docx' % (student_id.student_st_id) print filepath util.word(student_id.student_st_id, params.ex_id, filepath) zip_path = u'/source/exampage/%s.zip' % (ex_cl) util.zip_path(examDir, u'%s' % (exampage_source), u'%s.zip' % (ex_cl)) except: print("e") response = util.Response(status=util.Status.__error__, ) return util.objtojson(response) response = util.Response(status=util.Status.__success__, message=zip_path) return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin","*") must_params = ('st_id','cl_id') params = web.input() if util.paramsok(must_params, params) == Status.__params_not_ok__: response = Response(status = Status.__params_not_ok__ ) return util.objtojson(response) class_result = db.query("SELECT * FROM class WHERE cl_id= $cl_id", vars={'cl_id':params.cl_id}) # cl_id = class_result. __getitem__(0).get('cl_id') try: r1 = db.delete('student_has_class', where='class_cl_id=$cl_id and student_st_id = $st_id', vars={'cl_id':params.cl_id,'st_id':params.st_id}) r2 = db.delete('information',where = 'student_st_id=$st_id and class_cl_id = $cl_id',vars={'st_id':params.st_id,'cl_id':params.cl_id}) r3 = db.delete('student', where='st_id=$st_id', vars={'st_id':params.st_id}) if r1: if r3: response = Response(status = Status.__success__,message = "该学生已完全删除!") return util.objtojson(response) response = Response(status = Status.__success__,message = "该学生已从该课程班删除!") return util.objtojson(response) else: response = Response(status = Status.__success__,message = "该学生已从该课程班删除!") return util.objtojson(response) except Exception as e: response = Response(status = Status.__system_exception__,message = "该学生存在于其他课程班,已从当前课程班删除!") return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin","*") must_params = ('st_id','cl_name') params = web.input() if util.paramsok(must_params, params) == Status.__params_not_ok__: response = Response(status = Status.__params_not_ok__ ) return util.objtojson(response) class_result = db.query("SELECT * FROM class WHERE cl_name= $cl_name", vars={'cl_name':(params.cl_name.encode('utf-8'))}) if class_result: cl_id = class_result. __getitem__(0).get('cl_id') st_has_class_result = db.query("SELECT * FROM student_has_class WHERE class_cl_id= $cl_id", vars={'cl_id':cl_id}) if st_has_class_result: st = Student_model(st_id = params.st_id) st_result = Student_model.getByArgs(**st) if st_result == list(): response = Response(status = Status.__obj_null__ ,body = st_has_class_result) return util.objtojson(response) response = Response(status = Status.__success__,body = st_result) return util.objtojson(response) else: response = Response(status = Status.__obj_null__ ,body = st_has_class_result) return util.objtojson(response) else: response = Response(status = Status.__obj_null__) return util.objtojson(response)
def POST(self): mydata = web.input() print("删除题库", mydata) qb = model.Questions_bank_model() must_params = set(['qb_id']) web.header("Access-Control-Allow-Origin", "*") session = web.ctx.session # util.getFileRotatingLog().debug(session.password) # 写入到log文件 if (util.paramsok(must_params, mydata) == 2): response = util.Response(status=util.Status.__params_not_ok__) return util.objtojson(response) elif str(mydata.deletepassword) == session.password: qb.qb_id = mydata.qb_id result = model.Questions_bank_has_question_model.getByArgs( \ questions_bank_qb_id = qb.qb_id) for item in result: questions_bank_has_question = model.Questions_bank_has_question_model( ) questions_bank_has_question.qbhq_id = item.qbhq_id questions_bank_has_question.delete() if qb.delete(): response = util.Response(status=util.Status.__success__) return util.objtojson(response) else: response = util.Response(status=util.Status.__error__, message="删除失败") return util.objtojson(response) else: response = util.Response(status=util.Status.__error__, message="密码错误") return util.objtojson(response) response = util.Response(status=util.Status.__error__, message="删除失败") return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin","*") must_params = ('cl_id',) mydata = web.input() if util.paramsok(must_params, mydata) == Status.__params_not_ok__: response = Response(status = Status.__params_not_ok__ ,message = "参数错误!") return util.objtojson(response) params = Class_model(cl_id = mydata.cl_id) teacher = model.Teacher_model.getByArgs(tc_level='管理员') if str(mydata.deletepassword) != teacher[0].tc_password: response = util.Response(status=util.Status.__error__,message = "密码错误") return util.objtojson(response) try: with orm.db.transaction(): db.delete('student_has_class', where="class_cl_id = $class_cl_id", vars={'class_cl_id': params.cl_id, }) if db.delete('class', where="cl_id = $cl_id", vars={'cl_id': params.cl_id, }): response = Response(status=Status.__success__, message="班级删除成功!") return util.objtojson(response) else: response = Response(status=Status.__error__, message="班级删除失败!") return util.objtojson(response) except Exception as e: util.getFileRotatingLog().debug(e) response = Response(status=Status.__error__, message="班级删除失败!") return util.objtojson(response)
def GET(self): web.header("Access-Control-Allow-Origin", "*") # 接收参数 params = web.input() try: # session = web.ctx.session # username = "" if not username: print("not login") response = util.Response(status=util.Status.__not_login__, message='4') return util.objtojson(response) except Exception as e: print(e) response = util.Response(status=util.Status.__not_login__, message='4') return util.objtojson(response) teacher = model.Teacher_model.getByArgs(tc_id=session.username) if teacher[0].tc_level == '管理员': response = util.Response(status=util.Status.__success__, message='1') return util.objtojson(response) else: response = util.Response(status=util.Status.__success__, message='2') return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin", "*") must_params = ('cl_id', ) params = web.input(requestPage='0') if util.paramsok(must_params, params) == Status.__params_not_ok__: response = Response(status=Status.__params_not_ok__) return util.objtojson(response) requestPage = params['requestPage'].encode('utf-8') del params['requestPage'] #根据班号查学号,根据学号查学生 st_has_cl = Student_has_class_model(class_cl_id=params.cl_id) st_has_cl_result = Student_has_class_model.getByPage(page=requestPage, **st_has_cl) if st_has_cl_result: final_result = list() for s in range(len(st_has_cl_result)): st_ = st_has_cl_result[s].get('student_st_id') st = Student_model(st_id=st_) st_result = Student_model.getByPage(page=requestPage, **st) final_result.append(st_result[0]) response = Response(status=Status.__success__, body=final_result) return util.objtojson(response) else: response = Response(status=Status.__obj_null__) return util.objtojson(response)
def POST(self): mydata = web.input() print mydata web.header("Access-Control-Allow-Origin", "*") must_params = set({'qt_stem','currentPage',}) question = model.Question_model() Knowledge = model.Knowledge_model() currentPage = int(mydata.currentPage)-1; if(util.paramsok(must_params,mydata) == 2): response = util.Response(status = util.Status.__params_not_ok__) return util.objtojson(response) else: print 222 result = orm.db.query('select * from question where qt_stem like \'%%%s%%\'\ order by qt_id limit %s,%s'%(mydata.qt_stem,currentPage*10,10)) # result = orm.db.query('select * from question where qt_stem like \'%%%s%%\''%(mydata.qt_stem)) questionlist = [] result = [model.Question_model(**item) for item in result ] print result result1= question.query('select count(*) from question where qt_stem like \'%%%s%%\''%(mydata.qt_stem)) count = result1[0]['count(*)'] for params in result: qt = params qt['qt_type']=util.type[qt.qt_type] Knowledge = model.Knowledge_model() KnowledgeData = Knowledge.getByPK(qt.knowledge_kl_id) qt['kl_name'] = KnowledgeData.kl_name questionlist.append(qt) # response = util.Response(status=util.Status.__success__,body = questionlist) # return util.objtojson(response) page = util.Page(data = questionlist, totalRow = count, currentPage = int(mydata.currentPage), pageSize = 10, status=util.Status.__success__, message = "未知") response = util.Response(status=util.Status.__success__,body=page) return util.objtojson(response)
def POST(self): #修改为不需要管理员密码就能够删除 web.header("Access-Control-Allow-Origin", "*") must_params = ('cl_id', ) params = web.input() if util.paramsok(must_params, params) == Status.__params_not_ok__: response = Response(status=Status.__params_not_ok__, message="参数错误!") return util.objtojson(response) params = Class_model(cl_id=params.cl_id) print "delete_class" with orm.db.transaction(): db.delete('student_has_class', where="class_cl_id = $class_cl_id", vars={ 'class_cl_id': params.cl_id, }) if db.delete('class', where="cl_id = $cl_id", vars={ 'cl_id': params.cl_id, }): response = Response(status=Status.__success__, message="班级删除成功!") return util.objtojson(response) else: response = Response(status=Status.__error__, message="班级删除失败!") return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin", "*") must_params = ('st_id', 'st_name', 'cl_id') params = web.input() if util.paramsok(must_params, params) == Status.__params_not_ok__: response = util.Response(Status.__params_not_ok__, message='参数错误!') return util.objtojson(response) st_has_cl = Student_has_class_model(student_st_id=params.st_id, class_cl_id=params.cl_id) # del params.cl_id s = Student_model(st_id=params.st_id) try: st_exist = s.getByArgs(**s) if st_exist: if st_has_cl.insert(): information = model.Information_model.query('select \ distinct(exam_ex_id),sg_id from information where \ class_cl_id = %s' % (params.cl_id)) if information != None: information = [ model.Information_model(**item) for item in information ] for item in information: item.class_cl_id = params.cl_id item.student_st_id = params.st_id item.insert() else: print "none" response = util.Response(Status.__success__, message="该学生已添加进课程班级") return util.objtojson(response) response = util.Response(Status.__success__, message="该学生已存在于课程班级,不能重复添加!") return util.objtojson(response) else: s = Student_model(**params) s.insert() st_has_cl.insert() information = model.Information_model.query('select \ distinct(exam_ex_id),sg_id from information where \ class_cl_id = %s' % (params.cl_id)) if information != None: information = [ model.Information_model(**item) for item in information ] for item in information: item.class_cl_id = params.cl_id item.student_st_id = params.st_id item.insert() else: print "none" response = util.Response(Status.__success__, message="该学生已添加进课程班级!") return util.objtojson(response) except Exception as e: response = util.Response(Status.__error__, message="error") return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin", "*") # 接收参数 teacher = model.Teacher_model.query('select * from teacher') teacher = [model.Teacher_model(**item) for item in teacher] response = util.Response(status=util.Status.__success__, body=teacher) print(util.objtojson(response)) return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin", "*") # 接收参数 Knowledge = model.Knowledge_model.query('select * from knowledge') Knowledge = [model.Teacher_model(**item) for item in Knowledge] response = util.Response(status=util.Status.__success__, body=Knowledge) print(util.objtojson(response)) return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin", "*") params = web.input() exam = model.Exam_model() must_params = exam.__notnull__ if (util.paramsok(must_params, params) == 2): response = util.Response(status=util.Status.__params_not_ok__) return util.objtojson(response) else: exam = model.Exam_model(**params) if exam.update(): # 获取教务班学生id stuHasClass = model.Student_has_class_model() classId = params['add_class_cl_id'].encode('utf-8') classId = classId.split(',') print 'add_class_cl_id' print classId for k in range(1, len(classId) - 1): print 1234567 print classId[k] listStuid = stuHasClass.getByArgs(class_cl_id=classId[k]) for stuID in listStuid: informationArgs = dict( student_st_id=stuID.student_st_id, exam_ex_id=exam.ex_id, class_cl_id=classId[k], sg_id=exam.strategy_sg_id) information = model.Information_model( **informationArgs) information.insert() delete_classId = params['delete_class_cl_id'].encode('utf-8') delete_classId = delete_classId.split(',') print 'delete_class_cl_id' print delete_classId for k in range(1, len(delete_classId) - 1): listStuid = stuHasClass.getByArgs( class_cl_id=delete_classId[k]) for stuID in listStuid: # informationArgs = dict(student_st_id=stuID.student_st_id, exam_ex_id=exam.ex_id, # class_cl_id=delete_classId[k]) # information = model.Information_model() # information_id = information.getByArgs(informationArgs) # information.in_id = information_id[0]['in_id'] # information.delete() db.delete('information', where="student_st_id = $student_st_id \ and exam_ex_id = $exam_ex_id", vars={ 'student_st_id': stuID.student_st_id, 'exam_ex_id': exam.ex_id }) response = util.Response(status=util.Status.__success__) return util.objtojson(response) else: response = util.Response(status=util.Status.__error__) return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin", "*") mydata = web.input() #mydata={'qb_id': 1081} print(mydata) qb = model.Questions_bank_model() response = qb.getByArgs(qb_id=mydata['qb_id']) print("返回值: ", util.objtojson(response)) return util.objtojson(response)
def GET(self): print("getclass--------------") web.header("Access-Control-Allow-Origin", "*") class_info = Class_model.query('select * from class') class_info = [Class_model(**item) for item in class_info] response = util.Response(status=util.Status.__success__, body=class_info) print(util.objtojson(response)) return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin", "*") # 接收参数 params = web.input() print params teacher = model.Teacher_model(**params) if teacher.delete(): response = util.Response(status=util.Status.__success__, ) return util.objtojson(response) else: response = util.Response(status=util.Status.__error__, ) return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin", "*") # 接收参数 params = web.input() exam = model.Exam_model(**params) exam.delete() if exam.getByArgs(**params): response = util.Response(status=util.Status.__error__) return util.objtojson(response) else: response = util.Response(status=util.Status.__success__) return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin", "*") # 接收参数 params = web.input() params.setdefault("in_state", '1') params.setdefault("in_ip", web.ctx.ip) information = model.Information_model(**params) if information.update(): response = util.Response(status=util.Status.__error__) return util.objtojson(response) else: response = util.Response(status=util.Status.__success__) return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin", "*") mydata = web.input() print('printexam--------------', mydata) exam_list = Exam_model.query( 'select * from exam where ex_id in (select distinct exam_ex_id from \ information where class_cl_id = %s)' % (int(mydata.cl_id))) exam_list = [Exam_model(**item) for item in exam_list] response = util.Response(status=util.Status.__success__, body=exam_list) print(util.objtojson(response)) return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin", "*") information = model.Information_model() session = web.ctx.session information_data = information.query( 'SELECT * FROM information WHERE \ student_st_id=%s and exam_ex_id=%s' % (session.student_id, session.ex_id)) information = model.Information_model(**information_data[0]) information.in_endtime = datetime.datetime.now() information.in_state = '2' information.in_temp_ip = None exam = model.Exam_model.getByPK(session.ex_id) if exam.ex_type == "0": util.SaveFillb(information.in_id) db.update( 'exam_question', where="information_in_id = %s" % (information.in_id), eq_get_score='-2', ) # information.in_score = util.upInformationScore(1000,information.in_id) # while 1: # exam_question = model.Exam_question_model.getByArgs(information_in_id=information.in_id) # information.in_score = 0 # flag = 0 # for question in exam_question: # if question.eq_get_score >= 0: # information.in_score += question.eq_get_score # else: # flag = 1 # break # if flag == 0: # break # information.in_state = '0' information.update() response = util.Response(status=util.Status.__params_ok__, message=information.in_score) return util.objtojson(response) else: if exam.ex_auto == "1": util.SaveFillb(information.in_id) db.update( 'exam_question', where="information_in_id = %s" % (information.in_id), eq_get_score='-2', ) thread.start_new(util.GetScore, (1, information.in_id)) information.update() response = util.Response(status=util.Status.__success__, ) return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin", "*") params = web.input() print params information=model.Information_model.getByPK(params.in_id) try: minutes = datetime.timedelta(minutes=int(params.delay_time)) information.in_endtime += minutes information.update() except: response = util.Response(status=util.Status.__error__, ) return util.objtojson(response) response = util.Response(status=util.Status.__success__,) return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin", "*") params = web.input() information=model.Information_model.getByPK(params.in_id) try: information.in_state ='3' information.in_score = 0 information.update() db.update('exam_question', where="information_in_id=%s"%(params.in_id), eq_get_score=0, ) except: response = util.Response(status=util.Status.__error__, ) return util.objtojson(response) response = util.Response(status=util.Status.__success__,) return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin", "*") params = web.input() print params information=model.Information_model.getByPK(params.in_id) try: information.in_ip =None information.in_temp_ip = None information.update() except: response = util.Response(status=util.Status.__error__, ) return util.objtojson(response) response = util.Response(status=util.Status.__success__,) return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin", "*") # 接收参数 params = web.input() session = web.ctx.session teacher = model.Teacher_model.getByArgs(tc_id=params.tc_id) if teacher[0].tc_password != params.password: response = util.Response(status=util.Status.__error__, message="password_error") return util.objtojson(response) else: session.username = params.tc_id response = util.Response(status=util.Status.__success__, ) return util.objtojson(response)