How can I import this module in python script ?????
Hi, I am playing around trying to make something happen on a workflow state change. Beacause I cannot import the module I need in the python script I am getting an error: global name 'getMemberById' is not defined how can I import this module or better still code this so I am not importing anything at all (i imagine the restrictions on importing modules was done for a reason). #import the module we need from Products.CMFCore.utils import getToolByName # Get the content object we're publishing review_state.object # How can I import this module????? #from Products.CMFDefault.MembershipTool import MembershipTool mt = getToolByName(context, 'portal_membership') listed_ids = mt.getRoster() contentObject = review_state # Start with an empty list, ready to be filled with the addressed # of people we're dispatching to mailList=[] mailhost = context.MailHost mailhost = getattr(context, 'MailHost', None) # Iterate through all the site's users # context.portal_membership.listMembers(): for id in listed_ids: member = getMemberById(id) email = member.getProperty('email') # add them to the list of people we're emailing mailList.append(email) mMsg = 'Crop notification sent' mTo = email # and send it mailhost.send(mMsg, mTo, 'someone@somewhere.com', 'New Crops available') # The change in indentation signals the end of the loop, so we've # now sent all the emails. Let's now send a confirmation that we've done it. # We'll be building the email as a string again, but we have to convert our # list data elements into a string before we can append the information recipients = string.join(mailList) mMsg = 'These people were sent e-mails' #mMsg += contentObject.absolute_url() + mMsg += recipients mailhost.send(mMsg, 'someone@somewhere.com', 'someone@somewhere.com', 'Lizard Leaves Announcement email confirmation') thx []'s Ian F U cn rd dis U mst uz Linux.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 getMemberById is a method on the portal_membership tool. You grab the tool and call the method: mt = getToolByName(context, 'portal_membership') member = mt.getMemberById(id) I highly suggest you get more familiar with Python in general. Importing a module to somehow make a method on an instance available makes no sense whatsoever. jens On 26 Feb 2007, at 15:13, ian@inpa.gov.br wrote:
Hi, I am playing around trying to make something happen on a workflow state change. Beacause I cannot import the module I need in the python script I am getting an error: global name 'getMemberById' is not defined how can I import this module or better still code this so I am not importing anything at all (i imagine the restrictions on importing modules was done for a reason).
#import the module we need from Products.CMFCore.utils import getToolByName
# Get the content object we're publishing review_state.object
# How can I import this module????? #from Products.CMFDefault.MembershipTool import MembershipTool
mt = getToolByName(context, 'portal_membership')
listed_ids = mt.getRoster()
contentObject = review_state
# Start with an empty list, ready to be filled with the addressed # of people we're dispatching to mailList=[]
mailhost = context.MailHost mailhost = getattr(context, 'MailHost', None)
# Iterate through all the site's users # context.portal_membership.listMembers(): for id in listed_ids: member = getMemberById(id) email = member.getProperty('email')
# add them to the list of people we're emailing mailList.append(email)
mMsg = 'Crop notification sent' mTo = email # and send it mailhost.send(mMsg, mTo, 'someone@somewhere.com', 'New Crops available')
# The change in indentation signals the end of the loop, so we've # now sent all the emails. Let's now send a confirmation that we've done it.
# We'll be building the email as a string again, but we have to convert our # list data elements into a string before we can append the information
recipients = string.join(mailList)
mMsg = 'These people were sent e-mails' #mMsg += contentObject.absolute_url() + mMsg += recipients mailhost.send(mMsg, 'someone@somewhere.com', 'someone@somewhere.com', 'Lizard Leaves Announcement email confirmation')
thx []'s Ian
F U cn rd dis U mst uz Linux.
_______________________________________________ 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 )
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (Darwin) iD8DBQFF4vBARAx5nvEhZLIRAlqVAJ9uXfrE6ktRgS2rCOEqhqIPzvWQZACfYge6 ix/M5/TI5w1DyOXu+XTB604= =eV1e -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 ian@inpa.gov.br wrote: This issue is more on-topic for the 'zope-cmf@zope.org' list.
I am playing around trying to make something happen on a workflow state change. Beacause I cannot import the module I need in the python script I am getting an error: global name 'getMemberById' is not defined how can I import this module or better still code this so I am not importing anything at all (i imagine the restrictions on importing modules was done for a reason).
Yes, but that's a decoy here: you don't really need to import a module; you just need to get an *instance* which happens to have its class defined in that module. In fact, you already *have* got hold of that instance (see below). The reason imports are restricted in "untrusted" code is that the standard library includes modules whose APIs are dangerous (e.g., imaging 'shutils.rmtree'). So, in order to use a filesystem module in TTW code, you must first make a declaration in Zope filesystem code which enables it.
#import the module we need from Products.CMFCore.utils import getToolByName
# Get the content object we're publishing review_state.object
# How can I import this module????? #from Products.CMFDefault.MembershipTool import MembershipTool
mt = getToolByName(context, 'portal_membership')
listed_ids = mt.getRoster()
contentObject = review_state
# Start with an empty list, ready to be filled with the addressed # of people we're dispatching to mailList=[]
mailhost = context.MailHost mailhost = getattr(context, 'MailHost', None)
# Iterate through all the site's users # context.portal_membership.listMembers(): for id in listed_ids: member = getMemberById(id) member = mt.getMemberById(id) # use the tool
email = member.getProperty('email')
# add them to the list of people we're emailing mailList.append(email)
mMsg = 'Crop notification sent' mTo = email # and send it mailhost.send(mMsg, mTo, 'someone@somewhere.com', 'New Crops available')
# The change in indentation signals the end of the loop, so we've # now sent all the emails. Let's now send a confirmation that we've done it.
# We'll be building the email as a string again, but we have to convert our # list data elements into a string before we can append the information
recipients = string.join(mailList)
Tres. - -- =================================================================== Tres Seaver +1 540-429-0999 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFF4vGZ+gerLs4ltQ4RAk9TAKC65LdOamnCo9skSiBM+MZBpo7pZgCggCi5 hKOvEX/Q5QIBPeTXTlSVGuc= =d/V9 -----END PGP SIGNATURE-----
participants (3)
-
ian@inpa.gov.br -
Jens Vagelpohl -
Tres Seaver