[Zope] Why is it so hard to do simple things?
Lennart Regebro
lennart@torped.se
Wed, 8 May 2002 09:03:51 +0200
From: "John Adams" <jadams@inktomi.com>
> If I was doing this in perl it'd be quite easy; I could check the query
> variable, and act on it -- but now I have to deal with things like not
> being able to even examine the variable without throwing an exception
This has nothing to do with either Zope or Python. It has to do with how
HTML forms are done, and yes, I agree that the people designing that
standard are a bunch of morons.
Checkboxes in form submissions has only one state. Yes, thats stupid, but
thats how it is. Either they are checked or they don't exist at all. It is
therefore impossible to know from the form submission whether a certain
variable is unchecked or simply does not exist.
There are basically two solutions to this.
1. Define all the variables in the python method called, and let have
defaults on the optional variables. LIke so:
def form_submission_method( self, variable1, variable2,
thidisacheckbox=None, REQUEST):
#Now you can be sure there is a "thisisacheckbox" variable, and it will
either be set, or it will be None
if thisisacheckbox:
return "It's checked!"
2. Do a check like this:
if hasattr(request,'perm_or_temp') and request.perm_or_temp == 'P':
Btw, when doing forms, I suggest you look at formulator. It helps you
validate forms.
Best Regards
Lennart Regebro
Torped Strategi och Kommunikation AB
http://easypublisher.torped.se/english/