Getting the correct domain at add time.
I have a Zope instance with several domain names pointing at it using Virtual Host Monster. I don't know if this is the only way to have multiple domains on a single Zope instance, but I doubt it, and I would prefer for it not to matter how it's done. BUT, I want certain trees in the object FS to remember what their "preferred" domain is. In order to make this as transparent as possible, I want to find out what the domain name was at the time that an object is added. However, absolute_url() seems not to work as I would expect it to (possibly because I'm calling it before the ZODB transaction is closed?) in my product code: def manage_addTopic(self, id, title='', REQUEST=None): """ Add a NaryaTopic. """ ob=Topic(id, title=title) ob.id=str(id) ob.title=title self._setObject(id, ob) ob=self._getOb(id) ob.topic_domain = urlparse.urlparse(ob.absolute_url())[1] if REQUEST is not None: return self.manage_main(self, REQUEST, update_menu=1) I think the problem may only occur when this manage_addTopic is called from another manage_addFoo function, but I'm not positive about that. When I tried this, I got a complaint about not having a defined 'SERVER_URL' from Transaction.py and then, when I changed ob.absolute_url() to self.absolute_url(), I got this complaint: Traceback (innermost last): File /usr/local/narya/z2.5.1/lib/python/ZPublisher/Publish.py, line 150, in publish_module File /usr/local/narya/z2.5.1/lib/python/ZPublisher/Publish.py, line 114, in publish File /usr/local/narya/z2.5.1/lib/python/Zope/__init__.py, line 159, in zpublisher_exception_hook File /usr/local/narya/z2.5.1/lib/python/ZPublisher/Publish.py, line 98, in publish File /usr/local/narya/z2.5.1/lib/python/ZPublisher/mapply.py, line 88, in mapply (Object: manage_addNarya) File /usr/local/narya/z2.5.1/lib/python/ZPublisher/Publish.py, line 39, in call_object (Object: manage_addNarya) File /usr/local/narya/zope/Products/Narya/Narya.py, line 938, in manage_addNarya File /usr/local/narya/zope/Products/Narya/Narya.py, line 475, in __init__ (Object: Narya) File /usr/local/narya/zope/Products/Narya/Topic.py, line 686, in manage_addTopic (Object: Narya) File /usr/local/narya/z2.5.1/lib/python/OFS/Traversable.py, line 36, in absolute_url (Object: Narya) AttributeError: get My question is, if this isn't the smart way to get the domain at add time, what is a better way? Am I missing something fundamental here? It seems like a lot of Zope programming makes sense when there's a single domain to server relationship, but multiple virtual domains get very confusing. Thanks for any suggestions, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com
Terry Hancock wrote at 2003-11-25 09:59 -0600:
... However, absolute_url() seems not to work as I would expect it to ... in my product code:
def manage_addTopic(self, id, title='', REQUEST=None): ... self._setObject(id, ob) ob=self._getOb(id) ob.topic_domain = urlparse.urlparse(ob.absolute_url())[1] ...
I think the problem may only occur when this manage_addTopic is called from another manage_addFoo function, but I'm not positive about that.
Almost surely, you are right with this. See below.
File /usr/local/narya/z2.5.1/lib/python/OFS/Traversable.py, line 36, in absolute_url (Object: Narya) AttributeError: get
This means, "absolute_url" is unable to acquire "REQUEST". This happens when the "acquisition chain" is not complete. Note, that newly constructed objects are not yet acquisition wrapped. The get (usually) wrapped by: container._setObject(id, newObject) newObject = container._getOb(id) # now wrapped -- Dieter
On Tuesday 25 November 2003 02:57 pm, Dieter Maurer wrote:
This means, "absolute_url" is unable to acquire "REQUEST". This happens when the "acquisition chain" is not complete. [...] Note, that newly constructed objects are not yet acquisition wrapped.
Right. Because they wouldn't know where they were supposed to acquire from, until they've been put into the object tree.
container._setObject(id, newObject) newObject = container._getOb(id) # now wrapped
Thanks for clarifying what this code does, I had just copied it from other manage_add functions, without really understanding why it was necessary. Makes sense to me now. I figured out my problem -- the call actually wasn't from the manage_add function for the container, it was in the __init__() method of the container, which means it was happening before the acquisition wrapper was added to it. Thanks! Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com
participants (2)
-
Dieter Maurer -
Terry Hancock