[Zope3-checkins]
SVN: Zope3/branches/Zope-3.1/src/zope/app/component/browser/
Backported revision 40070 and 40187,
both of which dealt with providing
Stephan Richter
srichter at cosmos.phy.tufts.edu
Wed Nov 16 18:51:53 EST 2005
Log message for revision 40188:
Backported revision 40070 and 40187, both of which dealt with providing
better tests for zope.app.component.browser (issue 475).
Changed:
U Zope3/branches/Zope-3.1/src/zope/app/component/browser/configure.zcml
U Zope3/branches/Zope-3.1/src/zope/app/component/browser/registration.py
U Zope3/branches/Zope-3.1/src/zope/app/component/browser/site_management.pt
A Zope3/branches/Zope-3.1/src/zope/app/component/browser/tests/
U Zope3/branches/Zope-3.1/src/zope/app/component/browser/tools.py
A Zope3/branches/Zope-3.1/src/zope/app/component/browser/tools.txt
D Zope3/branches/Zope-3.1/src/zope/app/component/browser/xxx_tests/
-=-
Modified: Zope3/branches/Zope-3.1/src/zope/app/component/browser/configure.zcml
===================================================================
--- Zope3/branches/Zope-3.1/src/zope/app/component/browser/configure.zcml 2005-11-16 23:37:25 UTC (rev 40187)
+++ Zope3/branches/Zope-3.1/src/zope/app/component/browser/configure.zcml 2005-11-16 23:51:53 UTC (rev 40188)
@@ -44,7 +44,7 @@
/>
<page
- name="index.html"
+ name="index.html"
for="zope.app.component.interfaces.registration.IRegistrationManager"
menu="zmi_views" title="Registration"
permission="zope.ManageSite"
@@ -105,9 +105,9 @@
<page
for="zope.app.component.interfaces.ISiteManagementFolder"
- permission="zope.ManageSite"
+ permission="zope.ManageSite"
class="zope.app.container.browser.contents.JustContents"
- name="index.html" attribute="index"
+ name="index.html" attribute="index"
/>
<page
@@ -116,7 +116,7 @@
menu="zmi_views" title="Contents"
permission="zope.ManageSite"
class="zope.app.container.browser.contents.Contents"
- attribute="contents"
+ attribute="contents"
/>
<view
@@ -183,7 +183,7 @@
menu="zmi_actions" title="Add Site Management Folder"
for="zope.app.component.interfaces.ILocalSiteManager"
permission="zope.ManageSite"
- class="zope.app.container.browser.adding.Adding"
+ class="zope.app.container.browser.adding.Adding"
>
<page name="index.html" attribute="index"/>
<page name="action.html" attribute="action"/>
@@ -225,8 +225,8 @@
arguments="name provided component"
fields="name provided component status permission"
>
- <widget
- field="name"
+ <widget
+ field="name"
class="zope.app.form.browser.TextWidget"
required="False"
convert_missing_value="False"
@@ -264,7 +264,7 @@
arguments="required provided factoryName"
keyword_arguments="name permission"
permission="zope.ManageServices"
- fields="required provided name permission factoryName"
+ fields="required provided name permission factoryName"
menu="add_registration" title="Adapter Registration"
/-->
Modified: Zope3/branches/Zope-3.1/src/zope/app/component/browser/registration.py
===================================================================
--- Zope3/branches/Zope-3.1/src/zope/app/component/browser/registration.py 2005-11-16 23:37:25 UTC (rev 40187)
+++ Zope3/branches/Zope-3.1/src/zope/app/component/browser/registration.py 2005-11-16 23:51:53 UTC (rev 40188)
@@ -85,68 +85,6 @@
for reg in registered.registrations()]
-class ChangeRegistrations(BrowserView):
-
- _prefix = 'registrations'
- name = _prefix + ".active"
- message = ''
- configBase = ''
-
- def setPrefix(self, prefix):
- self._prefix = prefix
- self.name = prefix + ".active"
-
- def applyUpdates(self):
- message = ''
- if 'submit_update' in self.request.form:
- id = self.request.form.get(self.name)
- if id == "disable":
- active = self.context.active()
- if active is not None:
- self.context.activate(None)
- message = _("Disabled")
- else:
- for info in self.context.info():
- infoid = zapi.getPath(info['registration'])
- if infoid == id and not info['active']:
- self.context.activate(info['registration'])
- message = _("Updated")
- break
-
- return message
-
- def update(self):
- message = self.applyUpdates()
-
- self.configBase = zapi.absoluteURL(zapi.getSiteManager(), self.request)
-
- registrations = self.context.info()
-
- # This is OK because registrations is just a list of dicts
- registrations = removeSecurityProxy(registrations)
-
- inactive = 1
- for info in registrations:
- if info['active']:
- inactive = None
- else:
- info['active'] = False
-
- reg = info['registration']
- info['summary'] = reg.implementationSummary()
- info['id'] = zapi.getPath(reg)
-
- # Add a dummy registration since the stack removes trailing None.
- registrations.append({"active": False,
- "id": "disable",
- "summary": ""})
-
- self.inactive = inactive
- self.registrations = registrations
-
- self.message = message
-
-
#############################################################################
# BBB: Only for backward compatibility. 12/07/2004
class ComponentPathWidget(SimpleInputWidget):
Modified: Zope3/branches/Zope-3.1/src/zope/app/component/browser/site_management.pt
===================================================================
--- Zope3/branches/Zope-3.1/src/zope/app/component/browser/site_management.pt 2005-11-16 23:37:25 UTC (rev 40187)
+++ Zope3/branches/Zope-3.1/src/zope/app/component/browser/site_management.pt 2005-11-16 23:51:53 UTC (rev 40188)
@@ -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"
Copied: Zope3/branches/Zope-3.1/src/zope/app/component/browser/tests (from rev 40187, Zope3/trunk/src/zope/app/component/browser/tests)
Modified: Zope3/branches/Zope-3.1/src/zope/app/component/browser/tools.py
===================================================================
--- Zope3/branches/Zope-3.1/src/zope/app/component/browser/tools.py 2005-11-16 23:37:25 UTC (rev 40187)
+++ Zope3/branches/Zope-3.1/src/zope/app/component/browser/tools.py 2005-11-16 23:51:53 UTC (rev 40188)
@@ -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 ZopeMessageIDFactory 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''
Copied: Zope3/branches/Zope-3.1/src/zope/app/component/browser/tools.txt (from rev 40187, Zope3/trunk/src/zope/app/component/browser/tools.txt)
More information about the Zope3-Checkins
mailing list