[Zope] Getting the correct domain at add time.

Terry Hancock hancock at anansispaceworks.com
Tue Nov 25 10:59:54 EST 2003


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



More information about the Zope mailing list