def POST(self): mydata = web.input() qt = model.Question_model() kp = model.Knowledge_model() web.header("Access-Control-Allow-Origin", "*") qbhq = model.Questions_bank_has_question_model() must_params = set({ 'qt_id', 'qt_type', 'qt_stem', 'kl_name', 'qb_id', }) if (util.paramsok(must_params, mydata) == 2): response = util.Response(status=util.Status.__params_not_ok__) return util.objtojson(response) else: knowlagedata = kp.getByArgs(kl_name=mydata.kl_name) qt = model.Question_model(**mydata) qt.knowledge_kl_id = knowlagedata[0].kl_id qt.qt_state = 0 qt.update() if mydata.qt_type == 'choice': choice = model.Choice_model(**mydata) choice.question_qt_id = qt.qt_id choice.update() response = util.Response(status=util.Status.__success__) return util.objtojson(response) elif mydata.qt_type == 'coding': coding = model.Coding_model(**mydata) coding.question_qt_id = qt.qt_id coding.update() # shutil.rmtree('%s/%s' % (question_source, qt.qt_id)) response = util.Response(status=util.Status.__success__) return util.objtojson(response) elif mydata.qt_type == 'filla': Filla = model.Filla_model(**mydata) Filla.question_qt_id = qt.qt_id Filla.update() response = util.Response(status=util.Status.__success__) return util.objtojson(response) elif mydata.qt_type == 'fillb': Fillb = model.Fillb_model(**mydata) Fillb.question_qt_id = qt.qt_id Fillb.update() response = util.Response(status=util.Status.__success__) return util.objtojson(response) elif mydata.qt_type == 'judge': Judge = model.Judge_model(**mydata) Judge.question_qt_id = qt.qt_id Judge.update() response = util.Response(status=util.Status.__success__) return util.objtojson(response)
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)'] while 1: 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: 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(): qt.insert() reasurt = qt.query('select max(qt_id) from question') Fillb.question_qt_id = reasurt[0]['max(qt_id)'] qt.qt_id = Fillb.question_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.replace('&&&',' ') result = exam_question.insertBackid() eq_id = result[0]['max(eq_id)'] while 1: 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: 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() qt = model.Question_model() recover_question = model.Question_model.getByPK(mydata.qt_id) recover_coding = model.Coding_model.getByPK(mydata.qt_id) recover_fillb = model.Fillb_model.getByPK(mydata.qt_id) kp = model.Knowledge_model() web.header("Access-Control-Allow-Origin", "*") must_params = set({ 'qt_id', 'qt_type', 'qt_stem', 'kl_name', 'qb_id', }) if (util.paramsok(must_params, mydata) == 2): response = util.Response(status=util.Status.__params_not_ok__) return util.objtojson(response) else: knowlagedata = kp.getByArgs(kl_name=mydata.kl_name) qt = model.Question_model(**mydata) qt.knowledge_kl_id = knowlagedata[0].kl_id qt.qt_state = 0 qt.update() if mydata.qt_type == 'choice': choice = model.Choice_model(**mydata) choice.question_qt_id = qt.qt_id choice.update() response = util.Response(status=util.Status.__success__) return util.objtojson(response) elif mydata.qt_type == 'coding': coding = model.Coding_model(**mydata) coding.question_qt_id = qt.qt_id coding.update() exam_question = model.Exam_question_model() exam_question.information_in_id = 1 exam_question.qt_id = qt.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: recover_coding.update() recover_question.update() qt.update() response = util.Response(status=util.Status.__error__) return util.objtojson(response) elif mydata.qt_type == 'filla': Filla = model.Filla_model(**mydata) Filla.question_qt_id = qt.qt_id Filla.update() response = util.Response(status=util.Status.__success__) return util.objtojson(response) elif mydata.qt_type == 'fillb': Fillb = model.Fillb_model(**mydata) Fillb.question_qt_id = qt.qt_id Fillb.update() exam_question = model.Exam_question_model() exam_question.information_in_id = 1 exam_question.qt_id = qt.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( '&&&', ' ') 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: recover_fillb.update() recover_question.update() qt.update() 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) Judge.question_qt_id = qt.qt_id Judge.update() response = util.Response(status=util.Status.__success__) return util.objtojson(response)
def POST(self): mydata = web.input() print(mydata) # print mydata['qt_stem'].encode("utf-8") qt = model.Question_model() web.header("Access-Control-Allow-Origin", "*") qbhq = model.Questions_bank_has_question_model() qb = model.Questions_bank_model() print(mydata['questions_bank_qb_id']) qb = qb.getByArgs(qb_id=mydata['questions_bank_qb_id']) # print(qb) # print(qb[0]['qb_lang']) mydata['qt_lang'] = qb[0]['qb_lang'] # print("更新后的mydata: ", mydata) 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) # 编程题加题时需要把题目先加入到exam_question表,判题系统取出题目进行判题,如果判题成功则加入到question表 elif mydata.qt_type == 'coding': # qb = model.Questions_bank_model() # print(mydata['questions_bank_qb_id']) # qb = qb.getByArgs(qb_id=mydata['questions_bank_qb_id']) #mydata['eq_lang'] = qb[0]['qb_lang'] #print("更改后的mydata",mydata) coding = model.Coding_model(**mydata) # 实例化一个编程题 with orm.db.transaction(): qt.insert() # 插入到question表 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() # 插入到coding表 qbhq.question_qt_id = coding.question_qt_id qbhq.questions_bank_qb_id = mydata.questions_bank_qb_id result = qbhq.insertBackid() # 插入到qbhd表 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表 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' # -2为待判题状态 exam_question.eq_answer = coding.co_test_coding exam_question.eq_lang = qb[0]['qb_lang'] result = exam_question.insertBackid() # 插入到exam_question表 eq_id = result[0]['max(eq_id)'] for i in range(60): # 判题最大时长为1分钟 time.sleep(1) exam_question = model.Exam_question_model.getByPK(eq_id) if exam_question.eq_get_score == 100: # 判题成功,判题系统将该字段变为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) # 程序填空题加题时需要把题目先加入到exam_question表,判题系统取出题目进行判题,如果判题成功则加入到question表 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.eq_lang = qb[0]['qb_lang'] exam_question.fillb_coding = Fillb.fb_pre_coding.replace( '&&&', ' ') # util.getFileRotatingLog().debug(exam_question.fillb_coding) #写入到log文件 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) # 返回一个对象,status = 1