Beispiel #1
0
    def master_add_course_handler(self, data):
        masterIndex = int(data.split(";")[0])
        addList = data.split(";")[2].split(",")
        courseName = addList[0]
        startDate = addList[1]
        endDate = addList[2]
        banList = addList[3].split("*")
        allowList = addList[4].split("*")
        userList = addList[5].split("*")
        print(masterIndex,courseName,startDate, endDate, banList, allowList, userList)
        try:
            try:
                dao.add(insert_course(masterIndex, courseName, startDate, endDate))
                dao.commit()
            except Exception as e:
                dao.rollback()
                print(e)
                self.request.send("0".encode('utf-8'))
                return 
            testIndex = select_course_index(courseName)

            if len(userList[0]) is not 0:
                for userInfo in userList:
                    userInfo = userInfo.split('$')
                    try:
                        userIndex = select_user_index(userInfo[0])
                    except:
                        try:
                            dao.add(insert_user(userInfo[0], userInfo[1]))
                            dao.commit()
                        except Exception as e:
                            dao.rollback()
                            print(e)
                            self.request.send("-1".encode('utf-8'))
                            return
                        userIndex = select_user_index(userInfo[0])
                    dao.add(insert_user_in_course(testIndex, userIndex))

            if len(banList[0]) is not 0:
                for banProgram in banList:
                    dao.add(insert_ban_list_in_course(testIndex, int(banProgram)))

            if len(allowList[0]) is not 0:
                for allowSite in allowList:
                    dao.add(insert_allow_list_in_course(testIndex, int(allowSite)))

            dao.commit()
            self.request.send("1".encode('utf-8'))
        except Exception as e:
            print(e)
            dao.rollback()
            self.request.send("0".encode('utf-8'))
Beispiel #2
0
    def master_modify_course_handler(self, data):
        updateList = data.split(";")[2].split(",")
        courseName = updateList[0]
        startDate = updateList[1]
        endDate = updateList[2]
        banList = updateList[3].split("*")
        allowList = updateList[4].split("*")
        userList = updateList[5].split("*")
        courseIndex = select_course_index(courseName)

        try:
            if len(userList[0]) is not 0:
                for userInfo in userList:
                    userInfo = userInfo.split('$')

                    try:
                        userIndex = select_user_index(userInfo[0])
                    except:
                        dao.add(insert_user(userInfo[0], userInfo[1]))
                        dao.commit()
                        userIndex = select_user_index(userInfo[0])
                    try:
                        existUserIndex = select_user_in_course(courseIndex, userIndex)
                    except Exception as e:
                        dao.add(insert_user_in_course(courseIndex, userIndex))
                        dao.commit()

            delete_ban_list_in_course(courseIndex)
            delete_allow_list_in_course(courseIndex)
                
        except Exception as e:
            dao.rollback()
            self.request.send("-1".encode('utf-8'))
            return

        try:
            modify_course(courseName = courseName,
                          startDate = startDate,
                          endDate = endDate)

            if len(banList[0]) is not 0:
                for banIndex in banList:
                    try:
                        dao.add(insert_ban_list_in_course(courseIndex, int(banIndex)))
                    except:
                        modify_ban_list_in_course(courseIndex, int(banIndex))

            if len(allowList[0]) is not 0:
                for webIndex in allowList:
                    try:
                        dao.add(insert_allow_list_in_course(courseIndex, int(webIndex)))
                    except:
                        modify_allow_list_in_course(courseIndex, int(webIndex))

            dao.commit()
        except:
            dao.rollback()
            self.request.send("-1".encode('utf-8'))
            return
        try:
            userCount = select_user_count(courseIndex)
        except Exception as e:
            self.request.send("-1".encode('utf-8'))

        self.request.send(str(userCount).encode('utf-8'))