I am relatively new to Zope and Python and am trying to convert a Zope 'product' from version 2.1.4 (working okay) to 2.2.2 (the latest) and I'm having the following Zope Error when trying to publish the resource; Error Type: AttributeError Error Value: 'string' object has no attribute 'has_key' The code in question appears below (with non-important stuff taken out); Python code; def getContext(self): # return the list of parents up to the project level in reverse order . . . def getAbsoluteURL(self, REQUEST): """ Attempt to get the absolute URL of this object by building it manually""" print "Self : ", self.title print "Request : ", REQUEST . . . if REQUEST.has_key( 'URL1' ) : str = REQUEST['URL1'] . . . DTML Code; <dtml-in "getContext()"> <option value="<dtml-var expr="getAbsoluteURL(REQUEST)">/manage_container" <dtml-if expr="currId==getId()"> SELECTED </dtml-if> > . . . </option> </dtml-in> The function getContext does infact return a list of object instances (tested and okay) and also therefore the related REQUEST (I've assumed?). So that when we loop through the list (in the DTML), the 'context' of the 'current' object should change. Thus we can interrogate each instance and do whatever we want (certainly in previous versions of Zope). But what in fact I'm getting is the following (unexpected) debug information; Self : 'Object Name' Request : <Special Object Used to Force Acquisition> (and the Zope error as mentioned above) with the error line number pointing to the ' if REQUEST.has_key( 'URL1' ) :' statement. If I hack the code to avoid the above test (for the first instance only) the code works (?), in that the next item in the object list is processed correctly (only two objects in the list). So it appears that the REQUEST object (since it hasn't got a method 'has_key') is invalid for the parent object (which Zope thinks is a 'String' object rather than a REQUEST?) but okay for the other. I don't understand this behaviour, is this due to the changes in security implemented in the latest version or due to some other changes? Any help or advice would be appreciated. Regards Bernie Rossi.
Bernie Rossi wrote:
def getContext(self): # return the list of parents up to the project level in reverse order . . .
Okay fair enough...
def getAbsoluteURL(self, REQUEST): """ Attempt to get the absolute URL of this object by building it manually"""
Why bother? there's a builtin method to do this for you!
<dtml-in "getContext()"> <option value="<dtml-var expr="getAbsoluteURL(REQUEST)">/manage_container" <dtml-if expr="currId==getId()"> SELECTED </dtml-if> > . . . </option> </dtml-in>
Maybe try this instead (assuming getContext returns a list of actual objects): <dtml-in getContext> <option value="<dtml-var absolute_url>/manage_container" <dtml-if expr="currId==getId()"> SELECTED </dtml-if> > . . . </option> </dtml-in> I don't know where currId comes from so I'm not sure it does what it is supposed to do...
The function getContext does infact return a list of object instances (tested and okay) and also therefore the related REQUEST (I've assumed?).
Now why on earth would it do that? (It won't by the way, unless you code it like that, and even then it would work in the way you've assumed)
So that when we loop through the list (in the DTML), the 'context' of the 'current' object should change.
This is very confused...
Thus we can interrogate each instance and do whatever we want (certainly in previous versions of Zope).
Well yeah, the dtml-in means that stuff inside it gets executed for each object in the list. Hope this helps, Chris
participants (2)
-
Bernie Rossi -
Chris Withers