[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services - componentpathwidget.py:1.1.2.1 configure.zcml:1.31.2.4

Jim Fulton jim@zope.com
Wed, 19 Mar 2003 16:09:36 -0500


Update of /cvs-repository/Zope3/src/zope/app/browser/services
In directory cvs.zope.org:/tmp/cvs-serv21546/src/zope/app/browser/services

Modified Files:
      Tag: local-utility-branch
	configure.zcml 
Added Files:
      Tag: local-utility-branch
	componentpathwidget.py 
Log Message:
Added a new component path field and widget that simply shows the
component path for the compontent being configured. We no longer
select a component because configuration is done from the component
bing configured.



=== Added File Zope3/src/zope/app/browser/services/componentpathwidget.py ===
##############################################################################
#
# Copyright (c) 2003 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.
#
##############################################################################
"""Simple component path widget

$Id: componentpathwidget.py,v 1.1.2.1 2003/03/19 21:09:05 jim Exp $
"""

from zope.app.interfaces.browser.form import IBrowserWidget
from zope.app.interfaces.services.configuration import IComponentConfiguration
from zope.app.traversing import getPhysicalPathString, traverse
from zope.component import getView
from zope.app.browser.form.widget import BrowserWidget

class ComponentPathWidget(BrowserWidget):
    """Widget for displaying component paths

    The widget doesn't actually allow editing. Rather it gets the
    value by inspecting its field's context. If the context is an
    IComponentConfiguration, then it just gets it's value from the
    component using the field's name. Otherwise, it uses the path to
    the context.
    """

    __implements__ =  IBrowserWidget


    def __call__(self):
        "See zope.app.interfaces.browser.form.IBrowserWidget"
        # Render as a link to the component
        field = self.context
        context = field.context 
        if IComponentConfiguration.isImplementedBy(context):
            # It's a configuration object. Just get the corresponsing attr
            path = getattr(context, field.__name__)
            component = traverse(context, path)
        else:
            # It must be a component that is about to be configured.
            component = context
            path = getPhysicalPathString(context)

        url = getView(component, 'absolute_url', self.request)

        return ('<a href="%s/@@SelectedManagementView.html">%s</a>'
                % (url, path))

    def hidden(self):
        "See zope.app.interfaces.browser.form.IBrowserWidget"
        return ''

    def getData(self):
        "See zope.app.interfaces.form.IWidget"
        field = self.context
        context = field.context 
        if IComponentConfiguration.isImplementedBy(context):
            # It's a configuration object. Just get the corresponsing attr
            path = getattr(context, self.__name__)
        else:
            # It must be a component that is about to be configured.
            path = getPhysicalPathString(context)

        return path

    def haveData(self):
        "See zope.app.interfaces.form.IWidget"
        return True


=== Zope3/src/zope/app/browser/services/configure.zcml 1.31.2.3 => 1.31.2.4 ===
--- Zope3/src/zope/app/browser/services/configure.zcml:1.31.2.3	Tue Mar 18 16:10:02 2003
+++ Zope3/src/zope/app/browser/services/configure.zcml	Wed Mar 19 16:09:05 2003
@@ -859,4 +859,26 @@
 
   </view>
 
+<!-- Component path widget -->
+
+<page
+    permission="zope.Public"
+    allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
+    for="zope.app.interfaces.services.configuration.IComponentPath"
+    name="edit"
+    class=
+    "zope.app.browser.services.componentpathwidget.ComponentPathWidget" 
+    />
+
+<page
+    permission="zope.Public"
+    allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
+    for="zope.app.interfaces.services.configuration.IComponentPath"
+    name="display"
+    class=
+    "zope.app.browser.services.componentpathwidget.ComponentPathWidget" 
+    />
+
+
+
 </zopeConfigure>