Example #1
0
class SignUpHandler(tornado.web.RequestHandler):
    def initialize(self):
        self.dataController = DataController(self.application.con)

    def get(self):
        username = self.get_argument("userName", "")
        if username:
            userId = self.dataController.getUserIdByName(username)
            self.write(str(userId))
        else:
            self.render("signup.html", result=None)

    def post(self):
        username = self.get_argument("username", "")
        password = self.get_argument("password", "")
        user = self.dataController.getUserByName(username)
        if not user:
            user = dict()
            user["userName"] = username
            user["password"] = password
            userId = self.dataController.createUser(user)
            self.set_secure_cookie("userId", str(userId))
            self.redirect("/index", permanent=True)
            return
        self.render("signup.html", result="用户名已被注册!")
Example #2
0
class IndexHandler(tornado.web.RequestHandler):
	def initialize(self):
		self.dataController = DataController(self.application.con)

	def process(self):
		userId = getUserIdFromCookie(self)
		if not userId:
			self.redirect('/login', permanent=True)
			return
		userIdForView = self.get_argument('userId', None)
		if not userIdForView:
			userIdForView = userId

		user, supervisors, superviseds, planNum, completedPlanNum, \
			unReadMessageNum = self.dataController.getUserInfoByUserId(userId)
		userForView, plansForView = \
			self.dataController.getPlansViewByUserId(userIdForView, userId)
		'''
		user = self.dataController.getUserById(userId)
		userForView = user
		if not userIdForView:
			userIdForView = userId
		if userIdForView != userId:
			userForView = self.dataController.getUserById(userIdForView)
		plans = self.dataController.getPlansByUserId(userIdForView)
		supervisors = self.dataController.getAllSupervisorsByUserId(userId)
		superviseds = self.dataController.getAllSupervisedsByUserId(userId)
		completedNum = 0
		plansForView = list()
		for plan in plans:
			plan['startTime'] = time.strftime("%Y-%m-%d", time.localtime(plan['startTime']))
			plan['endTime'] = time.strftime("%Y-%m-%d", time.localtime(plan['endTime']))
			if plan['unCompletedStageNum'] == 0:
				completedNum += 1
			plan['completingRate'] = 100
			if plan['unCompletedStageNum'] > 0:
				plan['completingRate'] = int(round(float(plan['completedStageNum']) \
						/ (plan['completedStageNum'] + plan['unCompletedStageNum']) * 100))
			if userId == plan['userId']:
				plansForView.append(plan)
			else:
				srs = self.dataController.getSrsByPlanId(plan['id'])
				for sr in srs:
					if sr['userId'] == userId:
						plansForView.append(plan)
						break
			'''

		self.render('index.html', user=user, planNum=planNum, 
			plansForView=plansForView, userForView=userForView, 
			mySupervisors=supervisors, mySuperviseds=superviseds, 
			completedPlanNum=completedPlanNum, unReadMessageNum=unReadMessageNum)

	def get(self):
		self.process()

	def post(self):
		self.process()
Example #3
0
class updateMottoHandler(tornado.web.RequestHandler):
    def initialize(self):
        self.dataController = DataController(self.application.con)

    def post(self):
        userId = getUserIdFromCookie(self)
        if not userId:
            self.redirect("/login", permanent=True)
            return
        motto = self.get_argument("motto", "")
        self.dataController.updateUserMottoById(userId, motto)
Example #4
0
class LoginHandler(tornado.web.RequestHandler):
    def initialize(self):
        self.dataController = DataController(self.application.con)

    def get(self):
        userId = getUserIdFromCookie(self)
        if userId:
            self.redirect("/index", permanent=True)
        else:
            self.render("login.html", result=None)
        """
		username = self.get_argument('username', '')
		check = self.get_argument("check", 0)
		if (check == 0):
			self.render("login.html", result=None)
		else:
			userId = self.dataController.getUserByName(username)
			if userId:
				self.write('1')
			else:
				self.write('0')
		"""

    def post(self):
        username = self.get_argument("username", "")
        password = self.get_argument("password", "")
        user = self.dataController.getUserByName(username)
        if user:
            if password == user["password"]:
                userId = user["id"]
                self.set_secure_cookie("userId", str(userId))
                self.redirect("/index", permanent=True)
                return
        self.render("login.html", result="用户不存在或密码错误!")
Example #5
0
 def __init__(self):
     print("UARTC: Init UARTCommunicator")
     self.dataController = DataController(self)
     self.imageProcessingController = ImageProcessingController(
         self, self.dataController)
     #Control
     self.isStarted = False
     self.timeToDriveSlow = 8
     #Serialport
     self.setupSerialPorts()
     self.setupGPIO()
     #UART Listener Thread initialisieren
     self.startSigndetectionEvent = threading.Event()
     self.uartListenerThread = ParallelTask(
         UARTListenerThread(self.serialPort, self.dataController,
                            self.startSigndetectionEvent))
     self.serialPort.write(self.successInit)
     self.startSigndetectionEvent.clear()
Example #6
0
class CommentHandler(tornado.web.RequestHandler):
    def initialize(self):
        self.dataController = DataController(self.application.con)

    def post(self):
        comment = dict()
        comment["userId"] = getUserIdFromCookie(self)
        if not comment["userId"]:
            self.redirect("/login", permanent=True)
            return
        comment["content"] = self.get_argument("content", "")
        comment["planId"] = self.get_argument("planId", "")
        commentId = self.dataController.createComment(comment)
        plan = self.dataController.getPlanById(comment["planId"])
        if comment["userId"] != plan["userId"]:
            message = dict()
            message["planId"] = comment["planId"]
            message["sid"] = comment["userId"]
            message["rid"] = plan["userId"]
            message["cid"] = commentId
            message["state"] = 3
            self.dataController.createMessage(message)
        self.redirect("/plan?planId=" + str(comment["planId"]), permanent=True)
Example #7
0
class CommentHandler(tornado.web.RequestHandler):
	def initialize(self):
		self.dataController = DataController(self.application.con)

	def post(self):
		comment = dict()
		comment['userId'] = getUserIdFromCookie(self)
		if not comment['userId']:
			self.redirect('/login', permanent=True)
			return
		comment['content'] = self.get_argument('content', '')
		comment['planId'] = self.get_argument('planId', '')
		commentId = self.dataController.createComment(comment)
		plan = self.dataController.getPlanById(comment['planId'])
		if comment['userId'] != plan['userId']:
			message = dict()
			message['planId'] = comment['planId']
			message['sid'] = comment['userId']
			message['rid'] = plan['userId']
			message['cid'] = commentId
			message['state'] = 3
			self.dataController.createMessage(message)
		self.redirect('/plan?planId='+str(comment['planId']), permanent=True)
Example #8
0
 def initialize(self):
     self.dataController = DataController(self.application.con)
Example #9
0
class MessageHandler(tornado.web.RequestHandler):
    def initialize(self):
        self.dataController = DataController(self.application.con)

    def get(self):
        userId = getUserIdFromCookie(self)
        if not userId:
            self.redirect("/login", permanent=True)
            return
        unReadMessages = self.dataController.getUnReadMessagesByUserId(userId)
        messages = list()
        plansForMessages = list()
        usersForMessages = list()
        comments = list()
        plansForComments = list()
        usersForComments = list()
        for message in unReadMessages:
            if message["state"] == 3:
                comment = self.dataController.getCommentById(message["cid"])
                comment["commentTime"] = time.strftime("%Y-%m-%d", time.localtime(comment["commentTime"]))
                comments.append(comment)
                plansForComments.append(self.dataController.getPlanById(message["planId"]))
                usersForComments.append(self.dataController.getUserById(message["sid"]))
            else:
                messages.append(message)
                plansForMessages.append(self.dataController.getPlanById(message["planId"]))
                usersForMessages.append(self.dataController.getUserById(message["sid"]))
            message["state"] += 4
            self.dataController.updateMessage(message)

        user, supervisors, superviseds, planNum, completedPlanNum, unReadMessageNum = self.dataController.getUserInfoByUserId(
            userId
        )

        self.render(
            "message.html",
            messages=messages,
            comments=comments,
            plansForMessages=plansForMessages,
            usersForMessages=usersForMessages,
            plansForComments=plansForComments,
            usersForComments=usersForComments,
            user=user,
            planNum=planNum,
            mySupervisors=supervisors,
            mySuperviseds=superviseds,
            completedPlanNum=completedPlanNum,
            unReadMessageNum=unReadMessageNum,
        )

    def post(self):
        userId = getUserIdFromCookie(self)
        if not userId:
            self.redirect("/login", permanent=True)
            return
        allMessages = self.dataController.getAllMessagesByUserId(userId)
        messages = list()
        plansForMessages = list()
        usersForMessages = list()
        comments = list()
        plansForComments = list()
        usersForComments = list()
        for message in allMessages:
            if message["state"] == 3 or message["state"] == 7:
                comment = self.dataController.getCommentById(message["cid"])
                comment["commentTime"] = time.strftime("%Y-%m-%d", time.localtime(comment["commentTime"]))
                comments.append(comment)
                plansForComments.append(self.dataController.getPlanById(message["planId"]))
                usersForComments.append(self.dataController.getUserById(message["sid"]))
            else:
                messages.append(message)
                plansForMessages.append(self.dataController.getPlanById(message["planId"]))
                usersForMessages.append(self.dataController.getUserById(message["sid"]))

        user, supervisors, superviseds, planNum, completedPlanNum, unReadMessageNum = self.dataController.getUserInfoByUserId(
            userId
        )

        self.render(
            "message.html",
            messages=messages,
            comments=comments,
            plansForMessages=plansForMessages,
            usersForMessages=usersForMessages,
            plansForComments=plansForComments,
            usersForComments=usersForComments,
            user=user,
            planNum=planNum,
            mySupervisors=supervisors,
            mySuperviseds=superviseds,
            completedPlanNum=completedPlanNum,
            unReadMessageNum=unReadMessageNum,
        )
Example #10
0
class PlanHandler(tornado.web.RequestHandler):
    def initialize(self):
        self.dataController = DataController(self.application.con)

    def get(self):
        userId = getUserIdFromCookie(self)
        if not userId:
            self.redirect("/login", permanent=True)
            return
        planId = self.get_argument("planId", None)
        user, supervisors, superviseds, planNum, completedPlanNum, unReadMessageNum = self.dataController.getUserInfoByUserId(
            userId
        )
        if not planId:
            plan = dict()
            plan["id"] = 0
            plan["name"] = ""
            plan["startTime"] = ""
            plan["endTime"] = ""
            plan["completingRate"] = 100
            planSupervisors = list()
            comments = list()
            stages = list()
            usersForComments = list()
            """
			supervisors = list()
			superviseds = list()
			completedNum = 0
			plans = list()
			"""
            self.render(
                "plan.html",
                userOfPlan=user,
                usersForComments=usersForComments,
                plan=plan,
                planSupervisors=planSupervisors,
                stages=stages,
                comments=comments,
                user=user,
                planNum=planNum,
                mySupervisors=supervisors,
                mySuperviseds=superviseds,
                completedPlanNum=completedPlanNum,
                unReadMessageNum=unReadMessageNum,
            )
        else:
            plan = self.dataController.getPlanById(planId)
            userOfPlan = self.dataController.getUserById(plan["userId"])
            canAccess = False
            if plan:
                if plan["userId"] == userId:
                    canAccess = True
                else:
                    srs = self.dataController.getSrsByPlanId(planId)
                    for sr in srs:
                        if sr["userId"] == userId:
                            canAccess = True
                            break
            if canAccess:
                stages = self.dataController.getStagesByPlanId(planId)
                comments = self.dataController.getCommentsByPlanId(planId)

                usersForComments = list()
                for comment in comments:
                    comment["commentTime"] = time.strftime("%Y-%m-%d", time.localtime(comment["commentTime"]))
                    usersForComments.append(self.dataController.getUserById(comment["userId"]))
                if not plan["name"]:
                    plan["name"] = ""
                if not plan["startTime"]:
                    plan["startTime"] = ""
                else:
                    plan["startTime"] = time.strftime("%Y-%m-%d", time.localtime(plan["startTime"]))
                if not plan["endTime"]:
                    plan["endTime"] = ""
                else:
                    plan["endTime"] = time.strftime("%Y-%m-%d", time.localtime(plan["endTime"]))
                plan["completingRate"] = 100
                if plan["unCompletedStageNum"] != 0:
                    plan["completingRate"] = int(
                        round(
                            float(plan["completedStageNum"])
                            / (plan["completedStageNum"] + plan["unCompletedStageNum"])
                            * 100
                        )
                    )

                srs = self.dataController.getSrsByPlanId(planId)
                planSupervisors = list()
                for sr in srs:
                    planSupervisors.append(self.dataController.getUserById(sr["userId"]))

                self.render(
                    "plan.html",
                    userOfPlan=userOfPlan,
                    usersForComments=usersForComments,
                    plan=plan,
                    planSupervisors=planSupervisors,
                    stages=stages,
                    comments=comments,
                    user=user,
                    planNum=planNum,
                    mySupervisors=supervisors,
                    mySuperviseds=superviseds,
                    completedPlanNum=completedPlanNum,
                    unReadMessageNum=unReadMessageNum,
                )

            else:
                self.write("你没有访问该计划的权利")

    def post(self):
        userId = getUserIdFromCookie(self)
        if not userId:
            self.redirect("/login", permanent=True)
            return
        planId = int(self.get_argument("planId", ""))
        isSave = int(self.get_argument("save", 0))
        if isSave:
            plan = dict()
            plan["name"] = self.get_argument("name", "")
            plan["startTime"] = time.mktime(time.strptime(self.get_argument("startTime", ""), "%Y-%m-%d"))
            plan["endTime"] = time.mktime(time.strptime(self.get_argument("endTime", ""), "%Y-%m-%d"))
            plan["userId"] = userId
            if planId:
                plan["id"] = planId
            else:
                plan["id"] = self.dataController.createPlan(plan)
                planId = plan["id"]

            completedStageNum = 0
            unCompletedStageNum = 0

            stagesId = map(int, self.get_arguments("stageId", ""))
            stagesContent = self.get_arguments("stageContent", "")
            stagesState = map(int, self.get_arguments("stageState", ""))
            stagesDelete = map(int, self.get_arguments("stageDelete", ""))
            stages = list()
            if (
                len(stagesId) == len(stagesContent)
                and len(stagesContent) == len(stagesState)
                and len(stagesState) == len(stagesDelete)
                and len(stagesState) > 0
            ):
                stage = dict()
                stage["planId"] = planId
                for index in range(len(stagesId)):
                    if stagesDelete[index] == 1:
                        self.dataController.deleteStageById(stagesId[index])
                    else:
                        stage["content"] = stagesContent[index]
                        stage["state"] = stagesState[index]
                        if stagesId[index] == 0:
                            stage["id"] = self.dataController.createStage(stage)
                        else:
                            stage["id"] = stagesId[index]
                            self.dataController.updateStage(stage)
                        if stage["state"] == 1:
                            completedStageNum += 1
                        else:
                            unCompletedStageNum += 1

            plan["completedStageNum"] = completedStageNum
            plan["unCompletedStageNum"] = unCompletedStageNum
            self.dataController.updatePlan(plan)

            supervisorIds = map(int, self.get_arguments("supervisorId", ""))
            sr = dict()
            message = dict()
            sr["planId"] = planId
            message["planId"] = planId
            message["sid"] = userId
            message["state"] = 0
            for supervisor in supervisorIds:
                if supervisor:
                    sr["userId"] = supervisor
                    self.dataController.createSr(sr)
                    message["rid"] = supervisor
                    self.dataController.createMessage(message)
            self.redirect("/plan?planId=" + str(planId), permanent=True)

        else:
            self.dataController.deleteStagesByPlanId(planId)
            self.dataController.deleteCommentsByPlanId(planId)
            self.dataController.deleteSrsByPlanId(planId)
            self.dataController.deleteMessagesByPlanId(planId)
            self.dataController.deletePlanById(planId)
            self.redirect("/index", permanent=True)
Example #11
0
import logging

from flask import Flask

from config import DEBUG, INDEX_PATH

from DataController import DataController

if DEBUG:
    logging.getLogger().setLevel(logging.DEBUG)

controller = DataController(INDEX_PATH)
controller.open()
logging.debug('controller.open() returned')

app = Flask(__name__)

from dbconnector import views
Example #12
0
class UARTCommunicator():
    # Receive Commanddefinitions
    onCommand = [b'\n']  # =10
    #Send Commanddefinitions
    successInit = b'1\n'
    roundsDriven = b'5\n'
    stopSignDetected = b'7\n'

    def __init__(self):
        print("UARTC: Init UARTCommunicator")
        self.dataController = DataController(self)
        self.imageProcessingController = ImageProcessingController(
            self, self.dataController)
        #Control
        self.isStarted = False
        self.timeToDriveSlow = 8
        #Serialport
        self.setupSerialPorts()
        self.setupGPIO()
        #UART Listener Thread initialisieren
        self.startSigndetectionEvent = threading.Event()
        self.uartListenerThread = ParallelTask(
            UARTListenerThread(self.serialPort, self.dataController,
                               self.startSigndetectionEvent))
        self.serialPort.write(self.successInit)
        self.startSigndetectionEvent.clear()

    def ListenForStart(self):
        print("UARTC: listening for ON-Signal")
        while not self.isStarted:
            rcv = self.serialPort.readlines(1)
            print(rcv)
            if (rcv == self.onCommand):
                print("UARTC: On-Signal detected")
                self.isStarted = True
        #UART Listener-Thread starten
        self.StartUARTListener()
        #Auf StartSignDetectionEvent warten
        self.startSigndetectionEvent.set()
        self.StartSignDetection()

    def StartSignDetection(self):
        try:
            print("UARTC: Cube is safed")
            self.imageProcessingController.LookForStartSignCaptureStream()
        except:
            self.UnloadGPIO()

    def LastRoundIsFinished(self):
        try:
            print("UARTC: Last round is finished")
            self.serialPort.write(self.roundsDriven)
            self.__playBuzzer(
                self.imageProcessingController.GetStopSignDigit())
            start_timer = time.time()
            while (time.time() - start_timer < self.timeToDriveSlow):
                time.sleep(0.01)
            self.imageProcessingController.DetectStopSign()
        except:
            self.UnloadGPIO()

    def StopTrain(self):
        print("UARTC: Next Sign is Stopsign")
        self.serialPort.write(self.stopSignDetected)
        self.uartListenerThread.Stop()
        self.imageProcessingController.SaveImageStreamToFS(
            self.dataController.allImagesList())
        self.dataController.PersistData()
        self.closeSerialPorts()

    def __playBuzzer(self, number):
        print("Buzzer sound: ", number)
        self.buzzer.start(50.0)
        for x in range(number):
            sleep(0.3)
            self.buzzer.ChangeFrequency(4000)
            sleep(0.2)
            self.buzzer.ChangeFrequency(10)

    ###################################################################
    #UART-Listener
    def StartUARTListener(self):
        print("UARTC: UARTListener started")
        self.uartListenerThread.Start()

    def StopUARTListener(self):
        print("UARTC: UARTListener stopped")
        self.uartListenerThread.Stop()

    ###################################################################
    #Helpmethods

    def _listSerialPorts(self):
        ports = list(serial.port_list.comports())
        for p in ports:
            print(p)

    def setupSerialPorts(self):
        serialPortRxPath = '/dev/ttyS0'
        baudrate = 115200
        serialtTimeout = 1.0
        self.serialPort = serial.Serial(serialPortRxPath,
                                        baudrate=baudrate,
                                        timeout=serialtTimeout)

    def closeSerialPorts(self):
        self.serialPort.close()

    def setupGPIO(self):
        # Hier können die jeweiligen Eingangs-/Ausgangspins ausgewählt werden
        self.buzzer_Ausgangspin = 12
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.buzzer_Ausgangspin, GPIO.OUT)
        self.buzzer = GPIO.PWM(self.buzzer_Ausgangspin, 10)

    def UnloadGPIO(self):
        GPIO.cleanup()
import time

from Timer import Timer
from DataController import DataController
from mod_WebsiteController import WeeklyUpdateWebsiteController
from google_search_parser import generate_parsers


if __name__ == "__main__":
    print("Generating parsers")
    parsers = generate_parsers()

    print("Setting up controllers")
    tm = Timer(interval=24*3600)
    tm2 = Timer(tm.Stop, interval=24*3600)
    dc = DataController(tm.Stop)
    wc = WeeklyUpdateWebsiteController(parsers, tm.Stop, dc.dataq, tm.Tx)

    tm.start()
    tm2.start()
    dc.start()
    wc.start()
    print("Waiting for the controllers")
    datum_count = 0
    while True:
        if not tm2.Tx.empty():
            try:
                tm2.Tx.get_nowait()
                dc.save()
                print("Saved data")
            except Empty as _:
Example #14
0
class PlanHandler(tornado.web.RequestHandler):
	def initialize(self):
		self.dataController = DataController(self.application.con)

	def get(self):
		userId = getUserIdFromCookie(self)
		if not userId:
			self.redirect('/login', permanent=True)
			return
		planId = self.get_argument('planId', None)
		user, supervisors, superviseds, planNum, completedPlanNum, \
			unReadMessageNum = self.dataController.getUserInfoByUserId(userId)
		if not planId:
			plan = dict()
			plan['id'] = 0
			plan['name'] = ''
			plan['startTime'] = ''
			plan['endTime'] = ''
			plan['completingRate'] = 100
			planSupervisors = list()
			comments = list()
			stages = list()
			usersForComments = list()
			'''
			supervisors = list()
			superviseds = list()
			completedNum = 0
			plans = list()
			'''
			self.render('plan.html', userOfPlan=user, 
				usersForComments=usersForComments, 
				plan=plan, planSupervisors=planSupervisors, 
				stages=stages, comments=comments, 
				user=user, planNum=planNum, 
				mySupervisors=supervisors, mySuperviseds=superviseds, 
				completedPlanNum=completedPlanNum, unReadMessageNum=unReadMessageNum)
		else:
			plan = self.dataController.getPlanById(planId)
			userOfPlan = self.dataController.getUserById(plan['userId'])
			canAccess = False
			if plan:
				if plan['userId'] == userId:
					canAccess = True
				else:
					srs = self.dataController.getSrsByPlanId(planId)
					for sr in srs:
						if sr['userId'] == userId:
							canAccess = True
							break
			if canAccess:
				stages = self.dataController.getStagesByPlanId(planId)
				comments = self.dataController.getCommentsByPlanId(planId)

				usersForComments = list()
				for comment in comments:
					comment['commentTime'] = time.strftime("%Y-%m-%d", time.localtime(comment['commentTime']))
					usersForComments.append(self.dataController.getUserById(comment['userId']))
				if not plan['name']:
					plan['name'] = ''
				if not plan['startTime']:
					plan['startTime'] = ''
				else:
					plan['startTime'] = time.strftime("%Y-%m-%d", time.localtime(plan['startTime']))
				if not plan['endTime']:
					plan['endTime'] = ''
				else:
					plan['endTime'] = time.strftime("%Y-%m-%d", time.localtime(plan['endTime']))
				plan['completingRate'] = 100
				if plan['unCompletedStageNum'] != 0:
					plan['completingRate'] = int(round(float(plan['completedStageNum']) \
						/ (plan['completedStageNum'] + plan['unCompletedStageNum']) * 100))

				srs = self.dataController.getSrsByPlanId(planId)
				planSupervisors = list()
				for sr in srs:
					planSupervisors.append(self.dataController.getUserById(sr['userId']))

				
				self.render('plan.html', userOfPlan=userOfPlan, 
					usersForComments=usersForComments, 
					plan=plan, planSupervisors=planSupervisors, 
					stages=stages, comments=comments, 
					user=user, planNum=planNum, 
					mySupervisors=supervisors, mySuperviseds=superviseds, 
					completedPlanNum=completedPlanNum, unReadMessageNum=unReadMessageNum)

			else:
				self.write('你没有访问该计划的权利')

	def post(self):
		userId = getUserIdFromCookie(self)
		if not userId:
			self.redirect('/login', permanent=True)
			return
		planId = int(self.get_argument('planId', ''))
		isSave = int(self.get_argument('save', 0))
		if isSave:
			plan = dict()
			plan['name'] = self.get_argument('name', '')
			plan['startTime'] = time.mktime(time.strptime(self.get_argument('startTime', ''),'%Y-%m-%d'))
			plan['endTime'] = time.mktime(time.strptime(self.get_argument('endTime', ''),'%Y-%m-%d'))
			plan['userId'] = userId
			if planId:
				plan['id'] = planId
			else:
				plan['id'] = self.dataController.createPlan(plan)
				planId = plan['id']

			completedStageNum = 0
			unCompletedStageNum = 0

			stagesId = map(int, self.get_arguments('stageId', ''))
			stagesContent = self.get_arguments('stageContent', '')
			stagesState = map(int, self.get_arguments('stageState', ''))
			stagesDelete = map(int, self.get_arguments('stageDelete', ''))
			stages = list()
			if len(stagesId) == len(stagesContent) \
			and len(stagesContent) == len(stagesState) \
			and len(stagesState) == len(stagesDelete) \
			and len(stagesState) > 0:
				stage = dict()
				stage['planId'] = planId
				for index in range(len(stagesId)):
					if stagesDelete[index] == 1:
						self.dataController.deleteStageById(stagesId[index])
					else:
						stage['content'] = stagesContent[index]
						stage['state'] = stagesState[index]
						if stagesId[index] == 0:
							stage['id'] = self.dataController.createStage(stage)
						else:
							stage['id'] = stagesId[index]
							self.dataController.updateStage(stage)
						if stage['state'] == 1:
							completedStageNum += 1
						else:
							unCompletedStageNum += 1

			plan['completedStageNum'] = completedStageNum
			plan['unCompletedStageNum'] = unCompletedStageNum
			self.dataController.updatePlan(plan)

			supervisorIds = map(int, self.get_arguments('supervisorId', ''))
			sr = dict()
			message = dict()
			sr['planId'] = planId
			message['planId'] = planId
			message['sid'] = userId
			message['state'] = 0
			for supervisor in supervisorIds:
				if supervisor:
					sr['userId'] = supervisor
					self.dataController.createSr(sr)
					message['rid'] = supervisor
					self.dataController.createMessage(message)
			self.redirect('/plan?planId='+str(planId), permanent=True)

		else:
			self.dataController.deleteStagesByPlanId(planId)
			self.dataController.deleteCommentsByPlanId(planId)
			self.dataController.deleteSrsByPlanId(planId)
			self.dataController.deleteMessagesByPlanId(planId)
			self.dataController.deletePlanById(planId)
			self.redirect('/index', permanent=True)