John, your error message is doing all the suggesting as to what is wrong. Specifically, it says that it can't import GLOBALS from config (meaning config.py, of course). So... look again at your import statement (to learn about this) and what is it trying to import? Both GLOBALS and PROJECTNAME. When you look in your config.py file (according to what I see in the Zopemag article), it contains a line that says what PROJECTNAME should be, but nothing about GLOBALS. Looks like you have two choices: (1) don't import GLOBALS, or (2) define GLOBALS in your config.py file. (1) Try this: Change the line so that it only imports PROJECTNAME, and not GLOBALS. *or* (2) Try this: add the following line to your config.py: GLOBALS = globals() Why this line? Someone on the list earlier suggested to you that there was a mistake in the Zopemag Archetypes article, and several have made clear the suggestion that you do your own basic python homework. In this case, such homework would mean (1) knowing what python's import statement does, and (2) looking at some other Archetypes code, to see what GLOBALS looks like and how it is used in other samples (like ArchExample distributed with Archetypes, where I found this GLOBALS line, or ArcheRecipes and many more in the Collective). This line (#2 above) is what I found. I haven't myself tried this line to see if it fixes the example in the article. But you can't import GLOBALS if GLOBALS isn't defined there. Even if this does work, learn what GLOBALS might be trying to do for you (see how it is called, for example, and see how it is called in other code samples) so that this code isn't just *magic* for you. And finally, when you get the code to work properly and find what the errors in the article truly be, and what it should say, document it for others. =Paul At 10:50 AM 3/15/2004 +0000, John Poltorak wrote:
I have been following a worked example which shows how to add an External Method - something I have never done previously and it isn't working out as described in the article. Could someone suggest what is wrong?
Here is the actual article:-
http://www.zopemag.com/Issue006/Section_Articles/article_IntroToArchteypes.h...
I followed it religiously as far as this:-
Now, give it a try:
* Restart Zope * Make sure the product got imported just fine * Create a Plone Site * Create an External Method:
id: install_article module: MyArticle.Install function: install
* Run the External Method * Check that it worked by looking inside portal_types to see if it contains a type named "Article".
Instead of it working when I run it, it fails with:-
Traceback (innermost last):
* Module ZPublisher.Publish, line 150, in publish_module * Module Products.PlacelessTranslationService.PatchStringIO, line 45, in new_publish * Module ZPublisher.Publish, line 114, in publish * Module Zope.App.startup, line 202, in zpublisher_exception_hook * Module ZPublisher.Publish, line 98, in publish * Module ZPublisher.mapply, line 88, in mapply * Module ZPublisher.Publish, line 39, in call_object * Module Products.ExternalMethod.ExternalMethod, line 59, in manage_addExternalMethod * Module Products.ExternalMethod.ExternalMethod, line 110, in __init__ * Module Products.ExternalMethod.ExternalMethod, line 133, in manage_edit * Module Products.ExternalMethod.ExternalMethod, line 140, in getFunction * Module App.Extensions, line 145, in getObject __traceback_info__: ('C:/USR/local/zope/lib/python/Products/MyArticle/Extensions/Install.py', 'MyArticle.Install') * Module C:/USR/local/zope/lib/python/Products/MyArticle/Extensions/Install.py, line 1, in ?
ImportError: cannot import name GLOBALS (Also, an error occurred while attempting to render the standard error message.)
This is what Install.py contains:-
from Products.MyArticle.config import PROJECTNAME, GLOBALS from Products.Archetypes.public import listTypes from Products.Archetypes.Extensions.utils import installTypes from StringIO import StringIO
def install(self): out = StringIO()
installTypes(self, out, listTypes(PROJECTNAME), PROJECTNAME)
print >> out, "Successfully installed %s." % PROJECTNAME return out.getvalue()
I have no idea what GLOBALS pertains to and whether it is some sort of keyword in Python and it may well be due to an incorrect install of Python, but as I see it, I have followed the instructions in the article but it hasn't worked. Can anyone suggest what the cause might be and what I need to change to fix it?
-- John