[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/component/browser/
Jürgen Kartnaller
juergen at kartnaller.at
Sat Nov 12 13:01:01 EST 2005
Log message for revision 40070:
Changed:
U Zope3/trunk/src/zope/app/component/browser/site_management.pt
A Zope3/trunk/src/zope/app/component/browser/tests/
A Zope3/trunk/src/zope/app/component/browser/tests/__init__.py
A Zope3/trunk/src/zope/app/component/browser/tests/test_tools.py
U Zope3/trunk/src/zope/app/component/browser/tools.py
A Zope3/trunk/src/zope/app/component/browser/tools.txt
-=-
Modified: Zope3/trunk/src/zope/app/component/browser/site_management.pt
===================================================================
--- Zope3/trunk/src/zope/app/component/browser/site_management.pt 2005-11-12 17:32:32 UTC (rev 40069)
+++ Zope3/trunk/src/zope/app/component/browser/site_management.pt 2005-11-12 18:01:00 UTC (rev 40070)
@@ -56,6 +56,13 @@
Description of the tool
</div>
<br/>
+ <div class="message"
+ tal:define="message tool/message"
+ tal:condition="message"
+ tal:content="message" i18n:translate="">
+ Status Message
+ </div>
+ <br/>
<div tal:define="instances tool/instances">
<div tal:repeat="instance instances"
tal:condition="instances">
@@ -84,7 +91,11 @@
<input type="hidden" name="old_names:list" value=""
tal:attributes="value instance/name" />
<input type="text" size="20" name="new_names:list" value=""
+ tal:condition="not:instance/renameNew"
tal:attributes="value instance/name" />
+ <input type="text" size="20" name="new_names:list" value=""
+ tal:condition="instance/renameNew"
+ tal:attributes="value instance/renameNew" />
</span>
</div>
@@ -95,7 +106,9 @@
</div>
<div tal:condition="tool/add">
<div tal:define="info view/addingInfo">
- <input type="text" width="20" name="id" value="">
+ <input type="text" width="20" name="id" value=""
+ tal:attributes="value tool/addname"
+ />
<select name="type_name">
<option tal:repeat="entry info"
tal:attributes="value entry/action"
Added: Zope3/trunk/src/zope/app/component/browser/tests/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/component/browser/tests/__init__.py 2005-11-12 17:32:32 UTC (rev 40069)
+++ Zope3/trunk/src/zope/app/component/browser/tests/__init__.py 2005-11-12 18:01:00 UTC (rev 40070)
@@ -0,0 +1 @@
+# python package
Property changes on: Zope3/trunk/src/zope/app/component/browser/tests/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Zope3/trunk/src/zope/app/component/browser/tests/test_tools.py
===================================================================
--- Zope3/trunk/src/zope/app/component/browser/tests/test_tools.py 2005-11-12 17:32:32 UTC (rev 40069)
+++ Zope3/trunk/src/zope/app/component/browser/tests/test_tools.py 2005-11-12 18:01:00 UTC (rev 40070)
@@ -0,0 +1,21 @@
+import unittest
+from zope.testing import doctest
+from zope.app.testing.setup import placefulSetUp
+from zope.app.testing.setup import placefulTearDown
+
+def setUp(self):
+ placefulSetUp(True)
+
+def tearDown(self):
+ placefulTearDown()
+
+def test_suite():
+ return unittest.TestSuite((
+ doctest.DocFileSuite('../tools.txt',
+ setUp=setUp,
+ tearDown=tearDown),
+ ))
+
+if __name__=='main':
+ unittest.main(defaultTest='test_suite')
+
Property changes on: Zope3/trunk/src/zope/app/component/browser/tests/test_tools.py
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: Zope3/trunk/src/zope/app/component/browser/tools.py
===================================================================
--- Zope3/trunk/src/zope/app/component/browser/tools.py 2005-11-12 17:32:32 UTC (rev 40069)
+++ Zope3/trunk/src/zope/app/component/browser/tools.py 2005-11-12 18:01:00 UTC (rev 40070)
@@ -21,6 +21,7 @@
from zope.app import zapi
from zope.app.component import site, interfaces, browser
from zope.app.event import objectevent
+from zope.app.exception.interfaces import UserError
from zope.app.i18n import ZopeMessageFactory as _
@@ -59,7 +60,11 @@
activeTool = None
addTool = False
+ addName = u''
+ renameTool = False
renameList = []
+ newNames = []
+ msg = u''
def __init__(self, context, request):
super(SiteManagementView, self).__init__(context, request)
@@ -82,7 +87,12 @@
self.uninstall()
msg = _(u'Tools successfully uninstalled.')
if "ADD-TOOL-SUBMIT" in self.request:
- self.action(self.request['type_name'], self.request['id'])
+ try:
+ self.action(self.request['type_name'], self.request['id'])
+ except UserError, err:
+ self.addTool = True
+ self.addName = self.contentName
+ msg=err
elif "CANCEL-ADD-TOOL-SUBMIT" in self.request:
self.request.response.expireCookie('SetActiveTool')
self.activeTool = None
@@ -95,15 +105,26 @@
elif "ADD-SUBMIT" in self.request:
self.addTool = True
elif "DELETE-SUBMIT" in self.request:
- self.delete()
+ if 'selected' in self.request:
+ self.delete()
+ msg = _(u'Tools successfully deleted.')
+ else:
+ msg = _(u'No tools selected.')
elif "RENAME-SUBMIT" in self.request:
if 'selected' in self.request:
self.renameList = self.request['selected']
if 'new_names' in self.request:
- self.rename()
- msg = _(u'Tools successfully renamed.')
+ self.renameList = self.request['old_names']
+ self.newNames = self.request['new_names']
+ try:
+ self.rename()
+ except UserError, err:
+ msg=err
+ else:
+ msg = _(u'Tools successfully renamed.')
elif "RENAME-CANCEL-SUBMIT" in self.request:
self.activeTool = None
+ self.msg=msg
return msg
def getSiteManagementFolder(self, tool):
@@ -143,7 +164,11 @@
{'name': reg.name,
'url': zapi.absoluteURL(reg.component, self.request),
'rename': tool is self.activeTool and reg.name in self.renameList,
- 'active': reg.status == u'Active'
+ 'renameNew': tool is self.activeTool and \
+ reg.name in self.renameList and \
+ self.newNames and \
+ self.newNames[self.renameList.index(reg.name)],
+ 'active': reg.status == u'Active',
}
for reg in regManager.values()
if (zapi.isinstance(reg, site.UtilityRegistration) and
@@ -156,7 +181,9 @@
'description': tool.description,
'instances': self.getToolInstances(tool),
'add': tool is self.activeTool and self.addTool,
- 'rename': tool is self.activeTool and self.renameList
+ 'addname': tool is self.activeTool and self.addTool and self.addName,
+ 'rename': tool is self.activeTool and self.renameList,
+ 'message': tool is self.activeTool and self.msg,
}
for name, tool in zapi.getUtilitiesFor(IToolConfiguration)
if not tool.unique]
@@ -192,7 +219,7 @@
tool = self.activeTool
regManager = self.context[tool.folder].registrationManager
names = self.request.form['selected']
- for reg in regManager.values():
+ for reg in list(regManager.values()):
if reg.provided.isOrExtends(tool.interface) and reg.name in names:
component = reg.component
reg.status = interfaces.registration.InactiveStatus
@@ -204,20 +231,43 @@
regManager = self.context[tool.folder].registrationManager
new_names = self.request['new_names']
old_names = self.request['old_names']
+ msg=''
for reg in regManager.values():
if reg.provided.isOrExtends(tool.interface) and \
reg.name in old_names:
- orig_status = reg.status
- reg.status = interfaces.registration.InactiveStatus
- reg.name = new_names[old_names.index(reg.name)]
- reg.status = orig_status
+ old_name=reg.name
+ new_name = new_names[old_names.index(old_name)]
+ if new_name!=reg.name:
+ if self.toolExists(self.activeTool.interface,new_name):
+ if not msg:
+ msg=_(u'The given tool name is already being used.')
+ else:
+ orig_status = reg.status
+ reg.status = interfaces.registration.InactiveStatus
+ reg.name = new_names[old_names.index(old_name)]
+ reg.status = orig_status
+ self.renameList.remove(old_name)
+ self.newNames.remove(new_name)
+ else:
+ self.renameList.remove(old_name)
+ self.newNames.remove(new_name)
+ if msg:
+ raise UserError(msg)
def add(self, content):
"""See zope.app.container.interfaces.IAdding"""
+
+ name = self.contentName
+ if self.toolExists(self.activeTool.interface,name):
+ raise UserError(_(u'The given tool name is already being used.'))
+
sm = self.context
+
self.context = self.getSiteManagementFolder(self.activeTool)
+ self.contentName = '' # always use a unique name
util = super(SiteManagementView, self).add(content)
+ self.contentName = name
# Add registration
name = not self.activeTool.unique and self.contentName or u''
Added: Zope3/trunk/src/zope/app/component/browser/tools.txt
===================================================================
--- Zope3/trunk/src/zope/app/component/browser/tools.txt 2005-11-12 17:32:32 UTC (rev 40069)
+++ Zope3/trunk/src/zope/app/component/browser/tools.txt 2005-11-12 18:01:00 UTC (rev 40070)
@@ -0,0 +1,160 @@
+==============
+The Tools View
+==============
+
+ >>> from zope import interface
+
+First we define a utility to work with :
+
+ >>> from zope.app.content.interfaces import IContentType
+ >>> from zope.app.component.interfaces.registration import IRegisterable
+ >>> class IFooUtil(interface.Interface):
+ ... pass
+ >>> class FooUtil(object):
+ ... __parent__ = None
+ ... __name__ = u''
+ ... interface.implements(IFooUtil, IRegisterable, IContentType)
+
+ >>> from zope.app.component.browser import tools
+ >>> from zope import component
+
+ >>> toolConfig = tools.ToolConfiguration(IFooUtil, 'FooUtil')
+ >>> component.provideUtility(toolConfig, tools.IToolConfiguration, 'IFooUtil')
+
+We need a factory to create our new utility :
+
+ >>> from zope.component.interfaces import IFactory
+ >>> from zope.component.factory import Factory
+
+ >>> from zope.app.security import protectclass
+ >>> protectclass.protectName(Factory, '__call__', 'zope.public')
+
+ >>> factory = Factory(FooUtil,
+ ... 'Utility for foo',
+ ... 'This factory creates a foo utility.')
+ >>> component.provideUtility(factory, IFactory, 'IFooUtil')
+
+Let's now invoke our site management :
+
+ >>> from zope.publisher.browser import TestRequest
+ >>> request = TestRequest()
+ >>> request.form['activeTool']='IFooUtil'
+
+ >>> from zope.app import zapi
+ >>> view = tools.SiteManagementView(zapi.getSiteManager(), request)
+ >>> view.update()
+ u''
+ >>> request.form['ADD-TOOL-SUBMIT']='submit'
+ >>> request.form['type_name']='IFooUtil'
+ >>> request.form['id']='foo1'
+ >>> view.update()
+ u''
+ >>> util = component.getUtility(IFooUtil, 'foo1')
+ >>> util is not None
+ True
+ >>> current_tools = view.getTools()
+ >>> len(current_tools)
+ 1
+ >>> current_tools[0]['instances'][0]['name']
+ 'foo1'
+
+Registering with the same name
+------------------------------
+
+ >>> print view.update()
+ The given tool name is already being used.
+
+ >>> request.form['id']='foo2'
+ >>> view = tools.SiteManagementView(zapi.getSiteManager(), request)
+ >>> view.update()
+ u''
+ >>> current_tools = view.getTools()
+ >>> current_tools[0]['instances'][0]['name']
+ 'foo1'
+ >>> current_tools[0]['instances'][1]['name']
+ 'foo2'
+
+Creating a utility without a name
+---------------------------------
+
+ >>> request.form['id']=''
+ >>> view = tools.SiteManagementView(zapi.getSiteManager(), request)
+ >>> view.update()
+ u''
+ >>> current_tools = view.getTools()
+ >>> current_tools[0]['instances'][0]['name']
+ 'foo1'
+ >>> current_tools[0]['instances'][1]['name']
+ 'foo2'
+ >>> current_tools[0]['instances'][2]['name']
+ u''
+
+Renaming utilities
+------------------
+
+ >>> request = TestRequest()
+ >>> request.form['activeTool']='IFooUtil'
+ >>> request.form['RENAME-SUBMIT']='submit'
+
+First we rename a single utility :
+
+ >>> request.form['old_names']=['foo1']
+ >>> request.form['new_names']=['JohnDoe']
+ >>> view = tools.SiteManagementView(zapi.getSiteManager(), request)
+ >>> view.update()
+ u'Tools successfully renamed.'
+ >>> current_tools = view.getTools()
+ >>> current_tools[0]['instances'][0]['name']
+ 'JohnDoe'
+ >>> current_tools[0]['instances'][1]['name']
+ 'foo2'
+ >>> current_tools[0]['instances'][2]['name']
+ u''
+
+ >>> request.form['old_names']=['JohnDoe', 'foo2']
+ >>> request.form['new_names']=['foo1', 'Tres']
+ >>> view = tools.SiteManagementView(zapi.getSiteManager(), request)
+ >>> view.update()
+ u'Tools successfully renamed.'
+ >>> current_tools = view.getTools()
+ >>> current_tools[0]['instances'][0]['name']
+ 'foo1'
+ >>> current_tools[0]['instances'][1]['name']
+ 'Tres'
+ >>> current_tools[0]['instances'][2]['name']
+ u''
+
+Deleting utilities
+------------------
+
+ >>> request = TestRequest()
+ >>> request.form['activeTool']='IFooUtil'
+ >>> request.form['DELETE-SUBMIT']='submit'
+
+First we try without a selected utility :
+
+ >>> view = tools.SiteManagementView(zapi.getSiteManager(), request)
+ >>> view.update()
+ u'No tools selected.'
+
+Now select one utility :
+
+ >>> request.form['selected']=['']
+ >>> view = tools.SiteManagementView(zapi.getSiteManager(), request)
+ >>> view.update()
+ u'Tools successfully deleted.'
+ >>> current_tools = view.getTools()
+ >>> current_tools[0]['instances'][0]['name']
+ 'foo1'
+ >>> current_tools[0]['instances'][1]['name']
+ 'Tres'
+
+Select all the remaining utilities :
+
+ >>> request.form['selected']=['foo1', 'Tres']
+ >>> view = tools.SiteManagementView(zapi.getSiteManager(), request)
+ >>> view.update()
+ u'Tools successfully deleted.'
+ >>> view.getTools()[0]['instances']
+ []
+
Property changes on: Zope3/trunk/src/zope/app/component/browser/tools.txt
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the Zope3-Checkins
mailing list