Marius Gedminas wrote:
> On Thu, Dec 29, 2005 at 11:22:28PM -0700, Jeff Shell wrote:
> 
>>Again, this is to have URLs like:
>>
>>myapp/@@tags/zope/viewlet
>>
>>And turn that into a catalog search for anyof {'zope', 'viewlet'}
>>
>>    def publishTraverse(self, request, name):
>>        namestack = request.getTraversalStack()
>>        if name not in namestack:
>>            namestack.append(name)
>>        namestack.reverse()
>>        tags = tuple(namestack)
>>        request.setTraversalStack([])
>>
>>        results = TaggedArticleFinder(self.__name__,self.__parent__,tags)
>>        results.prepareSearch(request)
>>        return results
>>
>>The 'TaggedArticleFinder' then provides an interface that a view can
>>be found for that displays the results. So I've got it all working
>>now...
> 
> 
> My coworker Albertas recently implemented something like this in
> SchoolTool (I've CCed him).  Unfortunately it turned out to have some
> unforeseen consequences, for example, request.URL does not contain the
> path elements you "eat" manually, breaking self-posting forms (those
> that use <form tal:attributes="action request/URL">) and our login
> mechanism.
> 
> 

How about this? It gives
zope.app.publication.publicationtraverse.PublicationTraverse.traverseName()
some extra work, but it doesn't mess with the request and leaves
request.URL reflecting the entire "path".

###
from zope.interface import implements
from zope.publisher.interfaces import IPublishTraverse
from zope.app.publisher.browser import BrowserView

class BrowserViewStopTraversal(BrowserView):
    implements(IPublishTraverse)
    def __init__(self, context, request):
        self.context = context
        self.request = request
        self.traverse_subpath = []

    def publishTraverse(self, request, name):
        self.traverse_subpath.append(name)
        return self

    def __call__(self):
        """Just for example"""
        return ("traverse_subpath = %s\nrequest.URL = %s" %
                (self.traverse_subpath, self.request.URL))

###
<configure
    xmlns="http://namespaces.zope.org/zope";
    xmlns:browser="http://namespaces.zope.org/browser";
    i18n_domain="travtest"
    >
  <browser:page
      for="*"
      name="stoptrav"
      class=".travtest.BrowserViewStopTraversal"
      permission="zope.Public"
      />
</configure>
###

http://localhost:8080/@@stoptrav/foo/bar/baz  =>
  traverse_subpath = [u'foo', u'bar', u'baz']
  request.URL = http://localhost:8080/@@stoptrav/foo/bar/baz

-- Wade Leftwich
Ithaca, NY



_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users

Reply via email to