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

Mike Revoir mrevoir at gmail.com
Thu Aug 24 16:56:44 CEST 2006


Rob,

Here's the code I use in my workflow scripts to get the member. You
shouldn't need to use context.

    portal_url  = getToolByName(self, 'portal_url')
    portal      = portal_url.getPortalObject()
    portal_membership = getToolByName(self, 'portal_membership')

    member = portal_membership.getMemberById(obj.Creator())

Mike

On 8/23/06, Rob Lineberger <rob_lineberger at med.unc.edu> wrote:
>
> 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
> (
> http://plone.org/documentation/how-to/send-mail-on-workflow-transition/#1124212172
> )
> 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):
>     obj=state_change.object
>     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,
>                'id':member.getId(),
>                'fullname':member.getProperty('fullname', 'Fullname
> missing'),
>                'email':member.getProperty('email', None)}
>
>     actorid = wf_tool.getInfoFor(obj, 'actor')
>     actor = context.portal_membership.getMemberById(actorid)
>     reviewer = {'member':actor,
>                 'id':actor.getId(),
>                 'fullname':actor.getProperty('fullname', 'Fullname
> missing'),
>                 '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)
>
>
>
> _______________________________________________
> triangle-zpug mailing list
> triangle-zpug at starship.python.net
> http://starship.python.net/mailman/listinfo/triangle-zpug
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://starship.python.net/pipermail/triangle-zpug/attachments/20060824/0b09ebd5/attachment.html


More information about the triangle-zpug mailing list