question on python script, dtml method and options
I use the following template often. When using a page template for my MAIN page, I access the error and message vars with: <p tal:content="options/error">Error message</p> <p tal:content="options/message">Reg. Message</p> How would I access them when I use a dtml-method for my MAIN page? <dtml-var error> and <dtml-var message> don't seem to work. Python Script - index_html: # Import a standard function, and get the HTML request and response objects. from Products.PythonScripts.standard import html_quote request = container.REQUEST RESPONSE = request.RESPONSE error='' message='' if not request.has_key('next_state'): return container['MAIN'](context, request, error=error, message=message) elif request.get('next_state') == 'Do Something': try: doSomething() message = message + 'We did something' except: error = error + 'Error in doSomething()' elif request.get('next_state') == 'Do Something Else': try: doSomethingElse() message = message + 'We did something else' except: error = error + 'Error in doSomethingElse()' return container['MAIN'](context, request, error=error, message=message)
On 7/19/05, Erik Myllymaki <erik.myllymaki@aviawest.com> wrote:
I use the following template often. When using a page template for my MAIN page, I access the error and message vars with:
<p tal:content="options/error">Error message</p> <p tal:content="options/message">Reg. Message</p>
How would I access them when I use a dtml-method for my MAIN page? <dtml-var error> and <dtml-var message> don't seem to work.
That _should_ work. In DTML, I think when you ask for something it does a options, REQUEST, context, acquisition context lookup all in one loop. In TAL you can't be lazy :( and you have to specify exactly where you expect it to come from. Bare in mind that keyword arguments only span across ONE template where as variables in REQUEST span across ALL templates. Doublecheck your template usage and/or send us your traceback.
Python Script - index_html:
# Import a standard function, and get the HTML request and response objects. from Products.PythonScripts.standard import html_quote request = container.REQUEST RESPONSE = request.RESPONSE
error='' message=''
if not request.has_key('next_state'): return container['MAIN'](context, request, error=error, message=message)
elif request.get('next_state') == 'Do Something': try: doSomething() message = message + 'We did something' except: error = error + 'Error in doSomething()'
elif request.get('next_state') == 'Do Something Else': try: doSomethingElse() message = message + 'We did something else' except: error = error + 'Error in doSomethingElse()'
return container['MAIN'](context, request, error=error, message=message)
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
I don't get a traceback, i just get error and message back as empty strings; their initiallized value. very strange. Peter Bengtsson wrote:
On 7/19/05, Erik Myllymaki <erik.myllymaki@aviawest.com> wrote:
I use the following template often. When using a page template for my MAIN page, I access the error and message vars with:
<p tal:content="options/error">Error message</p> <p tal:content="options/message">Reg. Message</p>
How would I access them when I use a dtml-method for my MAIN page? <dtml-var error> and <dtml-var message> don't seem to work.
That _should_ work. In DTML, I think when you ask for something it does a options, REQUEST, context, acquisition context lookup all in one loop. In TAL you can't be lazy :( and you have to specify exactly where you expect it to come from.
Bare in mind that keyword arguments only span across ONE template where as variables in REQUEST span across ALL templates.
Doublecheck your template usage and/or send us your traceback.
Python Script - index_html:
# Import a standard function, and get the HTML request and response objects. from Products.PythonScripts.standard import html_quote request = container.REQUEST RESPONSE = request.RESPONSE
error='' message=''
if not request.has_key('next_state'): return container['MAIN'](context, request, error=error, message=message)
elif request.get('next_state') == 'Do Something': try: doSomething() message = message + 'We did something' except: error = error + 'Error in doSomething()'
elif request.get('next_state') == 'Do Something Else': try: doSomethingElse() message = message + 'We did something else' except: error = error + 'Error in doSomethingElse()'
return container['MAIN'](context, request, error=error, message=message)
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
On 7/19/05, Erik Myllymaki <erik.myllymaki@aviawest.com> wrote:
I don't get a traceback, i just get error and message back as empty strings; their initiallized value.
So you're not getting an error. What is the initialized value? Is 'error' and 'message' set in REQUEST? (that you can find out from doing <dtml-var REQUEST>)
Peter Bengtsson wrote:
On 7/19/05, Erik Myllymaki <erik.myllymaki@aviawest.com> wrote:
I use the following template often. When using a page template for my MAIN page, I access the error and message vars with:
<p tal:content="options/error">Error message</p> <p tal:content="options/message">Reg. Message</p>
How would I access them when I use a dtml-method for my MAIN page? <dtml-var error> and <dtml-var message> don't seem to work.
That _should_ work. In DTML, I think when you ask for something it does a options, REQUEST, context, acquisition context lookup all in one loop. In TAL you can't be lazy :( and you have to specify exactly where you expect it to come from.
Bare in mind that keyword arguments only span across ONE template where as variables in REQUEST span across ALL templates.
Doublecheck your template usage and/or send us your traceback.
Python Script - index_html:
# Import a standard function, and get the HTML request and response objects. from Products.PythonScripts.standard import html_quote request = container.REQUEST RESPONSE = request.RESPONSE
error='' message=''
if not request.has_key('next_state'): return container['MAIN'](context, request, error=error, message=message)
elif request.get('next_state') == 'Do Something': try: doSomething() message = message + 'We did something' except: error = error + 'Error in doSomething()'
elif request.get('next_state') == 'Do Something Else': try: doSomethingElse() message = message + 'We did something else' except: error = error + 'Error in doSomethingElse()'
return container['MAIN'](context, request, error=error, message=message)
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
Hi Erik,
I don't get a traceback, i just get error and message back as empty strings; their initiallized value.
very strange. Looking at your python script I saw that initially you set error and message to the empty string ''. I guess the script is not detecting a 'next_state' keyword in the request. So, it is excecuting the first if of your code:
if not request.has_key('next_state'): return container['MAIN'](context, request, error=error, message=message) Where are you initializing 'next_state'? Try printing the request object to see if it really exists or perhaps you are doing some typo. Regards, Josef
next_state does get initialized - it is the name of the submit buttons on my various forms. Josef Meile wrote:
Hi Erik,
I don't get a traceback, i just get error and message back as empty strings; their initiallized value.
very strange.
Looking at your python script I saw that initially you set error and message to the empty string ''. I guess the script is not detecting a 'next_state' keyword in the request. So, it is excecuting the first if of your code:
if not request.has_key('next_state'): return container['MAIN'](context, request, error=error, message=message)
Where are you initializing 'next_state'? Try printing the request object to see if it really exists or perhaps you are doing some typo.
Regards, Josef
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Hi Erik,
next_state does get initialized - it is the name of the submit buttons on my various forms. So, then it should be in the request object. Just to test it, put the following at the begining of your python script (You don't have to delelete anything):
return request Then submit the form that calls the script and check if next_state is really a key in the request object. On the contrary, it could be an error in the html code where create the form. Regards, Josef
I am using DTML only because I am using the excellent Calendar tag product. sometimes, the links on the calendar tag get affected by from variables so as a hack i re-write the QUERY_STRING using: request.RESPONSE.redirect(request['URL'] + '?mode-calendar=' + request['mode-calendar'] + '&date-calendar=' + request['date-calendar'] + '&location=' + request['location']) instead of: return container['MAIN'](context, request, error=error, message=message) I originally left that detail out to avoid unnecessary confusion, but I think it might be the cause...ideas? Peter Bengtsson wrote:
On 7/19/05, Erik Myllymaki <erik.myllymaki@aviawest.com> wrote:
I use the following template often. When using a page template for my MAIN page, I access the error and message vars with:
<p tal:content="options/error">Error message</p> <p tal:content="options/message">Reg. Message</p>
How would I access them when I use a dtml-method for my MAIN page? <dtml-var error> and <dtml-var message> don't seem to work.
That _should_ work. In DTML, I think when you ask for something it does a options, REQUEST, context, acquisition context lookup all in one loop. In TAL you can't be lazy :( and you have to specify exactly where you expect it to come from.
Bare in mind that keyword arguments only span across ONE template where as variables in REQUEST span across ALL templates.
Doublecheck your template usage and/or send us your traceback.
Python Script - index_html:
# Import a standard function, and get the HTML request and response objects. from Products.PythonScripts.standard import html_quote request = container.REQUEST RESPONSE = request.RESPONSE
error='' message=''
if not request.has_key('next_state'): return container['MAIN'](context, request, error=error, message=message)
elif request.get('next_state') == 'Do Something': try: doSomething() message = message + 'We did something' except: error = error + 'Error in doSomething()'
elif request.get('next_state') == 'Do Something Else': try: doSomethingElse() message = message + 'We did something else' except: error = error + 'Error in doSomethingElse()'
return container['MAIN'](context, request, error=error, message=message)
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
How you get to the page is irrelevant. I don't care if you redirect there or type in the url or click a link. On 7/19/05, Erik Myllymaki <erik.myllymaki@aviawest.com> wrote:
I am using DTML only because I am using the excellent Calendar tag product.
sometimes, the links on the calendar tag get affected by from variables so as a hack i re-write the QUERY_STRING using:
request.RESPONSE.redirect(request['URL'] + '?mode-calendar=' + request['mode-calendar'] + '&date-calendar=' + request['date-calendar'] + '&location=' + request['location'])
instead of:
return container['MAIN'](context, request, error=error, message=message)
I originally left that detail out to avoid unnecessary confusion, but I think it might be the cause...ideas?
Peter Bengtsson wrote:
On 7/19/05, Erik Myllymaki <erik.myllymaki@aviawest.com> wrote:
I use the following template often. When using a page template for my MAIN page, I access the error and message vars with:
<p tal:content="options/error">Error message</p> <p tal:content="options/message">Reg. Message</p>
How would I access them when I use a dtml-method for my MAIN page? <dtml-var error> and <dtml-var message> don't seem to work.
That _should_ work. In DTML, I think when you ask for something it does a options, REQUEST, context, acquisition context lookup all in one loop. In TAL you can't be lazy :( and you have to specify exactly where you expect it to come from.
Bare in mind that keyword arguments only span across ONE template where as variables in REQUEST span across ALL templates.
Doublecheck your template usage and/or send us your traceback.
Python Script - index_html:
# Import a standard function, and get the HTML request and response objects. from Products.PythonScripts.standard import html_quote request = container.REQUEST RESPONSE = request.RESPONSE
error='' message=''
if not request.has_key('next_state'): return container['MAIN'](context, request, error=error, message=message)
elif request.get('next_state') == 'Do Something': try: doSomething() message = message + 'We did something' except: error = error + 'Error in doSomething()'
elif request.get('next_state') == 'Do Something Else': try: doSomethingElse() message = message + 'We did something else' except: error = error + 'Error in doSomethingElse()'
return container['MAIN'](context, request, error=error, message=message)
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
participants (3)
-
Erik Myllymaki -
Josef Meile -
Peter Bengtsson