Hash: SHA1


This issue is more on-topic for the '[EMAIL PROTECTED]' 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, '[EMAIL PROTECTED]', '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 Seaver          +1 540-429-0999          [EMAIL PROTECTED]
Palladion Software   "Excellence by Design"    http://palladion.com
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


Zope maillist  -  Zope@zope.org
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to