Example #1
0
 def select_course(self, data):
     courseName = data.split(";")[2]
     sendData = ''
     courseIndex = select_course_index(courseName)
     endDate = get_course_end_date(courseIndex)
     siteIndexList = select_allow_list_index(courseIndex)
     siteIndexList = str(siteIndexList).strip('[]').replace(' ','').replace('(','').replace(',)','').replace(',', '*')
     programIndexList = select_ban_list_index(courseIndex)
     programIndexList = str(programIndexList).strip('[]').replace(' ','').replace('(','').replace(',)','').replace(',', '*')
     sendData = programIndexList+","+siteIndexList+","+str(endDate)
     self.request.send(sendData.encode('utf-8'))
Example #2
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'))
Example #3
0
 def user_logout_handler(self, data):
     userIndex = int(data.split(";")[0])
     message = data.split(";")[2]
     if len(message) is not 0:
         courseName = message.split(",")[0]
         processList =  message.split(",")[1]
         courseIndex = select_course_index(courseName)
         processInfo = ''
             
         if len(processList) is not 0:
             try:
                 processInfo = select_user_process_info(courseIndex, userIndex)
                 processList = processList.split("*")
                 for process in processList:
                     if processInfo.find(process) == -1:
                         processInfo = processInfo + "*" + process
                 update_user_process_info(courseIndex, userIndex, processInfo)
                                         
             except:
                 update_user_process_info(courseIndex, userIndex, processList)
     
     self.request.send('1'.encode('utf-8'))
     self.request.close()
     return
Example #4
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'))