[ZCM] [ZC] 809/ 5 Comment "Proposed new API method: 'absolute_path'"

Collector: Zope Bugs, Features, and Patches ... zope-coders-admin at zope.org
Fri Nov 28 05:16:58 EST 2003


Issue #809 Update (Comment) "Proposed new API method: 'absolute_path'"
 Status Accepted, Zope/feature+solution medium
To followup, visit:
  http://zope.org/Collectors/Zope/809

==============================================================
= Comment - Entry #5 by yuppie on Nov 28, 2003 5:16 am

Aargh! You changed the API. In an "inside-out hosting" scenario as described in entry #1 CMF 1.4 doesn't work with Zope 2.7 or HEAD. At least the icons are broken, but I'm afraid that's just the most obvious problem.

The ObjectManagerItem help file says: "If the relative argument is provided with a true value, then the URL returned is relative to the site object." That's the way it is used in CMF (and I guess in many other products too). Your 'fix' changed it to relative to the server root.
________________________________________
= Accept - Entry #4 by evan on Jul 8, 2003 1:05 pm

 Status: Rejected => Accepted

 Supporters added: evan

Fixed in CVS trunk, should be in next 2.7 release.
________________________________________
= Reject - Entry #3 by ajung on Mar 4, 2003 11:20 am

 Status: Pending => Rejected

Use '/'.join(obj.getPhysicalPath()) instead.

-aj
________________________________________
= Comment - Entry #2 by camil7 on Feb 17, 2003 7:07 am

Maybe "getPhysicalPath()" does what You want?

(You may want to join the return value via '/'.join()
as this method returns a tuple of ids, not an URL.)
________________________________________
= Request - Entry #1 by shh on Feb 15, 2003 7:50 am

Problem:

It is often desirable to get at the absolute path of a Zope object, i.e. the absolute url with the protocol and server parts removed. However, there is no easy way. 

In particular, absolute_url(1) does *not* return a path from the server root, but a path relative to a virtual root! Worse yet, the common idiom '/'+absolute_url(1) to get the absolute path even works in most cases, but breaks once certain types of virtual hosting come into play.

Specifically, it is inside-out hosting that breaks. When you are serving a Zope site from a virtual host's subdirectory and use '_vh_xyz' in your VHM rewrite rules to reinsert 'xyz' into the path, you will find that a path returned by absolute_url(1) fails to include 'xyz'.

Proposed Solution:

Add a new API method to Traversable named 'absolute_path' to safely cover this common requirement. An implementation of 'absolute_path' could look like:

  def absolute_path(self):
        """
        Returns the absolute path of an object, i.e.
        the absolute url with the protocol and server 
        parts removed but including the leading '/'.
        """
        req = self.REQUEST
        url = self.absolute_url()
        url = url[len(req.SERVER_URL):]
        return url

Related:

You might want to consider this together with 
http://collector.zope.org/Zope/797

==============================================================




More information about the Zope-Collector-Monitor mailing list