[ZPT] Where is my context

Thomas Olsen tol@tanghus.dk
Wed, 20 Mar 2002 13:35:00 +0100


Hi 

I have a small filesystem based python script which I use to get some 
variables to use in a page template. The script collects the variable and 
returns a dictionary to by used in the page template.

A snippet of the the script:

## Script (Python) "getAgendaVars"
##parameters=
##title=get variables for the Agenda
##
vars = {}
if context.meta_type == 'Media Manager Live Event':
    # get title
    vars['title'] = 'Sub Event Title'

    # stuff removed for clarity

elif context.meta_type == 'Media Sub Event':
    # get title
    vars['title'] = context.title

    # stuff removed for clarity

else:
    raise "Wrong meta type %s" % context.meta_type


And a snippet from the page template:

<span tal:define="global vars here/getAgendaVars;" />
<input type="text" name="title" value="title"
        tal:attributes="value vars/title|nothing">


This works excellent for a while, then if I leave it for some time I get:

Error Type: TALESError
 Error Value: exceptions.RuntimeError on 
Products/MyMediaManager/zpt_skins/getAgendaVars.py has errors. in 
"standard:'here/getAgendaVars'", at line 5, column 1
 
And if I reload the page I get:

Error Type: TALESError
 Error Value: exceptions.NameError on global name 'context' is not defined in 
"standard:'here/getAgendaVars'", at line 5, column 1
 
I have rewritten the python script several times and I totally baffled about 
whats happening

-- 
Regards,
    Thomas Olsen

http://www.tarpit.dk