[triangle-zpug] Global name 'context' is not defined error

Rob Lineberger rob_lineberger at med.unc.edu
Wed Aug 23 19:08:01 CEST 2006

Running into a wall here and hope someone can point me in the right 
direction.  I've programatically added a custom workflow called 
track_task to a product in Plone. Everything works fine; I tested the 
product, carrying an instance of "Task" through its lifecycle.

The problem comes when I try to add an action to one of the 
transitions.  When the Task is assigned via the 'assign' transition, I 
want it to send an email to the personResponsible. When I do that I get 
an error "global name 'context' is not defined."

 I followed both the tutorial on plone.org 
and the one in the Definitive guide to Plone. 

This error is causing me more trouble than usual because I don't know 
how to troubleshoot if there is no context.  I though context was always 
there no matter what?

Anyway, here is the offending code:

# File: LabProject.py
# Copyright (c) 2006 by Rob Lineberger

__author__ = """Rob Lineberger"""
__docformat__ = 'plaintext'

# Workflow Scripts for: track_task

def new_task(self, state_change, **kw): 
    creator = obj.Creator()
    history = state_change.getHistory()
    wf_tool = context.track_task

    mMsg = """
    You have been assigned a new task.
    The url is: %s.
    The description is: %s.

    member = context.portal_membership.getMemberById(creator)
    creator = {'member':member,
               'fullname':member.getProperty('fullname', 'Fullname 
               'email':member.getProperty('email', None)}

    actorid = wf_tool.getInfoFor(obj, 'actor')
    actor = context.portal_membership.getMemberById(actorid)
    reviewer = {'member':actor,
                'fullname':actor.getProperty('fullname', 'Fullname 
                'email':actor.getProperty('email', None)}

    mTo = creator['email']
    mFrom = reviewer['email']
    mSubj = 'Your item has transitioned'
    obj_url = obj.absolute_url() #use portal_url + relative_url
    comments = wf_tool.getInfoFor(obj, 'comments')

    message = mMsg % (obj_url, comments)
    context.MailHost.send(message, mTo, mFrom, mSubj)

More information about the triangle-zpug mailing list