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 from ZPublisher.BaseRequest import DefaultPublishTraverse from zope.publisher.interfaces import NotFound from interfaces import IBrowser class Browser(Persistent, SimpleItem): """ browse resources """ meta_type = "Browser" implements(IBrowser) id = 'browse' security = ClassSecurityInfo() def __init__(self): SimpleItem.__init__(self) def locate(self, REQUEST, name): """ compose waramu query """ stack = REQUEST.get('TraversalRequestNameStack') v = self.restrictedTraverse('browse.html') if stack: # there is something field = stack.pop() v.setField(field) if stack: #there is a field value! val = stack.pop() if val == '_null_': val = '' v.setValue(val) while stack: p = stack.pop() if p == 'start': # next is a number try: pp = stack.pop() v.start = int(pp) except IndexError: pass except ValueError: # redirect to some nasty error page pass elif p == '_sort': # sort criterion # next is a field to sort by if len(stack) > 0: v.setSortBy(stack.pop()) # next can be a sort order if len(stack) > 0 and (stack[-1] == 'ascending' or stack[-1] == 'descending'): v.setSortOrder(stack.pop()) else: p2 = stack.pop() v.addCrit(p, p2) return v InitializeClass(Browser) class ContentTraverser(object): """ browser traverser """ adapts(IBrowser, 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) except (NotFound, AttributeError), e: obj = self.context.locate(request, name) return obj