Re: formEncode - complicate validate form

"Grzesiek Slusarek" <[email protected]>
Newsgroups gmane.comp.python.formencode
Organization Poczta Wirtualnej Polski S.A. http://www.wp.pl/
Message-ID <[email protected]>
Hi Ian.
Thanks for any help but I still have problem with form encode (I'm 
using form encode 0.5.1). I write validator for entire Form and I in 
that formValidator I called one validator to validate file that I 
want to upload only when one of radio has set value file. The problem 
is that validator which validate file even if raise exception when 
file is not correct, validation of all form is a success. Here is the 
code
first my all schema:
class VerifyTitleValidationSchema(Schema):
	pType = validators.String(not_empty=True)
	pField1 = validators.String(if_missing="")
	pField2 = validators.String(if_missing="")
	chained_validators = [RequireIfEqual()]

now RequireIfEqual:
class RequireIfEqual(FormValidator):
	# Field name:
	field = 'pType'
	# expected value:
	value = 'own'
	other_field = 'pThumbnailFile'
	other_validator = Thumbnail
	def _to_python(self, form, state):
	if form.get(self.field) == self.value:
       try:
		conv = 
self.other_validator.to_python(form.get(self.other_field),state)
	 except:
		raise Invalid('Wrong_File_Type', form[self.other_field], 
state)
	 form = form.copy()
	 form[self.other_field] = conv
	return form
      
class Thumbnail(FancyValidator):
  def _to_python(self,value,state):
    if value.filename != '' and len(value.value)!= 0:
	NewIconName = generateUniqueName()+".png"
	IconPath = ScreenshotStoragePath + NewIconName
	try:
	  newFile = open(IconPath,'wb')
	  while 1:
	    data = value.file.read(8192)
	    if not data: 
		break
	    newFile.write(data)
	    newFile.close()
	  if IconManager.validateIcon(IconPath) is False:
		raise Invalid('WrongFileFormat1', value, state)
	  value = NewIconName
	  return value
	except:
	  raise Invalid('WrongFileFormat2', value, state)
    else:
	raise Invalid('There is no File!', value, state)

So the Problem looks like this: I have raised Invalid exception in 
Thumbnail validator but this exception  doesn't change the fact that 
schema is validated succesfull. How is it possible?
On my output i get message: INFO Improper validation Wrong_File_Type
Thanks for any help
Gregor

----------------------------------------------------
Seria "The Great Composers" do nabycia w salonach Empik.
Szopen, Bach, Mozart, Vivaldi, Puccini, Czajkowski.
Każdy tytuł to 2CD+DVD w ekskluzywnym, kartonowym wydaniu.
http://klik.wp.pl/?adr=http%3A%2F%2Fadv.reklama.wp.pl%2Fas%2Fcomposers.html&sid=856



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.