def addTest(): if request.method == 'POST': req = request.values testName = req['testName'] paperName = req['paperName'] beginTimeStr = req['beginTime'] endTimeStr = req['endTime'] diseaseName = req['diseaseName'] beginTime = datetime.strptime(beginTimeStr, '%Y%m%d %H:%M') endTime = datetime.strptime(endTimeStr, '%Y%m%d %H:%M') #略过数据合法性检测 testNameD = Test.query.filter_by(testName=testName).first() if (testNameD): return ops_renderErrJSON(msg="相同考试已存在,请再换一个试试") #写入数据库 model_test = Test() model_test.testName = testName model_test.paperName = paperName model_test.beginTime = beginTime model_test.endTime = endTime model_test.diseaseName = diseaseName db.session.add(model_test) db.session.commit() temp = {} temp["testName"] = testName temp["paperName"] = paperName temp["beginTime"] = beginTime temp["endTime"] = endTime temp["diseaseName"] = diseaseName data = [] data.append(temp) return ops_renderJSON(msg="添加成功", data=data) return "添加成功"
def addAnimal(): # html文件修改为新建题目的文件 if request.method == "GET": return render_template("提交宠物.html") elif request.method == "POST": req = request.values # 暂时略过合法性检测 animalName = req['animalName'] age = req['age'] temper = req['temper'] breathe = req['breathe'] heartRate = req['heartRate'] animalNameD = Animal.query.filter_by(animalName=animalName).first() if animalNameD: return ops_renderErrJSON(msg="相同名字已存在,请再换一个试试") # 注册写入数据库 model_animal = Animal() model_animal.age = age model_animal.animalName = animalName model_animal.temper = temper model_animal.breathe = breathe model_animal.heartRate = heartRate db.session.add(model_animal) db.session.commit() # json化data temp = {} temp["animalName"] = animalName temp["age"] = age temp["temper"] = temper temp["breathe"] = breathe temp["heartRate"] = heartRate data = [] data.append(temp) return ops_renderJSON(msg="添加成功", data=data) return "添加成功"
def addDisease(): # html文件修改为新建题目的文件 if request.method == "GET": return render_template("提交疾病.html") elif request.method == "POST": req = request.values # 暂时略过合法性检测 diseaseName = req['diseaseName'] categoryName = req['categoryName'] diseaseNameD = Disease.query.filter_by(diseaseName=diseaseName).first() if diseaseNameD: return ops_renderErrJSON(msg="相同名字已存在,请再换一个试试") # 注册写入数据库 model_disease = Disease() model_disease.diseaseName = diseaseName model_disease.categoryName = categoryName db.session.add(model_disease) db.session.commit() # json化data temp = {} temp["diseaseName"] = diseaseName temp["categoryName"] = categoryName data = [] data.append(temp) return ops_renderJSON(msg="添加成功", data=data) return "添加成功"
def searchCategory(): if request.method == 'POST': result = Category.query.all() temp = {} data = [] if (len(result) != 0): for i in result: temp["categoryID"] = i.categoryID temp["categoryName"] = i.categoryName data.append(temp.copy()) return ops_renderJSON(msg="查询成功", data=data) else: return ops_renderErrJSON(msg="查询失败,目前没有分类")
def updateCategory(): if request.method == 'POST': req = request.values categoryNameOld = req['categoryNameOld'] categoryNameNew = req['categoryNameNew'] categoryNameD = db.session.query(Category).filter_by( categoryName=categoryNameNew).first() if categoryNameD: return ops_renderErrJSON(msg="分类已经存在,请换一个再试试。") else: categoryNameU = db.session.query(Category).filter_by( categoryName=categoryNameOld).first() if categoryNameU: categoryNameU.categoryName = categoryNameNew db.session.commit() # json化data temp = {} temp["categoryName"] = categoryNameNew data = [] data.append(temp) return ops_renderJSON(msg="修改成功", data=data) else: return ops_renderErrJSON(msg="不存在这个分类,无法修改") return "修改成功"
def listTest(): if request.method == 'POST': result = Test.query.all() temp = {} data = [] if (len(result) != 0): for i in result: temp["testName"] = i.testName temp["paperName"] = i.paperName temp["beginTime"] = i.beginTime temp["endTime"] = i.endTime temp["diseaseName"] = i.diseaseName data.append(temp.copy()) return ops_renderJSON(msg="查询成功", data=data) else: return ops_renderErrJSON(msg="查询失败,目前没有考试")
def searchCategory(): if request.method == 'POST': result = db.session.query(Animal).all() temp = {} data = [] if (len(result) != 0): for i in result: temp["animalName"] = i.animalName temp["age"] = i.age temp["temper"] = i.temper temp["breathe"] = i.breathe temp["heartRate"] = i.heartRate data.append(temp.copy()) return ops_renderJSON(msg="查询成功", data=data) else: return ops_renderErrJSON(msg="查询失败,目前没有分类")
def listDisease(): if request.method == 'POST': result = db.session.query(Disease).all() temp = {} data = [] if (len(result) != 0): for i in result: temp["diseaseId"] = i.diseaseId temp["diseaseName"] = i.diseaseName temp["categoryName"] = i.categoryName data.append(temp.copy()) return ops_renderJSON(msg="查询成功", data=data) else: return ops_renderErrJSON(msg="查询失败,目前没有疾病") return ops_renderJSON(msg="添加成功")
def searchCase(): if request.method == 'POST': result = db.session.query(Case).all() temp = {} data = [] if (len(result) != 0): for i in result: temp["caseName"] = i.caseName temp["diseaseName"] = i.diseaseName temp["diseaseInfo"] = i.diseaseInfo temp["animalName"] = i.animalName temp["videoUrl"] = i.videoUrl temp["imageUrl"] = i.imageUrl data.append(temp.copy()) return ops_renderJSON(msg="查询成功", data=data) else: return ops_renderErrJSON(msg="查询失败,目前没有分类")
def addQuestion(): # html文件修改为新建题目的文件 if request.method == "GET": return render_template("提交题目.html") elif request.method == "POST": req = request.values # 暂时略过合法性检测 questionInfo = req['questionInfo'] answer = req['answer'] diseaseName = req['diseaseName'] score = req['score'] choiceA = req['choiceA'] choiceB = req['choiceB'] choiceC = req['choiceC'] choiceD = req['choiceD'] questionInfoD = Question.query.filter_by( questionInfo=questionInfo).first() if questionInfoD: return ops_renderErrJSON(msg="相同题干已存在,请再换一个试试") # 注册写入数据库 model_question = Question() model_question.questionInfo = questionInfo model_question.choiceA = choiceA model_question.choiceB = choiceB model_question.choiceC = choiceC model_question.choiceD = choiceD model_question.answer = answer model_question.score = score model_question.diseaseName = diseaseName db.session.add(model_question) db.session.commit() # json化data temp = {} temp["questionInfo"] = questionInfo temp["answer"] = answer temp["choiceA"] = choiceA temp["choiceB"] = choiceB temp["choiceC"] = choiceC temp["choiceD"] = choiceD temp["score"] = score temp["diseaseName"] = diseaseName data = [] data.append(temp) return ops_renderJSON(msg="添加成功", data=data) return "添加成功"
def searchDisease(): if request.method == 'POST': req = request.values categoryName = req['categoryName'] result = Disease.query.filter_by(categoryName=categoryName).all() temp = {} data = [] if (len(result) != 0): for i in result: temp["diseaseId"] = i.diseaseId temp["diseaseName"] = i.diseaseName temp["categoryName"] = i.categoryName data.append(temp.copy()) return ops_renderJSON(msg="查询成功", data=data) else: return ops_renderErrJSON(msg="查询失败,目前该分类没有疾病") return ops_renderJSON(msg="查询成功")
def listQuestion(): if request.method == 'POST': result = Question.query.all() temp = {} data = [] if (result != None): for i in result: temp["questionInfo"] = i.questionInfo temp["answer"] = i.answer temp["choiceA"] = i.choiceA temp["choiceB"] = i.choiceB temp["choiceC"] = i.choiceC temp["choiceD"] = i.choiceD temp["score"] = i.score temp["diseaseName"] = i.diseaseName data.append(temp.copy()) return ops_renderJSON(msg="查询成功", data=data) else: return ops_renderErrJSON(msg="查询失败,目前没有题目")
def searchTest(): if request.method == 'POST': req = request.values testName = req['testName'] result = Test.query.filter_by(testName=testName).all() temp = {} data = [] if (len(result) != 0): for i in result: temp["testName"] = i.testName temp["paperName"] = i.paperName temp["beginTime"] = i.beginTime temp["endTime"] = i.endTime temp["diseaseName"] = i.diseaseName data.append(temp.copy()) return ops_renderJSON(msg="查询成功", data=data) else: return ops_renderErrJSON(msg="查询失败,目前没有这场考试") return ops_renderJSON(msg="查询成功")
def addExecutes(): # html文件修改为新建题目的文件 if request.method == "GET": return render_template("提交执行类项目.html") elif request.method == "POST": req = request.values # 暂时略过合法性检测 name = req['name'] type = req['type'] pay = req['pay'] nameD = Executes.query.filter_by(name=name).first() if nameD: return ops_renderErrJSON(msg="相同项目已存在,请再换一个试试") # 注册写入数据库 model_executes = Executes() model_executes.type = type model_executes.name = name model_executes.pay = pay db.session.add(model_executes) db.session.commit() return ops_renderJSON(msg="添加成功") return "添加成功"
def register(): # 注册界面还没拿到,先用index.html代替 if request.method == "GET": return render_template("index.html") elif request.method == "POST": req = request.values username = req['user_name'] password = req['user_password'] # 这里应该判断一下用户名和密码的合法性,但是暂时略过 # 以下为查询语句,first()表示返回查到符合条件的第一条数据 # 找到第一个同名的用户名 usernameD = User.query.filter_by(userName=username).first() if usernameD: return ops_renderErrJSON(msg="用户名已经存在,请换一个再试试。") # 以下为注册语句并写入数据库 model_user = User() model_user.userName = username model_user.passWord = password db.session.add(model_user) db.session.commit() return ops_renderJSON(msg="注册成功~~") return "注册成功"
def addCase(): # html文件修改为新建题目的文件 if request.method == "GET": return render_template("提交病例.html") elif request.method == "POST": req = request.values # 暂时略过合法性检测 caseName = req['caseName'] animalName = req['animalName'] diseaseName = req['diseaseName'] diseaseInfo = req['diseaseInfo'] videoUrl = req['videoUrl'] imageUrl = req['imageUrl'] caseNameD = Case.query.filter_by(caseName=caseName).first() if caseNameD: return ops_renderErrJSON(msg="相同题干已存在,请再换一个试试") # 注册写入数据库 model_case = Case() model_case.caseName = caseName model_case.diseaseName = diseaseName model_case.diseaseinfo = diseaseInfo model_case.animalName = animalName model_case.videoUrl = videoUrl model_case.imageUrl = imageUrl db.session.add(model_case) db.session.commit() # json化data temp = {} temp["caseName"] = caseName temp["diseaseName"] = diseaseName temp["diseaseInfo"] = diseaseInfo temp["animalName"] = animalName temp["videoUrl"] = videoUrl temp["imageUrl"] = imageUrl data = [] data.append(temp) return ops_renderJSON(msg="添加成功", data=data) return "添加成功"
def searchQuestion(): if request.method == 'POST': req = request.values diseaseName = req['diseaseName'] result = Question.query.filter_by(diseaseName=diseaseName).all() temp = {} data = [] if (len(result) != 0): for i in result: temp["questionInfo"] = i.questionInfo temp["answer"] = i.answer temp["choiceA"] = i.choiceA temp["choiceB"] = i.choiceB temp["choiceC"] = i.choiceC temp["choiceD"] = i.choiceD temp["score"] = i.score temp["diseaseName"] = i.diseaseName data.append(temp.copy()) return ops_renderJSON(msg="查询成功", data=data) else: return ops_renderErrJSON(msg="查询失败,目前该病种没有试题") return ops_renderJSON(msg="查询成功")
def addCategory(): # html文件修改为新建题目的文件 if request.method == "GET": return render_template("提交分类.html") elif request.method == "POST": req = request.values # 暂时略过合法性检测 categoryName = req['categoryName'] categoryNameD = Category.query.filter_by( categoryName=categoryName).first() if categoryNameD: return ops_renderErrJSON(msg="相同分类已存在,请再换一个试试") # 注册写入数据库 model_category = Category() model_category.categoryName = categoryName db.session.add(model_category) db.session.commit() # json化data temp = {} temp["categoryName"] = categoryName data = [] data.append(temp) return ops_renderJSON(msg="添加成功", data=data) return "添加成功"