[Zope3-checkins] CVS: Zope3/src/zope/app/traversing/browser -
__init__.py:1.1 configure.zcml:1.1 interfaces.py:1.1
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sat Mar 13 22:44:10 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/traversing/browser
In directory cvs.zope.org:/tmp/cvs-serv24735/src/zope/app/traversing/browser
Added Files:
__init__.py configure.zcml interfaces.py
Log Message:
Moved absolute URL code to zope.app.traversing.browser.
=== Added File Zope3/src/zope/app/traversing/browser/__init__.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""Absolute URL View components
$Id: __init__.py,v 1.1 2004/03/14 03:44:08 srichter Exp $
"""
from zope.app import zapi
from zope.publisher.browser import BrowserView
from zope.proxy import sameProxiedObjects
from zope.app.i18n import ZopeMessageIDFactory as _
_insufficientContext = _("There isn't enough context to get URL information. "
"This is probably due to a bug in setting up location "
"information.")
class AbsoluteURL(BrowserView):
def __str__(self):
context = self.context
request = self.request
if sameProxiedObjects(context, request.getVirtualHostRoot()):
return request.getApplicationURL()
container = getattr(context, '__parent__', None)
if container is None:
raise TypeError, _insufficientContext
url = str(zapi.getView(container, 'absolute_url', request))
name = getattr(context, '__name__', None)
if name is None:
raise TypeError, _insufficientContext
if name:
url += '/'+name
return url
__call__ = __str__
def breadcrumbs(self):
context = self.context
request = self.request
# We do this here do maintain the rule that we must be wrapped
container = getattr(context, '__parent__', None)
if container is None:
raise TypeError, _insufficientContext
if sameProxiedObjects(context, request.getVirtualHostRoot()) or \
isinstance(context, Exception):
return ({'name':'', 'url': self.request.getApplicationURL()}, )
base = tuple(zapi.getView(container,
'absolute_url', request).breadcrumbs())
name = getattr(context, '__name__', None)
if name is None:
raise TypeError, _insufficientContext
if name:
base += ({'name': name,
'url': ("%s/%s" % (base[-1]['url'], name))
}, )
return base
class SiteAbsoluteURL(BrowserView):
def __str__(self):
context = self.context
request = self.request
if sameProxiedObjects(context, request.getVirtualHostRoot()):
return request.getApplicationURL()
url = request.getApplicationURL()
name = getattr(context, '__name__', None)
if name:
url += '/'+name
return url
__call__ = __str__
def breadcrumbs(self):
context = self.context
request = self.request
if sameProxiedObjects(context, request.getVirtualHostRoot()):
return ({'name':'', 'url': self.request.getApplicationURL()}, )
base = ({'name':'', 'url': self.request.getApplicationURL()}, )
name = getattr(context, '__name__', None)
if name:
base += ({'name': name,
'url': ("%s/%s" % (base[-1]['url'], name))
}, )
return base
=== Added File Zope3/src/zope/app/traversing/browser/configure.zcml ===
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">
<browser:page
name="_traverse"
for="zope.interface.Interface"
class="zope.app.publication.traversers.SimpleComponentTraverser"
permission="zope.Public"
/>
<browser:page
name="_traverse"
for="zope.app.container.interfaces.IItemContainer"
class="zope.app.container.traversal.ItemTraverser"
permission="zope.Public"
/>
<browser:page
name="_traverse"
for="zope.app.container.interfaces.ISimpleReadContainer"
class="zope.app.container.traversal.ContainerTraverser"
permission="zope.Public"
/>
<view
for="*"
name="absolute_url"
factory=".AbsoluteURL"
type="zope.publisher.interfaces.http.IHTTPRequest"
permission="zope.Public"
allowed_interface=".interfaces.IAbsoluteURL"
/>
<view
for="zope.app.traversing.interfaces.IContainmentRoot"
name="absolute_url"
factory=".SiteAbsoluteURL"
type="zope.publisher.interfaces.http.IHTTPRequest"
permission="zope.Public"
allowed_interface=".interfaces.IAbsoluteURL"
/>
<browser:page
for="*"
name="absolute_url"
class=".AbsoluteURL"
permission="zope.Public"
allowed_interface=".interfaces.IAbsoluteURL"
/>
<browser:page
for="zope.app.traversing.interfaces.IContainmentRoot"
name="absolute_url"
class=".SiteAbsoluteURL"
permission="zope.Public"
allowed_interface=".interfaces.IAbsoluteURL"
/>
</configure>
=== Added File Zope3/src/zope/app/traversing/browser/interfaces.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""
Revision information:
$Id: interfaces.py,v 1.1 2004/03/14 03:44:08 srichter Exp $
"""
from zope.interface import Interface
class IAbsoluteURL(Interface):
def __str__():
"""Get a human-readable string representation
"""
def __repr__():
"""Get a string representation
"""
def __call__():
"""Get a string representation
"""
def breadcrumbs():
"""Return a tuple like ({'name':name, 'url':url}, ...)
Name is the name to display for that segment of the breadcrumbs.
URL is the link for that segment of the breadcrumbs.
"""
More information about the Zope3-Checkins
mailing list