Ejemplo n.º 1
0
	def findAllMembersInCategory(self, category, active, oper = '=', labID = 0):
		
		db = self.db
		cursor = self.cursor
		
		#print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
		#print					# DITTO
		
		ucMapper = UserCategoryMapper(db, cursor)		# for category name/id mapping
		category_Name_ID_Map = ucMapper.mapCategoryNameToID()

		members = []	# list of User **objects**
		
		# When we include 'status=ACTIVE' restriction in the query, a DEP owner of an active project is not shown in project view.  However, we should not add DEP members to a project.
		# Therefore, the calling function should specify whether it wants to restrict query by status.
		# If 'active' parameter is True, add 'status=ACTIVE' clause
		# In any case, **remember to fill in 'category' column for DEP users before the launch**
		
		if labID == 0:
			if active:
				cursor.execute("SELECT userID, firstname, lastname, description FROM Users_tbl u, UserCategories_tbl c WHERE c.categoryID " + oper + " " + `category_Name_ID_Map[category]` + " AND c.categoryID=u.category AND u.firstname <> '' AND u.lastname <> '' AND u.description <>'' AND u.status='ACTIVE'")
			else:
				cursor.execute("SELECT userID, firstname, lastname, description FROM Users_tbl u, UserCategories_tbl c WHERE c.categoryID " + oper + " " + `category_Name_ID_Map[category]` + " AND c.categoryID=u.category AND u.firstname <> '' AND u.lastname <> '' AND u.description <>''")
		else:
			if active:
				cursor.execute("SELECT u.userID, u.firstname, u.lastname, u.description, l.lab_name FROM Users_tbl u, UserCategories_tbl c, LabInfo_tbl l WHERE c.categoryID " + oper + " " + `category_Name_ID_Map[category]` + " AND c.categoryID=u.category AND u.firstname <> '' AND u.lastname <> '' AND u.labID=" + `labID` + " AND l.labID=u.labID AND u.status='ACTIVE'")
			else:
				cursor.execute("SELECT u.userID, u.firstname, u.lastname, u.description, l.lab_name FROM Users_tbl u, UserCategories_tbl c, LabInfo_tbl l WHERE c.categoryID " + oper + " " + `category_Name_ID_Map[category]` + " AND c.categoryID=u.category AND u.firstname <> '' AND u.lastname <> '' AND u.description <>'' AND u.labID=" + `labID` + " AND l.labID=u.labID")
			
		results = cursor.fetchall()
		
		for result in results:
		
			userID = int(result[0])
			firstName = result[1]
			lastName = result[2]
			description = result[3]
			
			tmpLab = Laboratory(labID)
			
			if len(result) == 5:
				labName = result[4]
				tmpLab.setName(labName)
				
			# create a User object
			tmpUser = User(userID, "", firstName, lastName, description, tmpLab, category, "", "")
			members.append(tmpUser)
		

		return members
Ejemplo n.º 2
0
    def findLabByID(self, labID):

        db = self.db
        cursor = self.cursor

        ucMapper = UserCategoryMapper(db, cursor)
        category_ID_Name_Map = ucMapper.mapCategoryIDToName()

        cursor.execute(
            "SELECT lab_name, description, default_access_level, location, lab_head, labCode FROM LabInfo_tbl WHERE labID="
            + ` labID ` + " AND status='ACTIVE'")
        result = cursor.fetchone()

        if result:
            labName = result[0]
            labDescr = result[1]
            accessLevel = int(result[2])
            address = result[3]
            labHead = result[4]
            labCode = result[5].upper()

            newLab = Laboratory(labID, labName, labDescr,
                                category_ID_Name_Map[accessLevel], address,
                                labHead, labCode)

            return newLab
Ejemplo n.º 3
0
    def checkPermissions(self, uname, pwd):

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

        db = self.__db
        cursor = self.__cursor

        cursor.execute(
            "SELECT u.userID, u.firstname, u.lastname, u.description, c.category, u.labID, l.lab_name, u.email FROM Users_tbl u, LabInfo_tbl l, UserCategories_tbl c WHERE u.username="******" AND u.password=MD5(" + ` pwd ` +
            ") AND u.labID=l.labID AND c.categoryID=u.category AND u.status='ACTIVE' AND l.status='ACTIVE'"
        )
        result = cursor.fetchone()

        if result:
            uid = int(result[0])
            firstname = result[1]
            lastname = result[2]
            description = result[3]
            category = result[4]
            labID = int(result[5])
            labname = result[6]
            email = result[7]

            newLab = Laboratory(labID, labname)
            newUser = User(uid, uname, firstname, lastname, description,
                           newLab, category, email, pwd)

            self.__user = newUser
            return True
        else:
            return False
Ejemplo n.º 4
0
    def getUserByDescription(self, descr):

        db = self.db
        cursor = self.cursor

        cursor.execute(
            "SELECT u.userID, u.username, u.firstname, u.lastname, c.category, u.labID, l.lab_name, u.email, u.password FROM Users_tbl u, LabInfo_tbl l, UserCategories_tbl c WHERE u.description="
            + ` descr ` +
            " AND u.labID=l.labID AND c.categoryID=u.category AND l.status='ACTIVE'"
        )
        result = cursor.fetchone()

        if result:
            uid = int(result[0])
            username = result[1]
            firstname = result[2]
            lastname = result[3]
            category = result[4]
            labID = int(result[5])
            labname = result[6]
            email = result[7]
            password = result[8]

            newLab = Laboratory(labID, labname)
            newUser = User(uid, username, firstname, lastname, descr, newLab,
                           category, email, password)

            return newUser

        else:
            # Nov. 15/07: Retry, just select userID and category and labID - other attributes may be omitted - for ACTIVE users only
            cursor.execute(
                "SELECT u.userID, c.category FROM Users_tbl u, UserCategories_tbl c WHERE u.description="
                + ` descr ` +
                " AND c.categoryID=u.category AND u.status='ACTIVE'")
            result = cursor.fetchone()

            if result:
                uid = int(result[0])
                category = result[1]
                newUser = User(uid, "", "", "", descr, None, category, "", "")

                return newUser
Ejemplo n.º 5
0
    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() `)
Ejemplo n.º 6
0
    def __init__(self,
                 cType="",
                 cSize=0,
                 nRows=0,
                 nCols=0,
                 cName=0,
                 cLab=0,
                 cDesc="",
                 c_props=[]):

        self.__cont_type = cType
        self.__cont_size = cSize
        self.__rows = nRows
        self.__cols = nCols
        self.__num_wells = nRows * nCols
        self.__cont_name = cName
        self.__cont_desc = cDesc
        self.__cont_lab = Laboratory(cLab)

        # Assign properties based on container type
        if cType == 'Vector':
            self.__properties = ['Method ID', 'Concentration']

        elif cType == 'Glycerol Stocks':
            self.__properties = ['Bacteria Strain']

        elif cType == 'Oligo':
            self.__properties = ['Concentration', 'Reagent Source']

        elif cType == 'Insert':
            self.__properties = [
                'Concentration', 'Alternate ID', "5' digest/3' Digest"
            ]

        elif cType == 'Cell Line':
            self.__properties = [
                'Isolate Name', 'Plates/Vial', 'Date', 'Person', 'Passage'
            ]

        # Jan. 3/10
        else:
            self.__properties = c_props
Ejemplo n.º 7
0
    def getUserByID(self, uid):

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

        db = self.db  # make local copies of global variables for easy access
        cursor = self.cursor

        newUser = None

        # ATT'N: Removed 'user status=ACTIVE' clause, since this function may be called to retrieve a project owner, who may be gone, but his/her packet is still active

        #print "SELECT u.username, u.firstname, u.lastname, u.description, c.category, u.labID, l.lab_name, u.email, u.password FROM Users_tbl u, LabInfo_tbl l, UserCategories_tbl c WHERE u.userID=" + `uid` + " AND u.labID=l.labID AND c.categoryID=u.category AND l.status='ACTIVE'"

        cursor.execute(
            "SELECT u.username, u.firstname, u.lastname, u.description, c.category, u.labID, l.lab_name, u.email, u.password FROM Users_tbl u, LabInfo_tbl l, UserCategories_tbl c WHERE u.userID="
            + ` uid ` +
            " AND u.labID=l.labID AND c.categoryID=u.category AND l.status='ACTIVE'"
        )

        result = cursor.fetchone()

        if result:
            username = result[0]
            firstname = result[1]
            lastname = result[2]
            description = result[3]
            category = result[4]
            labID = int(result[5])
            labname = result[6]
            email = result[7]
            password = result[8]

            newLab = Laboratory(labID, labname)
            newUser = User(uid, username, firstname, lastname, description,
                           newLab, category, email, password)

        return newUser
	def findProjectMembers(self, projectID, role):

		db = self.db
		cursor = self.cursor

		#print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
		#print					# DITTO
		
		uHandler = UserHandler(db, cursor)
		
		members = []
		
		# include status='ACTIVE' clause; otherwise a DEP member might be selected causing an error
		cursor.execute("SELECT p.memberID, u.firstname, u.lastname, u.description, u.category, u.labID, l.lab_name, l.description FROM ProjectMembers_tbl p, Users_tbl u, LabInfo_tbl l WHERE p.packetID=" + `projectID` + " AND p.role=" + `role` + " AND u.userID=p.memberID AND l.labID=u.labID AND p.status='ACTIVE' AND u.status='ACTIVE' AND l.status='ACTIVE'")
		results = cursor.fetchall()
				
		for result in results:
			
			memberID = int(result[0])
			
			# removed, more efficient and accurate to rewrite query here and include 'status=ACTIVE' clause
			#member = uHandler.getUserByID(memberID)
			
			memberFirstName = result[1]
			memberLastName = result[2]
			memberFullName = result[3]
			memberCategory = int(result[4])
			memberLabID = result[5]
			
			labName = result[6]
			labDescr = result[7]
			tempLab = Laboratory(memberLabID, labName, labDescr)
			
			member = User(memberID, "", memberFirstName, memberLastName, memberFullName, tempLab, memberCategory)
			
			members.append(member)
		
		return members
Ejemplo n.º 9
0
    def findAllMembersInCategory(self, category, active, oper='=', labID=0):

        db = self.db
        cursor = self.cursor

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

        ucMapper = UserCategoryMapper(db,
                                      cursor)  # for category name/id mapping
        category_Name_ID_Map = ucMapper.mapCategoryNameToID()

        members = []  # list of User **objects**

        # When we include 'status=ACTIVE' restriction in the query, a DEP owner of an active project is not shown in project view.  However, we should not add DEP members to a project.
        # Therefore, the calling function should specify whether it wants to restrict query by status.
        # If 'active' parameter is True, add 'status=ACTIVE' clause
        # In any case, **remember to fill in 'category' column for DEP users before the launch**

        if labID == 0:
            if active:
                cursor.execute(
                    "SELECT userID, firstname, lastname, description FROM Users_tbl u, UserCategories_tbl c WHERE c.categoryID "
                    + oper + " " + ` category_Name_ID_Map[category] ` +
                    " AND c.categoryID=u.category AND u.firstname <> '' AND u.lastname <> '' AND u.description <>'' AND u.status='ACTIVE'"
                )
            else:
                cursor.execute(
                    "SELECT userID, firstname, lastname, description FROM Users_tbl u, UserCategories_tbl c WHERE c.categoryID "
                    + oper + " " + ` category_Name_ID_Map[category] ` +
                    " AND c.categoryID=u.category AND u.firstname <> '' AND u.lastname <> '' AND u.description <>''"
                )
        else:
            if active:
                cursor.execute(
                    "SELECT u.userID, u.firstname, u.lastname, u.description, l.lab_name FROM Users_tbl u, UserCategories_tbl c, LabInfo_tbl l WHERE c.categoryID "
                    + oper + " " + ` category_Name_ID_Map[category] ` +
                    " AND c.categoryID=u.category AND u.firstname <> '' AND u.lastname <> '' AND u.labID="
                    + ` labID ` + " AND l.labID=u.labID AND u.status='ACTIVE'")
            else:
                cursor.execute(
                    "SELECT u.userID, u.firstname, u.lastname, u.description, l.lab_name FROM Users_tbl u, UserCategories_tbl c, LabInfo_tbl l WHERE c.categoryID "
                    + oper + " " + ` category_Name_ID_Map[category] ` +
                    " AND c.categoryID=u.category AND u.firstname <> '' AND u.lastname <> '' AND u.description <>'' AND u.labID="
                    + ` labID ` + " AND l.labID=u.labID")

        results = cursor.fetchall()

        for result in results:

            userID = int(result[0])
            firstName = result[1]
            lastName = result[2]
            description = result[3]

            tmpLab = Laboratory(labID)

            if len(result) == 5:
                labName = result[4]
                tmpLab.setName(labName)

            # create a User object
            tmpUser = User(userID, "", firstName, lastName, description,
                           tmpLab, category, "", "")
            members.append(tmpUser)

        return members
Ejemplo n.º 10
0
    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())
Ejemplo n.º 11
0
 def setContainerLab(self, cLab):
     newLab = Laboratory(cLab)
     self.__cont_lab = newLab
Ejemplo n.º 12
0
    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())
Ejemplo n.º 13
0
import dash
from laboratory import Laboratory
import dash_bootstrap_components as dbc
from flask_caching import Cache
from laboratory.processing import Sample

lab = Laboratory()

stylesheets = [
    {
        'href': 'https://use.fontawesome.com/releases/v5.15.1/css/all.css',
        'rel': 'stylesheet',
        'integrity':
        'sha384-vp86vTRFVJgpjF9jiIGPEEqYqlDwgyBgEF109VFjmqGmIY/Y4HV4d3Gp2irVfcrp',
        'crossorigin': 'anonymous'
    },
    "assets\css\sb-admin-2.css",
    dbc.themes.DARKLY,
]

external_scripts = [
    "assets\js\jquery.min.js",
    "assets\js\\bootstrap.bundle.min.js",
    "assets\js\jquery.easing.min.js",
    "assets\js\sb-admin-2.js",
]

app = dash.Dash(
    __name__,
    external_stylesheets=stylesheets,
    external_scripts=external_scripts,