Florian Lindner wrote:
Am Samstag, 2. April 2005 08:37 schrieb Stephan Richter:

On Saturday 02 April 2005 04:38, jÃrgen Kartnaller wrote:

Why in the world would you want to do that? This seems just awful. What
is your use case?

In my case I want to have the possibility to jump back to my base view (which is the default view of my site) from wherever I am within my site.

But, if there is an easier way to do this, please let me know.

Then write a wrapper view for all interfaces that internally looks up the next site and looks up the default view:

class SiteDefaultView(object):

 def __call__(self):
        site = getNextSiteSomehow()
        defaultViewName = getDefaultViewName(site, self.request, site)
        view = zapi.getMultiAdapter((site, request), Interface,
name=defaultViewName) return view()


Hello,
your solution:

class toSite(object):
    def __call__(self):
        from zope.app.zapi import *

ugh. Don't do "from xyz import *" imports. Here it's ok maybe because the scope of the import is limited to the __call_ method. But still, they're highly discouraged.


        site = getSite()
        defaultViewName = getDefaultViewName(site, self.request, site)
        view = getMultiAdapter((site, self.request), name=defaultViewName)
        return view()

get the same results as mine:

class toSite(object):
    def __call__(self):
        from zope.app.zapi import absoluteURL
        URL = absoluteURL(getSite(), self.request)
        return self.request.response.redirect(URL)


What are the differences? Which is better? Why?

I think yours is better since it does not involve a redirect. What do you think?

I think your solution is better, Florian. Stephan's solution, while correct, makes it look like a site can or maybe even should be accessed through http://mysite.com/someobject/@@getSite.html. That's of course not true, a site should always be reached at http://mysite.com/++etc++site, so IMO it's better to redirect.


(One case where the redirect is definitely better is bookmarks. Imagine somebody gets the site through Stephan's solution and bookmarks that page. Then, later, 'someobject' is renamed to 'anobject'; now the bookmark won't work anymore, even though the site is still there).

Philipp

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

Reply via email to