[mod_python] R: servlet form against publisher

Manera, Villiam vmanera at manord.com
Tue Sep 7 10:52:49 EDT 2004


Date: 03 Sep 2004 11:18:18 -0400
From: Daniel Popowich <dpopowich at comcast.net>
Subject: Re: [mod_python] servlet form against publisher
To: mod_python user mailing list <mod_python at modpython.org>
Message-ID: <m23c1zbcud.fsf at fenway.local.>


Manera, Villiam writes:

>> ........
>> Difference in retrieve fields from Form between publisher and servlet:
>> 
>> In publischer : req.form = util.FieldStorage(req, keep_blank_values=1)
>> 
>> In servlet : self.form = util.FieldStorage(self.req)        
>> 
>> So in servlet the fields not filled are not inserted in  self.form.list
>> 
>> Why this choice??

>Two reasons:

>1) Assuming you're going to retrieve the field like this:
>
>     field = self.form.getfirst('fieldname', somedefault)
>
>   then returning blank values is meaningless: regardless of whether
>   or not the field was blank you'll get your default.

>2) With the mechanics of query_vars and form_vars in mpservlets, re
>   automatic retrieval of fields and setting them as instance
>   variables and setting defaults for missing fields, there is no
>   need to keep blank values.

>Daniel Popowich

===================================== remark ==================================

Ok, I suppose this reason, and I agree.
But for me will be useful to have a variable in order to choose keep_blank_values=1 when I need it.

And I need it for most of the routine already written that I'm modifying in order to work fine if they are called from publisher or from servlet.
This is un example of help_cliente.mps:

------------------------------
from _docBase_mps import *

class help_cliente(docBase_mps_FinestreHelp):
	def write_content(self):
		doc = finestre_help.help_cliente(self)
		self.writeln(str(doc) %self.session)
------------------------------
this is a wrap around finestre_help.help_cliente that work under publisher

and below a class with the prep redefined because there no choice for keep_blank_values=1.
With keep_blank_values = 1 will be possible do in high level:
		pard = self.session
		for F in self.form.list:
				if pard.has_key(F.name): 
					if type(pard[F.name]) == ListType: pard[F.name].append(F.value)
					else : pard[F.name] = [pard[F.name],F.value]
				else: pard[F.name] = F.value 
and all the fields of the form are inserted in self.session, that is the scenario that old 
publisher program expect	
#=========================== docBase_mps_FinestreHelp ==============================
class docBase_mps_FinestreHelp(docBase_mps):
	title = ''
	.....
	
	def prep(self):
		docBase_mps.prep(self)
		self.session['suffisso_funzione_js'] = self.form.getfirst('suffisso_funzione_js')
		self.session['nome_colonna_input'] = self.form.getlist('nome_colonna_input')
		self.session['nome_returnback'] = self.form.getlist('nome_returnback')
		for el in self.form.getlist('nome_returnback'):
			self.session[el] = self.form.getfirst(el,'')


Villiam Manera



More information about the Mod_python mailing list