Exemplo n.º 1
0
def selectData(tableName,fieldNameArray,parameterDic):
    #prepare db
    import util.dbOperator as dbor
    dbConn,dbCursor=dbor.prepareDb()
    
    #fetch data
    sqlString="select distinct "+(",".join(fieldNameArray))+" from "+tableName
    if (parameterDic):
        parameterData=[]
        parameterTitle=[]
        for k,v in parameterDic.iteritems():
            parameterData.append(v)
            parameterTitle.append(k)
        sqlString=sqlString+" where ("+(",".join(parameterTitle))+")=('"+("','".join(parameterData))+"')"
#     logger.debug(sqlString)
    
    sqlResultData,sqlResultCount=dbor.sqlSelect(sqlString,dbCursor)
#     logger.debug(sqlResultCount)
    #close
    dbConn.close()
    return sqlResultData,sqlResultCount
Exemplo n.º 2
0
def assemble(request,queryName="component5Design"):
    inputHtmlPath,resultHtmlPath=htmlPage(queryName)
    from forms import formDict# 引入我们创建的表单类
    if request.method != 'POST':# 当正常访问时
        if queryName=="component5Design":
            organismList=["E.coli","S.cerevisiae","C.glutamicum",]
            navL1LinkList=[]
            from models import NavLink
            for organism in organismList:
                navL1LinkList.append(NavLink(organism,""))
        #backup
        #form = formDict[queryName]()
    else:# 当提交表单时
        form=formDict[queryName](request.POST,request.FILES)
        if form.is_valid():# 如果提交的数据合法
            formData=form.cleaned_data
            
            if queryName=="designModule":
                assembleComponentList=request.POST.get("assembleComponentList")
                len_ha=request.POST.get("len_ha")
                len_ha=int(len_ha) if len_ha else 20
                
                import util.dataEncapsulater as deer
                #design primer
                from func.designPrimer import primerList
                assembleComponentListDict=deer.decapsulateJson(assembleComponentList)
                primerDataListDict=primerList(assembleComponentListDict,len_ha)
                primerDataList=deer.encapsulateJson(primerDataListDict)
                #join assembleComponent
#                 from func.joinComponent import joinSequence
#                 wholeSequence=joinSequence(assembleComponentListDict)
                request.session["assembleComponentList"]=assembleComponentList
                request.session["len_ha"]=len_ha
                request.session["primerDataList"]=primerDataList
                
            if queryName=="sendAssemble":
                #store user_submit
                #prepare db
                import util.dbOperator as dbor
                dbConn,dbCursor=dbor.prepareDb()
                #store
                sqlString="insert into user_submit (assembleComponentList,len_ha,submit_time) values (\'"+request.session["assembleComponentList"]+"\',"+str(request.session["len_ha"])+",now())"
                #backup 存的是单引号且字典内部顺序非原始 sqlString="insert into test (assembleComponentList,submit_time) values (\""+str(assembleComponentListDict)+"\",now())"
                isContinue=dbor.sqlDo(sqlString,dbCursor,dbConn)
                if(not isContinue):
                    logger.warning(sqlString)
                #close
                dbConn.close()
                #email assemble list
                wetlab_email='*****@*****.**'
                subject="Assemble component"
                content="Assemble Component\n"
                content+="Assemble Component List: \n"+request.session["assembleComponentList"]+"\n"
                content+="Primer Data List: \n"+request.session["primerDataList"]+"\n"
                content+="Length of homologous arm: \n"+str(request.session["len_ha"])+"\n"
                msg=EmailMultiAlternatives(subject,content,from_email,[wetlab_email,])
                msg.send()
                
                httpString="<div><h3>Design biocomponent</h3></div>\
                            <div><p>Task has been sent to laboratory</p>\
                                <p>Please contact to <a href\""+wetlab_email+"\">"+wetlab_email+"</a> for wet-lab technical support and "+"<a href\"[email protected]\">Yi Yang</a>"+" for computing-lab technical support</p></div>"
                
                
                #backup
                #symbolList=symbol.split(",")
            #calculate success, direct to the result page
            return render(request,resultHtmlPath,locals())
    #form = formDict[queryName]()
    return render(request,inputHtmlPath,locals())