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
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
On Mon, Mar 15, 2004 at 10:20:08AM -0500, Paul Howell wrote:
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).
Yes, I gather there is a problem, but the last place I would have expected it to find it would have been in the sample code provided. How are you expected to learn anything when the information you are presented with is incorrect?
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.
One wonders why it was included in the sample code...
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.
Looks like you have already found this documented. I know Google is wonderful, but how on earth did you find that article?
=Paul
-- John
At 03:53 PM 3/15/2004 +0000, John Poltorak wrote:
On Mon, Mar 15, 2004 at 10:20:08AM -0500, Paul Howell wrote:
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).
Yes, I gather there is a problem, but the last place I would have expected it to find it would have been in the sample code provided.
No, the sample code is what generated this error, so it should be the FIRST place to expect to find it. Even (likely) the ONLY place to find it.
How are you expected to learn anything when the information you are presented with is incorrect?
John, mistakes happen. Even when people get paid the big bucks to document things and to edit articles ;-)
<snip>
(1) Try this: Change the line so that it only imports PROJECTNAME, and not GLOBALS.
One wonders why it was included in the sample code...
In this case, GLOBALS is very commonly imported from config.py, especially in Archetypes code (you'll notice this when you read some more samples). In all likelihood, GLOBALS was required in an earlier draft of the code for the article (perhaps to setup a skins folder properly), and then the code was later simplified but the import call remained (unfortunately). Just a guess... many mistakes in documentation (and other publications) come about like that.
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.
Looks like you have already found this documented.
Nope, not in the sense of someone writing about the error, at least not at the time I wrote that message. But also Yes, it is very clearly documented by reading the source code... In the words of Obi Wan Pythobi, "Use the Source, Luke." In this case, do all the python tutorials you can too, so that you'll better follow (and thus appropriately appropriate) the code in other samples.
I know Google is wonderful, but how on earth did you find that article?
There is a fine art of Googling, of course, but there are also basic techniques to finding your answer. The most fundamental is to picture your answer, and search on the key words and phrases that would appear in your answer. The second most fundamental technique is to rephrase your question in a fashion that someone else might have posed it, and to use those keywords. In this case, I used "Technique #2" and searched Google on: Zopemag archetypes article problem The discussion from awkly.org was top of the list. =Paul
John Poltorak wrote:
On Mon, Mar 15, 2004 at 10:20:08AM -0500, Paul Howell wrote:
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).
Yes, I gather there is a problem, but the last place I would have expected it to find it would have been in the sample code provided.
How are you expected to learn anything when the information you are presented with is incorrect?
Indeed, I'd take it up with their editor. I'm suprised they don't have an errata submission and updating process... Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
participants (3)
-
Chris Withers -
John Poltorak -
Paul Howell