[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/ZopePublication/TraversalViews - AbsoluteURL.py:1.1 ObjectName.py:1.1 __init__.py:1.1 config.zcml:1.1

Steve Alexander steve@cat-box.net
Thu, 13 Jun 2002 12:20:10 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/ZopePublication/TraversalViews
In directory cvs.zope.org:/tmp/cvs-serv4064/TraversalViews

Added Files:
	AbsoluteURL.py ObjectName.py __init__.py config.zcml 
Log Message:
Moved AbsoluteURL into a TraversalViews package, to cover both
AbsoluteURL and also ObjectName.

ObjectName is sort of like a minimal version of AbsoluteURL in that it
gets you the name the current object was traversed via.
It can be used as a view, as @@object_name or by getting an adapter 
for IObjectName, as in getAdapter(obj, IObjectName)().

Also, I added a __call__ method to IAbsoluteURL, as it was needed for
security declarations.


=== Added File Zope3/lib/python/Zope/App/ZopePublication/TraversalViews/AbsoluteURL.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: AbsoluteURL.py,v 1.1 2002/06/13 16:20:09 stevea Exp $
"""
from Zope.Publisher.Browser.BrowserView import BrowserView
from Zope.Proxy.ContextWrapper import getWrapperContainer, getWrapperData
from Zope.ComponentArchitecture import getView

from 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
        """

class AbsoluteURL(BrowserView):

    def __str__(self):
        context = self.context
        dict = getWrapperData(context)
        name = dict and dict.get('name') or None
        container = getWrapperContainer(context)
        if name is None or container is None:
            raise TypeError, 'Not enough context information to get a URL'

        return "%s/%s" % (getView(container, 'absolute_url', self.request),
                          name)

    __call__ = __str__


class SiteAbsoluteURL(BrowserView):

    def __str__(self):
        return self.request.getApplicationURL()

    __call__ = __str__


=== Added File Zope3/lib/python/Zope/App/ZopePublication/TraversalViews/ObjectName.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: ObjectName.py,v 1.1 2002/06/13 16:20:09 stevea Exp $
"""
from Zope.Publisher.Browser.IBrowserView import IBrowserView
from Zope.Proxy.ContextWrapper import getWrapperData

from Interface import Interface

class IObjectName(Interface):

    def __str__():
        """Get a human-readable string representation
        """

    def __repr__():
        """Get a string representation
        """
        
    def __call__():
        """Get a string representation
        """

class ObjectName(object):
    # functions as both view and adapter

    __implements__ = IBrowserView, IObjectName
    
    def __init__(self, context, request=None):
        self.context = context

    def __str__(self):
        dict = getWrapperData(self.context)
        name = dict and dict.get('name') or None
        if name is None:
            raise TypeError, \
                  'Not enough context information to get an object name'
        return name

    __call__ = __str__


class SiteObjectName(object):
    # functions as both view and adapter

    __implements__ = IBrowserView, IObjectName
    
    def __init__(self, context, request=None):
        pass
        
    def __str__(self):
        return ''

    __call__ = __str__


=== Added File Zope3/lib/python/Zope/App/ZopePublication/TraversalViews/__init__.py ===
# empty __init__.py file to make this a package


=== Added File Zope3/lib/python/Zope/App/ZopePublication/TraversalViews/config.zcml ===
<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
   xmlns:security='http://namespaces.zope.org/security'
   xmlns:browser='http://namespaces.zope.org/browser'
>

  <browser:view
      name="absolute_url"
      factory=".AbsoluteURL."
      permission='Zope.Public'
      allowed_interface=".AbsoluteURL.IAbsoluteURL"
  />
  
  <browser:view
      for="Zope.App.OFS.Content.Folder.RootFolder.IRootFolder"
      name="absolute_url"
      factory=".AbsoluteURL.SiteAbsoluteURL"
      permission='Zope.Public'
      allowed_interface=".AbsoluteURL.IAbsoluteURL"
  />

  <browser:view
      name="object_name"
      factory=".ObjectName."
      permission='Zope.Public'
      allowed_interface=".ObjectName.IObjectName"
  />
  
  <browser:view
      for="Zope.App.OFS.Content.Folder.RootFolder.IRootFolder"
      name="object_name"
      factory=".ObjectName.SiteObjectName"
      permission='Zope.Public'
      allowed_interface=".ObjectName.IObjectName"
  />

  <adapter
      factory=".ObjectName."
      provides=".ObjectName.IObjectName"
      permission='Zope.Public'
  />
  
  <adapter
      factory=".ObjectName.SiteObjectName"
      provides=".ObjectName.IObjectName"
      for="Zope.App.OFS.Content.Folder.RootFolder.IRootFolder"
      permission='Zope.Public'
  />

</zopeConfigure>