Re: [Zope] Zoo guestbook example.
Ignacio Valdes writes:
Error Type: AttributeError Error Value: 'string' object has no attribute 'objectIds' (Info: (('Anonymous', 'test'), {}, None)) File <string>, line 2, in addEntry AttributeError: (see above)
With this code, with guest_name and self as parameters.
id='entry_%d' % len(self.objectIds()) self.manage_addDTMLDocument(id, title="", file=comments) doc=getattr(self, id) doc.manage_addProperty('guest_name', guest_name, 'string')
Apparently, your "self" is a string while you expect it to be an object. Dieter
Dieter Maurer wrote:
Ignacio Valdes writes:
Error Type: AttributeError Error Value: 'string' object has no attribute 'objectIds' (Info: (('Anonymous', 'test'), {}, None)) File <string>, line 2, in addEntry AttributeError: (see above)
With this code, with guest_name and self as parameters.
id='entry_%d' % len(self.objectIds()) self.manage_addDTMLDocument(id, title="", file=comments) doc=getattr(self, id) doc.manage_addProperty('guest_name', guest_name, 'string')
Apparently, your "self" is a string while you expect it to be an object.
Dieter
Okay, how to fix it? I've tried putting either 'self' or 'comments' in the parameter line as well as various combinations in the code, which results in either a key error, or the same problem. Wish I could upgrade to 2.2.4 from 2.2.2, but I can't yet. -- IV
Dieter Maurer wrote:
Ignacio Valdes writes:
Dieter Maurer wrote:
Apparently, your "self" is a string while you expect it to be an object. Okay, how to fix it? Where does your "self" come from?
Dieter
I'm from Georgia originally, but I grew up in Texas :-) Markus Kemmerling suggested replacing 'context' in the code below with 'self' using this code: id='entry_%d' % len(self.objectIds()) self.manage_addDTMLDocument(id, title="", file=comments) doc=getattr(self, id) doc.manage_addProperty('guest_name', guest_name, 'string') and says this works with Zope 2.2.4, but I can only use 2.2.2 for the time being. The original code from the Zope book example at http://www.zope.org/Members/michel/ZB/SimpleExamples.html is: """ Create a guest book entry. """ # create a unique document id id='entry_%d' % len(context.objectIds()) # create the document context.manage_addProduct['OFSP'].manage_addDTMLDocument(id, title="", file=comments) # add a guest_name string property doc=getattr(context, id) doc.manage_addProperty('guest_name', guest_name, 'string') This is the basic functionality I would need for a medical software rating site. Unfortunately, I can only use Zope 2.2.2 as it will be running on a production site that I don't control. Thanks, -- IV
Ignacio Valdes writes:
Dieter Maurer wrote:
Where does your "self" come from? I'm from Georgia originally, but I grew up in Texas :-) I meant the question seriously.
Let's go a step back. The Zope book is based on Zope 2.3, neither on 2.2.2 nor 2.2.4. "context" is a new concept from PythonScripts. As of Zope 2.3, they are "in the core". I am not sure, whether you can use PythonScript with Zope 2.2.x. There may be problems. I would not expect big differences between Zope 2.2.2 and 2.2.4. If you do not use PythonScripts, you would need an ExternalMethod. An ExternalMethod will only get automatically a reference to the object for which is is called, if the name is "self" and it is the first parameter. Furthermore, if you call such a method, then the self is passed automatically only, if the call is precisely with one parameter less than that required by the method. In all other cases, you must pass the object explicitly. Your problem description indicates that you have called the method with enough parameters that the auto-passing of "self" did not happen. Instead "self" appears to have got a string as value. If this description really matches your case, then call the method with '<dtml-XXXX "method(this(),further parameters)">'. Dieter
Dieter Maurer wrote:
Your problem description indicates that you have called the method with enough parameters that the auto-passing of "self" did not happen. Instead "self" appears to have got a string as value.
If this description really matches your case, then call the method with '<dtml-XXXX "method(this(),further parameters)">'.
Dieter
addEntry is a Python method, I don't think DTML is allowed judging by it not liking <dtml-comment> as a test and certainly not liking my try below: If it did take DTML, would one transform this: comments.manage_addDTMLDocument(id, title="", file=comments) To something like this? <dtml-call "manage_addDTMLDocument(comments(),id, title="", file=comments)"> -- IV
participants (2)
-
Dieter Maurer -
Ignacio Valdes