[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services/utility - addconfiguration.pt:1.1.2.1 useconfiguration.pt:1.1.2.1 useconfiguration.py:1.1.2.1
   
    Guido van Rossum
     
    guido@python.org
       
    Mon, 17 Mar 2003 11:16:50 -0500
    
    
  
Update of /cvs-repository/Zope3/src/zope/app/browser/services/utility
In directory cvs.zope.org:/tmp/cvs-serv23553
Added Files:
      Tag: local-utility-branch
	addconfiguration.pt useconfiguration.pt useconfiguration.py 
Log Message:
Three files that weren't added by mistake.
=== Added File Zope3/src/zope/app/browser/services/utility/addconfiguration.pt ===
<html metal:use-macro="context/@@standard_macros/page">
  <body>
    <div metal:fill-slot="body">
      <form action="addConfiguration_action.html">
        <div class="row">
	  <div class="label">Utility name</div>
	  <div class="field"><input type="text" name="name"></div>
	  <br>
	  <div class="label">Interface</div>
	  <select name="interface">
            <option tal:repeat="interface view/listInterfaces"
	            tal:attributes="value interface/id"
		    tal:content="interface/name">IFoo</option>
	  </select>
	  <br>
	  <input type="reset" value="Reset form">
	  <input type="submit" value="Submit">
	</div>
      </form>
    </div>
  </body>
</html>
=== Added File Zope3/src/zope/app/browser/services/utility/useconfiguration.pt ===
<html metal:use-macro="context/@@standard_macros/page">
<body>
  <div metal:fill-slot="body">
    <p>Configurations for this utility:</p>
    <ul>
      <li tal:repeat="use view/uses">
	<a href="."
	   tal:attributes="href use/url">
	  <span tal:replace="use/interface">IFoo</span>
	  <span tal:condition="use/name">
	    named <span tal:replace="use/name" />
	  </span>
	</a>
	(<span tal:replace="use/status">Active</span>)
      </li>
    </ul>
    <p><a href="addConfiguration.html">Add a configuration for this utility</a>
  </div>
</body>
</html>
=== Added File Zope3/src/zope/app/browser/services/utility/useconfiguration.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.
#
##############################################################################
"""Use-Configuration view for utilities.
$Id: useconfiguration.py,v 1.1.2.1 2003/03/17 16:16:48 gvanrossum Exp $
"""
from zope.component import getAdapter, getView
from zope.app.interfaces.services.configuration import IUseConfiguration
from zope.app.traversing import traverse, getPhysicalPathString
from zope.publisher.browser import BrowserView
from zope.interface.implements import flattenInterfaces
from zope.app.interfaces.services.configuration \
     import Unregistered, Registered, Active
from zope.app.services.utility import UtilityConfiguration
from zope.proxy.introspection import removeAllProxies
from zope.proxy.context import getWrapperContainer
from zope.app.interfaces.container import IZopeContainer
class UseConfiguration(BrowserView):
    def uses(self):
        component = self.context
        useconfig = getAdapter(component, IUseConfiguration)
        result = []
        for path in useconfig.usages():
            config = traverse(component, path)
            url = getView(config, 'absolute_url', self.request)
            result.append({'name': config.name,
                           'interface': config.interface.__name__,
                           'path': path,
                           'url': url(),
                           'status': config.status,
                           })
        return result
class AddConfiguration(BrowserView):
    def action(self, name, interface=None):
        if interface is None:
            raise UserError("you must select an interface")
        path = getPhysicalPathString(self.context)
        configure = traverse(getWrapperContainer(self.context), 'configure')
        container = getAdapter(configure, IZopeContainer)
        config = UtilityConfiguration(name, interface, path)
        name = container.setObject("", config)
        config = container[name]
        config.status = Active # XXX Really? Always activate it?
        self.request.response.redirect("@@useConfiguration.html")
    def listInterfaces(self):
        bare = removeAllProxies(self.context)
        return [{'id': i.__module__ + "." + i.__name__, 'name': i.__name__}
                for i in flattenInterfaces(bare.__implements__)
                if i.names(True)]