def addLab(self, form):

        db = self.__db
        cursor = self.__cursor
        hostname = self.__hostname

        lHandler = LabHandler(db, cursor)
        ucMapper = UserCategoryMapper(db, cursor)
        category_Name_ID_Map = ucMapper.mapCategoryNameToID()

        # print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
        # print					# DITTO
        # print `form`

        # Get form values
        labName = form.getvalue("labName")
        labHeadTitle = form.getvalue("titles")
        labHeadName = form.getvalue("labHead")
        labHead = labHeadTitle + " " + labHeadName
        labCode = form.getvalue("labCode").upper()
        labDescr = form.getvalue("labDescription")
        labAddress = form.getvalue("labAddress")
        labAccess = form.getvalue("system_access_level")
        defaultLabAccessLevel = category_Name_ID_Map[labAccess]  # map to database ID

        try:
            newLabID = lHandler.insertLab(labName, labDescr, labAddress, defaultLabAccessLevel, labHead, labCode)
            # print `newLabID`
            newLab = Laboratory(newLabID, labName, labDescr, labAccess, labAddress, labHead, labCode)
            self.printLabInfo("view", newLab)

        except DuplicateLabCodeException:

            d = DuplicateLabCodeException()
            utils.redirect(
                hostname
                + "User.php?View=3&labName="
                + labName
                + "&title="
                + labHeadTitle
                + "&labHead="
                + labHeadName
                + "&labCode="
                + labCode
                + "&labDescr="
                + labDescr
                + "&locn="
                + labAddress
                + "&access="
                + labAccess
                + "&ErrCode="
                + ` d.err_code() `
            )
    def addLab(self, form):

        db = self.__db
        cursor = self.__cursor
        hostname = self.__hostname

        lHandler = LabHandler(db, cursor)
        ucMapper = UserCategoryMapper(db, cursor)
        category_Name_ID_Map = ucMapper.mapCategoryNameToID()

        #print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
        #print					# DITTO
        #print `form`

        # Get form values
        labName = form.getvalue("labName")
        labHeadTitle = form.getvalue("titles")
        labHeadName = form.getvalue("labHead")
        labHead = labHeadTitle + " " + labHeadName
        labCode = form.getvalue("labCode").upper()
        labDescr = form.getvalue("labDescription")
        labAddress = form.getvalue("labAddress")
        labAccess = form.getvalue("system_access_level")
        defaultLabAccessLevel = category_Name_ID_Map[
            labAccess]  # map to database ID

        try:
            newLabID = lHandler.insertLab(labName, labDescr, labAddress,
                                          defaultLabAccessLevel, labHead,
                                          labCode)
            #print `newLabID`
            newLab = Laboratory(newLabID, labName, labDescr, labAccess,
                                labAddress, labHead, labCode)
            self.printLabInfo('view', newLab)

        except DuplicateLabCodeException:

            d = DuplicateLabCodeException()
            utils.redirect(hostname + "User.php?View=3&labName=" + labName +
                           "&title=" + labHeadTitle + "&labHead=" +
                           labHeadName + "&labCode=" + labCode + "&labDescr=" +
                           labDescr + "&locn=" + labAddress + "&access=" +
                           labAccess + "&ErrCode=" + ` d.err_code() `)
    def saveLab(self, form):

        db = self.__db
        cursor = self.__cursor
        hostname = self.__hostname

        # print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
        # print					# DITTO
        # print `form`

        # Handlers and mappers
        lHandler = LabHandler(db, cursor)
        ucMapper = UserCategoryMapper(db, cursor)
        category_Name_ID_Map = ucMapper.mapCategoryNameToID()

        # Get form values
        labID = int(form.getvalue("labID"))
        lab = Laboratory(
            labID
        )  # here need to use the default constructor and not findLabByID, because lab is being updated and need a fresh instance and set its attributes to new values

        newName = form.getvalue("labName")
        newLabHead = form.getvalue("labHead")
        newLabCode = form.getvalue("labCode").upper()
        newDescr = form.getvalue("description")
        newAddr = form.getvalue("address")
        newAccess = form.getvalue("system_access_level")
        newAccLev = category_Name_ID_Map[newAccess]

        # change database values
        try:
            lHandler.setLabName(labID, newName)
            lHandler.setLabHead(labID, newLabHead)
            lHandler.setLabCode(labID, newLabCode)
            lHandler.setLabDescription(labID, newDescr)
            lHandler.setLabAccessLevel(labID, newAccLev)
            lHandler.setLocation(labID, newAddr)

            #######################
            # update members!
            #######################

            newMembers = form.getlist("labMembers")
            lHandler.updateLabMembers(labID, newMembers)

            # change object values
            lab.setName(newName)
            lab.setLabHead(newLabHead)
            lab.setLabCode(newLabCode)
            lab.setDescription(newDescr)
            lab.setAddress(newAddr)
            lab.setDefaultAccessLevel(newAccess)

            # return to detailed view
            self.printLabInfo("view", lab)
            # utils.redirect(hostname + "User.php?View=5&Lab=" + `labID` + "&fd=" + filename)

        except DuplicateLabCodeException:

            newLab = Laboratory(labID, newName, newDescr, newAccess, newAddr, newLabHead, newLabCode)

            d = DuplicateLabCodeException()
            self.printLabInfo("edit", newLab, d.err_code())
    def saveLab(self, form):

        db = self.__db
        cursor = self.__cursor
        hostname = self.__hostname

        #print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
        #print					# DITTO
        #print `form`

        # Handlers and mappers
        lHandler = LabHandler(db, cursor)
        ucMapper = UserCategoryMapper(db, cursor)
        category_Name_ID_Map = ucMapper.mapCategoryNameToID()

        # Get form values
        labID = int(form.getvalue("labID"))
        lab = Laboratory(
            labID
        )  # here need to use the default constructor and not findLabByID, because lab is being updated and need a fresh instance and set its attributes to new values

        newName = form.getvalue("labName")
        newLabHead = form.getvalue("labHead")
        newLabCode = form.getvalue("labCode").upper()
        newDescr = form.getvalue("description")
        newAddr = form.getvalue("address")
        newAccess = form.getvalue("system_access_level")
        newAccLev = category_Name_ID_Map[newAccess]

        # change database values
        try:
            lHandler.setLabName(labID, newName)
            lHandler.setLabHead(labID, newLabHead)
            lHandler.setLabCode(labID, newLabCode)
            lHandler.setLabDescription(labID, newDescr)
            lHandler.setLabAccessLevel(labID, newAccLev)
            lHandler.setLocation(labID, newAddr)

            #######################
            # update members!
            #######################

            newMembers = form.getlist("labMembers")
            lHandler.updateLabMembers(labID, newMembers)

            # change object values
            lab.setName(newName)
            lab.setLabHead(newLabHead)
            lab.setLabCode(newLabCode)
            lab.setDescription(newDescr)
            lab.setAddress(newAddr)
            lab.setDefaultAccessLevel(newAccess)

            # return to detailed view
            self.printLabInfo('view', lab)
            #utils.redirect(hostname + "User.php?View=5&Lab=" + `labID` + "&fd=" + filename)

        except DuplicateLabCodeException:

            newLab = Laboratory(labID, newName, newDescr, newAccess, newAddr,
                                newLabHead, newLabCode)

            d = DuplicateLabCodeException()
            self.printLabInfo('edit', newLab, d.err_code())