[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/ServiceManager - interfaces.py:1.1.2.1 viewpackage.py:1.1.2.1 configure.zcml:1.8.12.1

Jim Fulton jim@zope.com
Thu, 12 Dec 2002 10:20:26 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/ServiceManager
In directory cvs.zope.org:/tmp/cvs-serv23093/lib/python/Zope/App/OFS/Services/ServiceManager

Modified Files:
      Tag: AdapterAndView-branch
	configure.zcml 
Added Files:
      Tag: AdapterAndView-branch
	interfaces.py viewpackage.py 
Log Message:
Got view service and view registration working TTW (sort of).

This includes a new "View Package". You set up a view package with
default registration parameters. Then, as you add ZPT templates to the
package, they are automatically registered as views.

There are lots of rough edges that need to be smoothed out after the
sprint and before this branch merge.



=== Added File Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/interfaces.py ===
##############################################################################
#
# Copyright (c) 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.
# 
##############################################################################
"""View package.

$Id: interfaces.py,v 1.1.2.1 2002/12/12 15:19:55 jim Exp $
"""
__metaclass__ = type

from Zope.Publisher.Browser.IBrowserPresentation import IBrowserPresentation
from Interface import Interface
from Zope.App.ComponentArchitecture.InterfaceField import InterfaceField
from Zope.Schema import BytesLine
from Zope.ComponentArchitecture.IPresentation import IPresentation
from Zope.App.OFS.Container.IContainer import IContainer

class IViewPackageInfo(Interface):

    forInterface = InterfaceField(
        title = u"For interface",
        description = u"The interface of the objects being viewed",
        required = True,
        )

    presentationType = InterfaceField(
        title = u"Presentation type",
        description = u"The presentation type of a view",
        required = True,
        type = IPresentation,
        default = IBrowserPresentation,
        )

    factoryName = BytesLine(
        title=u"The dotted name of a factory for creating the view",
        required = True,
        )

    layer = BytesLine(
        title = u"Layer",
        description = u"The skin layer the view is registered for",
        required = False,
        min_length = 1,
        default = "default",
        )

class IViewPackage(IViewPackageInfo,  IContainer):
    """Sub-packages that contain templates that are registered as views
    """


=== Added File Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/viewpackage.py ===
##############################################################################
#
# Copyright (c) 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.
# 
##############################################################################
"""View package.

$Id: viewpackage.py,v 1.1.2.1 2002/12/12 15:19:55 jim Exp $
"""
__metaclass__ = type

from Zope.App.OFS.Container.BTreeContainer import BTreeContainer
from Zope.App.OFS.Services.interfaces import IZPTTemplate
from Zope.Publisher.Browser.IBrowserPresentation import IBrowserPresentation
from Zope.App.Traversing import getPhysicalPathString, traverse
from Zope.Proxy.ContextWrapper import getItem, getAttr
from Zope.ContextWrapper import ContextMethod
from Zope.App.OFS.Services.ConfigurationInterfaces import Active
from Zope.App.OFS.Services.ServiceManager.ConfigurationManager \
     import ConfigurationManager
from Zope.App.OFS.Services.Configuration import ConfigurationStatusProperty
from Zope.Proxy.ProxyIntrospection import removeAllProxies
from Zope.App.OFS.Services.view import PageConfiguration
from interfaces import IViewPackage

class ViewPackage(BTreeContainer):

    __implements__ = IViewPackage


    presentationType = IBrowserPresentation
    layer = "default"
    description = ''
    title = ''

    def __init__(self):
        super(ViewPackage, self).__init__()
        super(ViewPackage, self).setObject('configure', ConfigurationManager())

    def setObject(self, name, object):
        if not IZPTTemplate.isImplementedBy(object):
            raise TypeError("Can only add packages")
        
        # super() does not work on a context wrapped instance
        base = removeAllProxies(self)

        name = super(ViewPackage, base).setObject(name, object)
        template = getItem(self, name)
        template = getPhysicalPathString(template)
        config = PageConfiguration(self.forInterface, name,
                                   self.presentationType,
                                   self.factoryName, template,
                                   self.layer)
        configure = traverse(self, 'configure')
        id = configure.setObject('', config)
        config = getItem(configure, id)
        config.status = Active
        return name

    setObject = ContextMethod(setObject)

    def activated(self):
        "See Zope.App.OFS.Services.ConfigurationInterfaces.IConfiguration"

    def deactivated(self):
        "See Zope.App.OFS.Services.ConfigurationInterfaces.IConfiguration"



=== Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/configure.zcml 1.8 => 1.8.12.1 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/configure.zcml:1.8	Sun Dec  1 05:28:22 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/configure.zcml	Thu Dec 12 10:19:55 2002
@@ -23,6 +23,7 @@
     <require
         permission="Zope.ManageServices"
         interface=".IComponentManager." />
+    <implements interface="Zope.App.OFS.Annotation.IAttributeAnnotatable." />
 
   </content>
 
@@ -33,6 +34,7 @@
     <require
         permission="Zope.ManageServices"
         interface="Zope.App.OFS.Container.IContainer.IWriteContainer" />
+    <implements interface="Zope.App.OFS.Annotation.IAttributeAnnotatable." />
 
   </content>
 
@@ -50,6 +52,7 @@
         id = "Zope.App.OFS.Services.ServiceManager.ConfigurationManager" 
 	permission = "Zope.ManageServices"
 	title = "Configuration Manager" />
+    <implements interface="Zope.App.OFS.Annotation.IAttributeAnnotatable." />
   </content>
 
   <content class=".Module.Manager.">
@@ -78,6 +81,27 @@
         />
 
   </content>
+
+  <content class=".viewpackage.ViewPackage">
+    <factory 
+        id = "Zope.App.OFS.Services.ServiceManager.viewpackage.ViewPackage" 
+	permission = "Zope.ManageServices"
+	title = "View Package" />
+    <require
+        permission="Zope.View"
+        interface="Zope.App.OFS.Container.IContainer.IReadContainer" />
+    <require
+        permission="Zope.ManageServices"
+        interface="Zope.App.OFS.Container.IContainer.IWriteContainer"
+        set_schema=".interfaces.IViewPackageInfo"
+        />
+    <require
+        permission="Zope.ManageServices"
+        interface=".interfaces.IViewPackageInfo"
+        />
+    <implements interface="Zope.App.OFS.Annotation.IAttributeAnnotatable." />
+  </content>
+
   
   <include package="Zope.App.OFS.Services.ServiceManager.Browser" />