def insertContainer(self, contTypeID, cSize, cName, cDesc, cLab, storage_type, storage_name, storage_address, cont_shelf, cont_rack, cont_row, cont_col): db = self.db cursor = self.cursor # for easy access ltHandler = LocationTypeHandler(db, cursor) # find 'container type' and 'container size' foreign keys #contTypeID = ltHandler.containerTypeToID(cType) cType = ltHandler.findContainerTypeName(contTypeID) contSizeID = ltHandler.containerSizeToID(cSize) # find the next available number in this container group to assign to the new container contNum = self.findNextContainerNumberInGroup(contTypeID) # check if this is an isolate active container isoActive = ltHandler.isIsoActive(contTypeID) # generate barcode bcNum = self.findNextContainerBarcodeNumber(contTypeID, contSizeID, cLab) barcode = self.generateBarcode(contTypeID, contSizeID, bcNum, cLab) cursor.execute("INSERT INTO Container_tbl(contGroupID, contTypeID, contGroupCount, name, container_desc, labID, barcode, location, locationName, address, shelf, rack, row_number, col_number) VALUES(" + `contTypeID` + ", " + `contSizeID` + ", " + `contNum` + ", " + `cName` + ", " + `cDesc` + ", " + `cLab` + ", " + `barcode` + ", " + `storage_type` + ", " + `storage_name` + ", " + `storage_address` + ", " + `cont_shelf` + ", " + `cont_rack` + ", " + `cont_row` + ", " + `cont_col` + ")") newContID = int(db.insert_id()) # Store container-specific properties nRows = ltHandler.findNumRows(contSizeID) nCols = ltHandler.findNumCols(contSizeID) container = Container(cType, cSize, nRows, nCols, cName, cLab, cDesc) #props = container.getContainerProperties() props = ltHandler.findContainerTypeProperties(contTypeID) #print "Content-type:text/html" #print #print storage_type #print `props` self.insertContainerProperties(newContID, props) return newContID
def exportPlate(self, form): db = self.__db cursor = self.__cursor hostname = self.__hostname lHandler = LocationHandler(db, cursor) ltHandler = LocationTypeHandler(db, cursor) rHandler = ReagentHandler(db, cursor) prepPropMapper = PrepPropertyMapper(db, cursor) cTypeMapper = ContainerTypeMapper(db, cursor) prepProp_Name_ID_Map = prepPropMapper.mapPrepPropNameToID() prepProp_ID_Name_Map = prepPropMapper.mapPrepPropIDToName() contType_Name_ID_Map = cTypeMapper.mapContainerTypeNameToID() contID = int(form.getvalue("contID")) contName = lHandler.findContainerName(contID) contArray = contName.split(" ") fname = string.join(contArray, "_") + ".csv" wells = lHandler.findContainerWells(contID) content = "" # debug #print "Content-type:text/html" #print contType = lHandler.findContainerType(contID) contTypeID = contType_Name_ID_Map[contType] contProps = ltHandler.findContainerTypeProperties( contTypeID) # array of names iso_active = ltHandler.isIsoActive(contTypeID) if iso_active == 'YES': isoActive = True else: isoActive = False #print `contProps` # Header if isoActive: content = "Well,OpenFreezer ID,Selected Isolate,Flag,Reference,Comments," else: content = "Well,OpenFreezer ID,Flag,Reference,Comments," contPropIDs_sorted = [] for cPropName in contProps: cPropID = prepProp_Name_ID_Map[cPropName] contPropIDs_sorted.append(cPropID) contPropIDs_sorted.sort() for cPropID in contPropIDs_sorted: cPropName = prepProp_ID_Name_Map[cPropID] content += cPropName + ',' content += '\n' numRows = lHandler.getNumRows(contID) numCols = lHandler.getNumCols(contID) plate = {} for well in wells: wellRowNum = well.getWellRowNumber() #print wellRowNum if plate.has_key(wellRowNum): plate[wellRowNum].append(well) else: tmp_ar = [] tmp_ar.append(well) plate[wellRowNum] = tmp_ar plate.keys().sort() for rowNum in range(1, numRows + 1): if plate.has_key(rowNum): wellRow = plate[rowNum] wellRowNum = rowNum wellRowLetter = Well.convertRowNumberToChar(wellRowNum) wellRow.sort() #print "ROW " + `rowNum` for colNum in range(1, numCols + 1): for well in wellRow: wellID = well.getWellID() #print wellID wellCol = well.getWellColumn() if wellCol == colNum: #print "COLUMN " + `wellCol` wellCoords = wellRowLetter + ":" + ` wellCol ` # get prep, reference, comments, flag prepID = lHandler.findPrepIDInWell(wellID) #print prepID prepRef = lHandler.findPrepReference(prepID) #print prepRef if not prepRef: prepRef = "" prepComms = lHandler.findPrepComments(prepID) #print prepComms if not prepComms: prepComms = "" prepFlag = lHandler.findPrepFlag(prepID) #print prepFlag # get isolate number, selected isolate isoID = lHandler.findPrepIsolateID(prepID) isoNum = lHandler.findIsolateNumber(isoID) isoSelected = lHandler.isSelectedIsolate(isoID) # get prep property values prepPropValues = lHandler.findAllPrepProperties( prepID) # find the LIMS ID of the reagent stored in this well expID = lHandler.findExperimentIDByIsolate(isoID) rID = lHandler.findReagentIDByExperiment(expID) limsID = rHandler.convertDatabaseToReagentID(rID) # Output: Well , Reagent-isolate , Selected , Flag , Reference , Comments , Attributes [name1 , name2 , name3....] if isoActive: content += wellCoords + ',' + limsID + "-" + ` isoNum ` + ',' + isoSelected + ',' + prepFlag + ',' + prepRef + ',' + prepComms + "," else: content += wellCoords + ',' + limsID + ',' + prepFlag + ',' + prepRef + ',' + prepComms + "," prepPropIDs_sorted = {} prepProps = {} for pProp in prepPropValues: pName = pProp.getPropName() pVal = pProp.getPropValue() prepProps[pName] = pVal prepProps.keys().sort( ) # might not be necessary but still for cPropID in contPropIDs_sorted: cPropName = prepProp_ID_Name_Map[cPropID] if prepProps.has_key(cPropName): pVal = prepProps[cPropName] content += pVal + ',' else: content += ',' content += '\n' print "Content-type: application/octet-stream" print "Content-Disposition: attachment; name=" + fname print print content