Пример #1
0
	def insertUpdateCheck(self, fd, warning= ""):
		self.dict['title'] = "%s GeneWiki Entry for %s" % (self.action.title(), self.symbol)
		#mailsrch = re.compile('([\w\-][\w\-\.]*@[\w\-][\w\-\.]+[a-zA-Z]{1,4})([\s,;])*')
		mailsrch = re.compile('([\w\-][\w\-\.]*)@([\w\-\.]+)\.([a-zA-Z]{1,4})([\s,;])*')
		httpsrch = re.compile('((?:http|ftp|gopher|file)://(?:[^ \n\r<\)]+))([\s,;])*')
		if not self.comment or not self.email:
			heading = self.dict['title']
			detail = ["Please don't leave text field or email field empty."]
			self.error(heading=heading,detail=detail,error="Error")
			return
		if self.action == 'update' and not self.reason:
			heading = self.dict['title']
			detail = ["Please submit your reason for this modification."]
			self.error(heading=heading,detail=detail,error="Error")
			return
		if len(self.comment) >500:
			heading = self.dict['title']
			detail = ["Your entry is more than 500 characters."]
			self.error(heading=heading,detail=detail,error="Error")
			return
		if self.email and re.sub(mailsrch, "", self.email) != "":
			heading = self.dict['title']
			detail = ["The format of your email address is incorrect."]
			self.error(heading=heading,detail=detail,error="Error")
			return
		
		if self.weburl == "http://":
			self.weburl = ""
		
		if self.weburl and re.sub(httpsrch, "", self.weburl) != "":
			heading = self.dict['title']
			detail = ["The format of web resource link is incorrect."]
			self.error(heading=heading,detail=detail,error="Error")
			return
		
		if self.pubmedid:
			try:
				test = map(int, string.split(self.pubmedid))
			except:
				heading = self.dict['title']
				detail = ["PubMed IDs can only be integers."]
				self.error(heading=heading,detail=detail,error="Error")
				return
		
		form = HT.Form(cgi= os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), name='addgenerif',submit=HT.Input(type='hidden'))
		recordInfoTable = HT.TableLite(border=0, cellspacing=1, cellpadding=5,align="center")
		
		addButton = HT.Input(type='submit',name='submit', value='%s GeneWiki Entry' % self.action.title(),Class="button")
		hddn = {'curStatus':'insertResult', 'FormID':'geneWiki', 'symbol':self.symbol, 
			'comment':self.comment, 'email':self.email, 'species':self.species, 
			'action':self.action, 'reason':self.reason}
		if self.Id:
			hddn['Id']=self.Id
		
		formBody = HT.TableLite()
		
		formBody.append(HT.TR(
			HT.TD(HT.Strong("Species: ")), 
			HT.TD(width=10), 
			HT.TD(string.split(self.species, ":")[0])
		))
		if self.pubmedid:
			try:
				formBody.append(HT.TR(
					HT.TD(HT.Strong("PubMed IDs: ")), 
					HT.TD(width=10), 
					HT.TD(self.pubmedid)
				))
				hddn['pubmedid'] = self.pubmedid
			except:
				pass
		if self.weburl:
			try:
				formBody.append(HT.TR(
					HT.TD(HT.Strong("Web URL: ")), 
					HT.TD(width=10), 
					HT.TD(HT.Href(text=self.weburl, url=self.weburl, Class='fwn'))
				))
				hddn['weburl'] = self.weburl
			except:
				pass
		formBody.append(HT.TR(
			HT.TD(HT.Strong("Gene Notes: ")), 
			HT.TD(width=10), 
			HT.TD(self.comment)
		))
		formBody.append(HT.TR(
			HT.TD(HT.Strong("Email: ")), 
			HT.TD(width=10), 
			HT.TD(self.email)
		))
		if self.initial:
			formBody.append(HT.TR(
				HT.TD(HT.Strong("Initial: ")), 
				HT.TD(width=10), 
				HT.TD(self.initial)
			))
			hddn['initial'] = self.initial
		
		if self.genecategory:
			cTD = HT.TD()
			if type(self.genecategory) == type(""):
				self.genecategory = string.split(self.genecategory)
			self.cursor.execute("Select Id, Name from GeneCategory where Id in (%s) order by Name " % string.join(self.genecategory, ', '))
			results = self.cursor.fetchall()
			for item in results:
				cTD.append(item[1], HT.BR())
				
			formBody.append(HT.TR(
				HT.TD(HT.Strong("Category: ")), 
				HT.TD(width=10), 
				cTD
			))
			hddn['genecategory'] = string.join(self.genecategory, " ")
			
		formBody.append(HT.TR(
			HT.TD(
				HT.BR(), HT.BR(), 
				HT.Div("For security reasons, enter the code (case insensitive) in the image below to finalize your submission"), HT.BR(), 
				addButton, HT.Input(type="password", size = 25, name="password"), 
			colspan=3)
		))
		
		
		code = webqtlUtil.genRandStr(length=5, chars="abcdefghkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789")
		filename= webqtlUtil.genRandStr("Sec_")
		hddn['filename'] = filename 
		securityCanvas = pid.PILCanvas(size=(300,100))
		Plot.plotSecurity(securityCanvas, text=code)
		
		os.system("touch %s_.%s" % (os.path.join(webqtlConfig.IMGDIR,filename), code))
		securityCanvas.save(os.path.join(webqtlConfig.IMGDIR,filename), format='png')
		
		formBody.append(HT.TR(
			HT.TD(HT.Image("/image/"+filename+".png"), colspan=3)
		))
		
		hddn['filename'] = filename 
		TD_LR = HT.TD(valign="top", bgcolor="#eeeeee")
		title = HT.Paragraph("%s GeneWiki Entry for %s" % (self.action.title(), self.symbol), Class="title")
		
		form.append(HT.P(), HT.Blockquote(formBody))
		
		for key in hddn.keys():
			form.append(HT.Input(name=key, value=hddn[key], type='hidden'))
			
		TD_LR.append(title, HT.Blockquote(warning, Id="red"), form)
		
		self.dict['body'] = TD_LR