Kini Natekar writes:
I have got a html form which accepts an input from the user. This input has to be passed to a Python script, as a parameter, which is added as an external method in zope. Is there any way to do this ? Your method:
def my_method(REQUEST): '''my_method interpreting *REQUEST*.form.''' form= REQUEST.form # this is a dictionary containing form # variables and associated values ..... If you like, you can directly use it as form action. But probably, you will wrap it into a DTML method: DTML wrapper: ..... <dtml-call "my_method(REQUEST)"> ..... Dieter
Wouldn't it be better to pass in self? As in: def my_method(self,REQUEST=None): '''my_method interpreting *REQUEST*.form.''' if REQUEST is None: REQUEST=self.REQUEST # safety_valve in case you forget to pass in REQUEST form= REQUEST.form # this is a dictionary containing form # variables and associated values ----- Original Message ----- From: "Dieter Maurer" <dieter@handshake.de> To: "Kini Natekar" <kininatekar@yahoo.com> Cc: <zope@zope.org> Sent: Wednesday, November 22, 2000 8:43 PM Subject: Re: [Zope] External Methods | Kini Natekar writes: | > I have got a html form which accepts an input from | > the user. This input has to be passed to a Python | > script, as a parameter, which is added as an external | > method in zope. | > Is there any way to do this ? | Your method: | | def my_method(REQUEST): | '''my_method interpreting *REQUEST*.form.''' | form= REQUEST.form # this is a dictionary containing form | # variables and associated values | ..... | | | If you like, you can directly use it as form action. | But probably, you will wrap it into a DTML method: | | DTML wrapper: | | ..... | <dtml-call "my_method(REQUEST)"> | ..... | | | Dieter | | | _______________________________________________ | Zope maillist - Zope@zope.org | http://lists.zope.org/mailman/listinfo/zope | ** No cross posts or HTML encoding! ** | (Related lists - | http://lists.zope.org/mailman/listinfo/zope-announce | http://lists.zope.org/mailman/listinfo/zope-dev )
Phil Harris writes:
Wouldn't it be better to pass in self?
As in:
def my_method(self,REQUEST=None): '''my_method interpreting *REQUEST*.form.''' if REQUEST is None: REQUEST=self.REQUEST # safety_valve in case you forget to pass in REQUEST form= REQUEST.form # this is a dictionary containing form # variables and associated values
I would pass in "self" only if I need it (to access Zope objects in the method). I can trust ZPublisher that it will pass REQUEST. Thus, there is no danger to forget passing REQUEST in this case. And if I call the method directly from DTML, the danger to forget passing "this()" (to be passed to 'self') is as great as to forget passing "REQUEST". Just, that "this()" is more nasty than "REQUEST" (requires more Zen). Really knowledgable people can use: def my_method(self): REQUEST= self.REQUEST .... and then call it in DTML by <dtml-call my_method> This will work, as an external method passes the folder containing the method as the first argument, provided that 1. the first argument is called "self" 2. the method is called with precisely one argument less than the number of defined arguments. The above "dtml-call" will result in "my_method()". Therefore, both rules are satisfied. However, should we really propose this? I tend to favour the following rule: Whenever you call an external method from DTML, *ALWAYS* pass all parameters explicitely. Dieter
Phil Harris wrote:
Wouldn't it be better to pass in self?
As in:
def my_method(self,REQUEST=None): '''my_method interpreting *REQUEST*.form.''' if REQUEST is None: REQUEST=self.REQUEST # safety_valve in case you forget to pass in REQUEST form= REQUEST.form # this is a dictionary containing form # variables and associated values
Hello, Ok Sirs, I'm very late in my checking my mailbox ;-) I've a question in this code above : How can I get the values of a dictionary form? In my Method, I used form.values(), form.Name_Of_Variable_OF_my_form, but it is not working. Thanks Marcus Mendes
Try... for k,v in form.items(): k should contain the key name v should contain the value Otherwise... value = form['Name_Of_Variable_OF_my_form'] Hope that helps. Ryan
Hello,
Ok Sirs, I'm very late in my checking my mailbox ;-)
I've a question in this code above : How can I get the values of a dictionary form? In my Method, I used form.values(), form.Name_Of_Variable_OF_my_form, but it is not working.
Thanks
Marcus Mendes
"Ryan M. Dolensek" wrote:
Try...
for k,v in form.items(): k should contain the key name v should contain the value
Otherwise...
value = form['Name_Of_Variable_OF_my_form']
Hope that helps.
Ryan
Hello,
Ok Sirs, I'm very late in my checking my mailbox ;-)
I've a question in this code above : How can I get the values of a dictionary form? In my Method, I used form.values(), form.Name_Of_Variable_OF_my_form, but it is not working.
Thanks
Marcus Mendes
Hello again, I've got the follow content : Key Error SERVER_NAME, that is, Look at my code, please: def log_info(REQUEST): if REQUEST is None: REQUEST=self.REQUEST form= REQUEST.form try: log=open('/home/mvmendes/testes_zope/log.txt', 'a') except IOError: log=open('/home/mvmendes/testes_zope/log.txt', 'w') server = form['SERVER_NAME'] connection = form['CONNECTION_TYPE'] line='Server: %s, Connection type : %s\n' % ( server, connection ) log.write(line) log.close() return I calling my external method using : <dtml-call "grava_arq(REQUEST)"> I also tried with "for" command but isn't working. Can you help me? Thanks in advance. Marcus Mendes
participants (4)
-
Dieter Maurer -
Marcus Mendes -
Phil Harris -
Ryan M. Dolensek