from OFS.SimpleItem import SimpleItem from zope.interface import implements from Globals import Persistent, InitializeClass from AccessControl import ClassSecurityInfo from zope.publisher.http import IHTTPRequest from zope.publisher.interfaces import IPublishTraverse from zope.component import adapts, getUtility from ZPublisher.BaseRequest import DefaultPublishTraverse from zope.publisher.interfaces import NotFound from interfaces import IContent, IBrowser, iMDPortal class Content(Persistent, SimpleItem): """ content display """ implements(IContent) meta_type = "Content" id = 'content' security = ClassSecurityInfo() def __init__(self): SimpleItem.__init__(self) InitializeClass(Content) class ContentTraverser(object): """ content traverser """ adapts(IContent, IHTTPRequest) implements(IPublishTraverse) def __init__(self, context, request): self.context = context self.default = DefaultPublishTraverse(context,request) def publishTraverse(self, request, name): try: obj = self.default.publishTraverse(request, name) if name in ['view', 'edit', 'info']: stack = request.get('TraversalRequestNameStack') rid = stack.pop() obj.setRID(rid) if request.get('HTTP_REFERER'): # have referer pu = self.context.getPortalURL() pu += '/browse/by/' if request.get('HTTP_REFERER').startswith(pu): # it is a browse! critsurl = request.get('HTTP_REFERER').replace(pu, '') crits = critsurl.split('/') crits.reverse() #print "crits:", crits mdp = getUtility(iMDPortal, context=self.context) bu = getUtility(IBrowser, context=self.context).__of__(mdp) #print bu #fakerequest = {'TraversalRequestNameStack': crits} #bu.locate(fakerequest, 'by') except (NotFound, AttributeError), e: obj = self.context.locate(request, name) return obj