AbsoluteURL inconsistent between adapter and view

Bug #747086 reported by Wolfgang Schnerring
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
zope.traversing
Invalid
Undecided
Unassigned

Bug Description

AbsoluteURL can be accessed in two ways, as an adapter from (context, request) to IAbsoluteURL, and as a view, i.e. an adapter from (context, request) to Interface, with the name 'absolute_url'.

zope.traversing's default implementation implements this duality by registering the same class twice -- and not by delegating one access path to the other. This means that if you want to override AbsoluteURL, you have to override both access paths, too, which feels conceptually broken to me, and creates superfluous busywork.

Revision history for this message
Brian Sutherland (jinty) wrote :

+1

It would save many many lines of zcml.

I'd prefer to make the view delegate to the IAbsoluteURL adapter. In my projects I always override the default view with this class to do it:

class AbsoluteURLView(object):
    """An absoluteURL view that delegates to the IAbsoluteURL multi-adapter"""

    def __init__(self, context, request):
        self.context = context
        self.request = request

    @property
    def _url(self):
        return getMultiAdapter((self.context, self.request), IAbsoluteURL)

    def __unicode__(self):
        return self._url.__unicode__()

    def __str__(self):
        return self._url.__str__()

    def __call__(self):
        return self._url()

Revision history for this message
Colin Watson (cjwatson) wrote :

The zope.traversing project on Launchpad has been archived at the request of the Zope developers (see https://answers.launchpad.net/launchpad/+question/683589 and https://answers.launchpad.net/launchpad/+question/685285). If this bug is still relevant, please refile it at https://github.com/zopefoundation/zope.traversing.

Changed in zope.traversing:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.