IPublishTraverse and subpath

This is my pattern for subpaths with browser views:

@implementer(IPublishTraverse)
class VersionedDocument(BrowserView):

    def __init__(self, context, request):
        super(VersionedDocument, self).__init__(context, request)
        self.subpath = []

    def publishTraverse(self, request, name):
        if not hasattr(self, 'subpath'):
            self.subpath = []
        self.subpath.append(name)
        return self

    def external(self):
        fn = u'/'.join(self.subpath)

In this case you can get hold of the subpath in the view external through the concatenation of the self.subpath list.

-aj

1 Like