def POST(self): mydata = web.input() 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) 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 GET(self): web.header("Access-Control-Allow-Origin", "*") # 接收参数 params = web.input() try: session = web.ctx.session username = session.username # util.getFileRotatingLog().debug(username) if not username: response = util.Response(status=util.Status.__not_login__, message='4') return util.objtojson(response) except Exception as e: print e util.getFileRotatingLog().debug(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',) 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 POST(self): mydata = web.input() print("删除题目", mydata) qbhq = model.Questions_bank_has_question_model() web.header("Access-Control-Allow-Origin", "*") must_params = set({'qt_id'}) #util.getFileRotatingLog().debug(mydata) session = web.ctx.session teacher = model.Teacher_model.getByArgs(tc_level='管理员') try: if (util.paramsok(must_params, mydata) == 2): response = util.Response(status=util.Status.__params_not_ok__) return util.objtojson(response) elif mydata.qb_id == "all": if str(mydata.deletepassword) == teacher[0].tc_password: result = qbhq.getByArgs(question_qt_id=mydata.qt_id) for k in result: qbhq.qbhq_id = k.qbhq_id qbhq.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: if str(mydata.deletepassword) == teacher[0].tc_password: result = qbhq.query( 'select * from questions_bank_has_question where question_qt_id = %s \ and questions_bank_qb_id = %s' % (mydata.qt_id, mydata.qb_id)) qbhq = model.Questions_bank_has_question_model(**result[0]) qbhq.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) except Exception as e: util.getFileRotatingLog().debug(e) response = util.Response(status=util.Status.__error__, message="删除失败") return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin", "*") # 接收参数 params = web.input() util.getFileRotatingLog().debug(params) strategy = model.Strategy_model(**params) teacher = model.Teacher_model.getByArgs(tc_level='管理员') if str(params.deletepassword) != teacher[0].tc_password: response = util.Response(status=util.Status.__error__, message="密码错误") return util.objtojson(response) try: with orm.db.transaction(): db.delete('strategy_term', where="strategy_sg_id = $strategy_sg_id", vars={'strategy_sg_id': params.sg_id, }) if strategy.delete(): response = util.Response(status=util.Status.__success__, message="删除成功!") return util.objtojson(response) else: response = util.Response(status=util.Status.__error__, message="删除失败!") return util.objtojson(response) except Exception as e: util.getFileRotatingLog().debug(e) response = util.Response(status=util.Status.__error__, message="删除失败!") return util.objtojson(response)
#!/usr/bin/env python
#!/usr/bin/env python
def POST(self): mydata = web.input() # print mydata['qt_stem'].encode("utf-8") qt = model.Question_model() web.header("Access-Control-Allow-Origin", "*") qbhq = model.Questions_bank_has_question_model() must_params = qt.__notnull__ if (util.paramsok(must_params, mydata) == 2): response = util.Response(status=util.Status.__params_not_ok__) return util.objtojson(response) else: qt = model.Question_model(**mydata) if mydata.qt_type == 'choice': choice = model.Choice_model(**mydata) with orm.db.transaction(): qt.insert() reasurt = qt.query('select max(qt_id) from question') choice.question_qt_id = int(reasurt[0]['max(qt_id)']) choice.insert() qbhq.question_qt_id = choice.question_qt_id qbhq.questions_bank_qb_id = mydata.questions_bank_qb_id qbhq.insert() response = util.Response(status=util.Status.__success__) return util.objtojson(response) elif mydata.qt_type == 'coding': coding = model.Coding_model(**mydata) with orm.db.transaction(): qt.insert() reasurt = qt.query('select max(qt_id) from question') coding.question_qt_id = reasurt[0]['max(qt_id)'] qt.qt_id = coding.question_qt_id coding.insert() qbhq.question_qt_id = coding.question_qt_id qbhq.questions_bank_qb_id = mydata.questions_bank_qb_id result = qbhq.insertBackid() qbhq.qbhq_id = result[0]['max(qbhq_id)'] # os.mkdir('%s/%s'%(question_source,coding.question_qt_id)) # test_in = coding.co_test_answer_in.split('&&&') # test_out = coding.co_test_answer_out.split('&&&') # for k in range(1, len(test_in) - 1): # with open('%s/%s/%s.in' % (question_source,coding.question_qt_id,k), 'w') as f: # f.write(test_in[k]) # with open('%s/%s/%s.out' % (question_source,coding.question_qt_id,k), 'w') as f: # f.write("%s"%test_out[k]) exam_question = model.Exam_question_model() exam_question.information_in_id = 1 exam_question.qt_id = qbhq.question_qt_id exam_question.eq_qt_type = 'coding' exam_question.eq_pre_score = 100 exam_question.eq_get_score = '-2' exam_question.eq_answer = coding.co_test_coding result = exam_question.insertBackid() eq_id = result[0]['max(eq_id)'] for i in range(60): time.sleep(1) exam_question = model.Exam_question_model.getByPK(eq_id) if exam_question.eq_get_score == 100: response = util.Response( status=util.Status.__success__) return util.objtojson(response) if exam_question.eq_get_score == 0 or i == 59: exam_question.delete() qbhq.delete() coding.delete() qt.delete() response = util.Response(status=util.Status.__error__) return util.objtojson(response) elif mydata.qt_type == 'filla': Filla = model.Filla_model(**mydata) with orm.db.transaction(): qt.insert() reasurt = qt.query('select max(qt_id) from question') Filla.question_qt_id = reasurt[0]['max(qt_id)'] Filla.insert() qbhq.question_qt_id = Filla.question_qt_id qbhq.questions_bank_qb_id = mydata.questions_bank_qb_id qbhq.insert() response = util.Response(status=util.Status.__success__) return util.objtojson(response) elif mydata.qt_type == 'fillb': Fillb = model.Fillb_model(**mydata) with orm.db.transaction(): Fillb.question_qt_id = qt.qt_id = qt.insertBackid( )[0]['max(qt_id)'] Fillb.insert() qbhq.question_qt_id = Fillb.question_qt_id qbhq.questions_bank_qb_id = mydata.questions_bank_qb_id result = qbhq.insertBackid() qbhq.qbhq_id = result[0]['max(qbhq_id)'] # os.mkdir('%s/%s' % (question_source,Fillb.question_qt_id)) # test_in = Fillb.fb_test_answer_in.split('&&&') # test_out = Fillb.fb_test_answer_out.split('&&&') # for k in range(1, len(test_in) - 1): # # with open('../examTransplant1.7/source/question/%s/%s.in' % (Fillb.question_qt_id, k), 'w') as f: # with open('%s/%s/%s.in' % (question_source,Fillb.question_qt_id, k), 'w') as f: # f.write(test_in[k]) # with open('%s/%s/%s.out' % (question_source,Fillb.question_qt_id, k), 'w') as f: # f.write("%s" % test_out[k]) exam_question = model.Exam_question_model() exam_question.information_in_id = 1 exam_question.qt_id = qbhq.question_qt_id exam_question.eq_qt_type = 'fillb' exam_question.eq_pre_score = 100 exam_question.eq_get_score = '-2' exam_question.eq_answer = Fillb.fb_pre_coding exam_question.fillb_coding = Fillb.fb_pre_coding.replace( '&&&', ' ') util.getFileRotatingLog().debug(exam_question.fillb_coding) result = exam_question.insertBackid() eq_id = result[0]['max(eq_id)'] for i in range(60): time.sleep(1) exam_question = model.Exam_question_model.getByPK(eq_id) if exam_question.eq_get_score == 100: response = util.Response( status=util.Status.__success__) return util.objtojson(response) if exam_question.eq_get_score == 0 or i == 59: exam_question.delete() qbhq.delete() Fillb.delete() qt.delete() response = util.Response(status=util.Status.__error__) return util.objtojson(response) response = util.Response(status=util.Status.__success__) return util.objtojson(response) elif mydata.qt_type == 'judge': Judge = model.Judge_model(**mydata) # print qt with orm.db.transaction(): qt.insert() reasurt = qt.query('select max(qt_id) from question') Judge.question_qt_id = reasurt[0]['max(qt_id)'] Judge.insert() qbhq.question_qt_id = Judge.question_qt_id qbhq.questions_bank_qb_id = mydata.questions_bank_qb_id qbhq.insert() response = util.Response(status=util.Status.__success__) return util.objtojson(response)
def POST(self): mydata = web.input() print mydata # 必须有的参数 must_params = set({'questions_bank_qb_id', 'currentPage'}) web.header("Access-Control-Allow-Origin", "*") currentPage = int(mydata.currentPage) - 1 if (util.paramsok(must_params, mydata) == 2): print 333 response = util.Response(status=util.Status.__params_not_ok__) return util.objtojson(response) else: question = model.Question_model() # result = orm.db.query('select * from question where qt_id in (select question_qt_id from questions_bank_has_question where questions_bank_qb_id = %s ) order by qt_id limit %s,%s'%(int(mydata.questions_bank_qb_id),currentPage*10,currentPage*10+9)) result = orm.db.query( 'select * from question where qt_id in \ (select question_qt_id from questions_bank_has_question where questions_bank_qb_id = %s )\ order by qt_id limit %s,%s' % (mydata.questions_bank_qb_id, currentPage * 10, 10)) questionlist = [] result = [model.Question_model(**item) for item in result] # print result count = dict() total_num = question.query( 'select count(*) from question where qt_id in (select question_qt_id \ from questions_bank_has_question where questions_bank_qb_id = %s )' % (mydata.questions_bank_qb_id)) # print result1[0] choice_num = question.query( 'select count(*) from question where qt_id in (select question_qt_id \ from questions_bank_has_question where questions_bank_qb_id = %s ) and qt_type = \'choice\'' % (mydata.questions_bank_qb_id)) coding_num = question.query( 'select count(*) from question where qt_id in (select question_qt_id \ from questions_bank_has_question where questions_bank_qb_id = %s ) and qt_type = \'coding\'' % (mydata.questions_bank_qb_id)) filla_num = question.query( 'select count(*) from question where qt_id in (select question_qt_id \ from questions_bank_has_question where questions_bank_qb_id = %s ) \ and qt_type = \'filla\'' % (mydata.questions_bank_qb_id)) fillb_num = question.query( 'select count(*) from question where qt_id in (select question_qt_id \ from questions_bank_has_question where questions_bank_qb_id = %s ) \ and qt_type = \'fillb\'' % (mydata.questions_bank_qb_id)) judge_num = question.query( 'select count(*) from question where qt_id in (select question_qt_id \ from questions_bank_has_question where questions_bank_qb_id = %s ) \ and qt_type = \'judge\'' % (mydata.questions_bank_qb_id)) count['total_num'] = total_num[0]['count(*)'] count['choice_num'] = choice_num[0]['count(*)'] count['coding_num'] = coding_num[0]['count(*)'] count['filla_num'] = filla_num[0]['count(*)'] count['fillb_num'] = fillb_num[0]['count(*)'] count['judge_num'] = judge_num[0]['count(*)'] util.getFileRotatingLog().debug(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=int(count['total_num']), currentPage=int(mydata.currentPage), pageSize=10, status=util.Status.__success__, message=count) response = util.Response(status=util.Status.__success__, body=page) return util.objtojson(response)
def POST(self): web.header("Access-Control-Allow-Origin", "*") x = web.input(myfile={}) #获得文件流 must_params = ('cl_id', ) file_range = [ 'xls', 'xlsx', ] if util.paramsok(must_params, x) == Status.__params_not_ok__: return util.objtojson({"error": "参数错误"}) # excel_save_site = "../examTransplant1.7/source/excel" excel_save_site = student_source current_site = os.getcwd() print current_site current_site = current_site.replace('\\', '/') real_site = current_site.split('/') save_site = excel_save_site.split('/') flag = 1 i = -1 # print(real_site) # print(save_site) while i > -4: if real_site[i] != save_site[i]: flag = 0 break # print(i) i = i - 1 print(flag) if flag == 0: try: os.chdir(excel_save_site) except: print('os.chdir error') os.chdir(current_site) return 0 if 'myfile' in x: filepath = x.myfile.filename.replace('\\', '/') filename = unicode(filepath.split('/')[-1], 'utf-8') # import time # filename = int(time.time()) file_suffix = filename.split('.')[-1] file_truth = 0 for i in range(len(file_range)): if file_suffix == file_range[i]: file_truth = 1 if file_truth == 1: origin_site = os.getcwdu() try: # try: # str = x.myfile.file.read() # str = str.decode('ascii') # # util.getFileRotatingLog().debug(str) # util.getFileRotatingLog().debug(type(str)) # except BaseException as e: # util.getFileRotatingLog().debug(e) with open( origin_site + '/' + filename, 'wb+' ) as fout: # creates the file where the uploaded file should be stored fout.write( x.myfile.file.read() ) # writes the uploaded file to the newly created file. file_site = origin_site + '/' + filename except BaseException as e: util.getFileRotatingLog().debug(e) os.chdir(current_site) return util.objtojson({"error": "文件上传失败!"}) try: data = xlrd.open_workbook(file_site) table = data.sheets()[0] nrows = table.nrows params = dict.fromkeys(Student_model.__attr__) for i in range(5, nrows - 1): #行数 if i > 0: try: params['st_id'] = int(table.row_values(i)[1]) params['st_name'] = table.row_values(i)[2] params['st_sex'] = table.row_values(i)[3] params['st_specialty'] = table.row_values(i)[4] params['st_phone'] = table.row_values(i)[5] params['st_picture'] = table.row_values(i)[6] params = Student_model(**params) except Exception as e: continue try: params.insert() db.insert("student_has_class", student_st_id=params['st_id'], class_cl_id=x.cl_id) except Exception as e: util.getFileRotatingLog().debug(e) os.chdir(current_site) return 1 except BaseException as e: util.getFileRotatingLog().debug(e) r = {"success": 0, "error": "导入数据库失败"} os.chdir(current_site) return util.objtojson(r) else: os.chdir(current_site) return 0 else: os.chdir(current_site) return 0