Пример #1
0
    def post(self):
        """
        将老师上传的题目存到数据库
        """
        try:
            self.sqlhandler = None
            self.args = {}
            if not utils.isUIDValid(self):
                self.write("need login")
                return
            utils.parseJsonRequestBody(self)
            self.classId = self.args["classId"]
            self.practiceId = self.args["practiceId"]

            if self.deletePractice():
                self.write("success")
                self.finish()
            else:
                raise RuntimeError
        except Exception as e:
            print(e)
            self.write("找不到对应的练习")
            self.finish()
        finally:
            if self.sqlhandler is not None:
                self.sqlhandler.closeMySql()
    def get(self):
        """
        从数据库获取学生列表返回给管理员
        """
        try:
            self.sqlhandler = None
            if "UID" not in self.request.cookies.keys():
                self.write("no uid")
                return

            if not utils.isUIDValid(self):
                self.write("no uid")
                return
            if self.getStuList():
                self.write(
                    json.dumps(self.stuList if self.
                               stuList is not None else {"length": 0}))
                self.finish()
            else:
                raise RuntimeError
        except Exception as e:
            print(e)
            self.write("error")
            self.finish()
        finally:
            if self.sqlhandler is not None:
                self.sqlhandler.closeMySql()
Пример #3
0
    def get(self):
        """
        从数据库删除学生信息
        """
        try:
            self.sqlhandler = None
            if "UID" not in self.request.cookies:
                self.write("error")
                return

            if not utils.isUIDValid(self):
                self.write("no uid")
                return
            self.stuId = self.get_argument("StuId")
            if self.deleteStu():
                self.write("success")
                self.finish()
            else:
                raise RuntimeError
        except Exception as e:
            print(e)
            self.write("error")
            self.finish()
        finally:
            if self.sqlhandler is not None:
                self.sqlhandler.closeMySql()
Пример #4
0
    def post(self):
        """
        增加老师

        """
        try:
            self.sqlhandler = None
            if "UID" not in self.request.cookies:
                self.write("error")
                return
                
            if not utils.isUIDValid(self):
                self.write("no uid")
                return
            self.teaId = self.get_argument("teaId")
            self.teaName = self.get_argument("teaName")
            self.teaPassword = self.get_argument("teaPassword")
            if self.AddTea():
                self.set_status(200)
                self.write("success")
                self.finish()
            else:
                raise RuntimeError
        except Exception as e:
            print(e)
            self.set_status(403)
            self.write("error")
            self.finish()
        finally:
            if self.sqlhandler is not None:
                self.sqlhandler.closeMySql()
Пример #5
0
    def post(self):
        """
        添加班级信息
        """
        try:
            self.sqlhandler = None
            if "UID" not in self.request.cookies:
                self.write("error")
                return

            if not utils.isUIDValid(self):
                self.write("no uid")
                return

            if self.setClass():

                self.write("success")
                self.finish()
            else:
                raise RuntimeError
        except Exception as e:
            print(e)
            self.write("error")
            self.finish()
        finally:
            if self.sqlhandler is not None:
                self.sqlhandler.closeMySql()
Пример #6
0
    def get(self):
        try:
            self.sqlhandler = None
            if "UID" not in self.request.cookies:
                self.write("no uid")
                return

            if not utils.isUIDValid(self):
                self.write("no uid")
                return

            self.roomList = None

            if self.getList():
                self.write(
                    json.dumps(self.roomList) if self.
                    roomList is not None else "[]")
                self.finish()
            else:
                raise RuntimeError
        except Exception as e:
            print(e)
            self.write("[]")
            self.finish()
        finally:
            if self.sqlhandler is not None:
                self.sqlhandler.closeMySql()
    def post(self):
        """
        添加班级信息
        """
        try:
            self.sqlhandler = None
            if "UID" not in self.request.cookies:
                self.write("error")
                return

            if not utils.isUIDValid(self):
                self.write("no uid")
                return
            self.classId = self.get_argument("classId")
            self.courseName = self.get_argument("courseName")
            self.teacher = self.get_argument("teacher")
            self.classStuNumber = self.get_argument("classStuNumber")
            if self.setClass():
                
                self.write("success")
                self.finish()
            else:
                raise RuntimeError
        except Exception:
            self.write("error")
            self.finish()
        finally:
            if self.sqlhandler is not None:
                self.sqlhandler.closeMySql()
Пример #8
0
 def get(self):
     """
     获取练习题列表,返回给老师客户端
     """
     try:
         self.teaClassPractice = []
         self.sqlhandler = None
         if not utils.isUIDValid(self):
             self.write("no uid")
             return
         if self.getTeaClass():
             print(self.teaClassPractice)
             self.write(
                 json.dumps(self.teaClassPractice) if self.
                 teaClassPractice is not None else "[]")
             self.finish()
         else:
             raise RuntimeError
     except Exception as e:
         traceback.print_exc()
         print(e)
         self.write("[]")
         self.finish()
     finally:
         if self.sqlhandler is not None:
             self.sqlhandler.closeMySql()
Пример #9
0
    def get(self):
        """
        从数据库获取班级学生信息返回给管理员

        """
        try:
            self.sqlhandler = None
            if "UID" not in self.request.cookies:
                self.write("error")
                return

            if not utils.isUIDValid(self):
                self.write("no uid")
                return
            self.classStu = dict()
            self.classId = self.get_argument("classId")
            if self.getClassStuList():
                self.write(json.dumps(self.classStu))
                self.finish()
            else:
                raise RuntimeError
        except Exception as e:
            print(e.args)
            self.write("error")
            self.finish()
        finally:
            if self.sqlhandler is not None:
                self.sqlhandler.closeMySql()
    def post(self):
        """
        将老师上传的题目存到数据库
        """
        try:
            self.sqlhandler = None
            if not utils.isUIDValid(self):
                self.write("no uid")
                return

            utils.parseJsonRequestBody(self)
            self.stuId = self.args["stuId"]
            self.stuScore = self.args["stuScore"]
            self.practiceId = self.args["practiceId"]
            self.scoreDetail = self.args["scoreDetail"]

            if self.pushPractice():
                self.write("success")
                self.finish()
            else:
                raise RuntimeError
        except Exception:
            self.write("error")
            self.finish()
        finally:
            if self.sqlhandler is not None:
                self.sqlhandler.closeMySql()
    def get(self):
        """
        获取练习题答案,返回给老师客户端
        """
        try:
            self.teaClassPractice = []
            self.sqlhandler = None
            if not utils.isUIDValid(self):
                self.write("no uid")
                return

            self.practiceId = self.get_argument("practiceId")
            self.StuId = self.get_argument("stuId")
            self.stuAnser = None
            if self.getAnswer():
                print(self.stuAnser)
                self.write(
                    self.stuAnser if self.stuAnser is not None else "{}")
                self.finish()
            else:
                raise RuntimeError
        except Exception as e:
            print(e)
            self.write("error")
            self.finish()
        finally:
            if self.sqlhandler is not None:
                self.sqlhandler.closeMySql()
Пример #12
0
    def post(self):
        """
        从数据库删除班级学生信息

        """
        try:
            self.sqlhandler = None
            if "UID" not in self.request.cookies.keys():
                self.write("no uid")
                return

            if not utils.isUIDValid(self):
                self.write("no uid")
                return
            self.classId = self.get_argument("classId")
            self.stuId = self.get_argument("stuId")
            if self.deleteClassStu():
                self.write("success")
                self.finish()
            else:
                raise RuntimeError
        except Exception:
            self.write("error")
            self.finish()
        finally:
            if self.sqlhandler is not None:
                self.sqlhandler.closeMySql()
            tornado.ioloop.IOLoop.current().stop()
    def post(self):
        """
        将老师上传的题目存到数据库
        """
        try:
            self.sqlhandler = None
            self.args = {}
            if not utils.isUIDValid(self):
                self.write("need login")
                return

            utils.parseJsonRequestBody(self)
            self.classId = self.args["classId"]
            self.practiceId = self.args["title"]
            self.fullScore = self.args["fullScore"]
            questions = self.args["questions"]
            self.examDetail = []
            self.answers = []
            for i in questions:
                self.answers.append({
                    "orderNumber": i["orderNumber"],
                    "answer": i.pop("answer")
                })
                self.examDetail.append(i)
            self.examDetail = json.dumps(self.examDetail)
            self.answers = json.dumps(self.answers)

            if self.pushPractice():
                self.write("success")
                self.finish()
            else:
                raise RuntimeError
        except Exception as e:
            print(e)
            self.write("请检查练习标题是否重复")
            self.finish()
        finally:
            if self.sqlhandler is not None:
                self.sqlhandler.closeMySql()