[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services - configureView.pt:1.1 view.py:1.13 view.zcml:1.2 views.pt:1.3
Guido van Rossum
guido@python.org
Thu, 1 May 2003 11:51:25 -0400
Update of /cvs-repository/Zope3/src/zope/app/browser/services
In directory cvs.zope.org:/tmp/cvs-serv31713
Modified Files:
view.py view.zcml views.pt
Added Files:
configureView.pt
Log Message:
Finish Views service configuration panel: implement "(change registration)"
feature, and display the usageSummary(), which looks much nicer than
what we had before. Some internal refactoring.
=== Added File Zope3/src/zope/app/browser/services/configureView.pt ===
<html metal:use-macro="context/@@standard_macros/page">
<div metal:fill-slot="body">
<h2>View registrations for
<i tal:content="view/summary">key</i></h2>
<form method="POST"
action="."
tal:attributes="action request/URL"
tal:define="form view/update"
>
<input type="hidden"
name="key"
tal:attributes="value request/key"
/>
<div tal:replace="structure form" />
<input type="submit"
name="submit_update"
value="Update"
/>
</form>
</div>
</html>
=== Zope3/src/zope/app/browser/services/view.py 1.12 => 1.13 ===
--- Zope3/src/zope/app/browser/services/view.py:1.12 Thu May 1 10:46:26 2003
+++ Zope3/src/zope/app/browser/services/view.py Thu May 1 11:51:24 2003
@@ -11,15 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""Views for local view configuration.
-
- ViewSeviceView -- it's a bit different from other services, as it
- has a lot of things in it, so we provide a search interface:
-
- search page
- browsing page
-
- PageConfigurationView -- calls validation on PageConfiguration.
+"""Helper classes for local view configuration.
$Id$
"""
@@ -68,7 +60,39 @@
)
-class ViewServiceView(BrowserView):
+class _SharedBase(BrowserView):
+
+ def _getRegistryFromKey(self, key):
+ values = key.split(":")
+ assert len(values) == 4, `values`
+ viewName, forInterfaceName, presentationTypeName, layerName = values
+ sm = getServiceManager(self.context)
+ if forInterfaceName == "(Anything)":
+ forInterface = None
+ else:
+ forInterface = sm.resolve(forInterfaceName)
+ presentationType = sm.resolve(presentationTypeName)
+ infos = self.context.getRegisteredMatching(forInterface,
+ presentationType,
+ viewName,
+ layerName)
+ # We only want exact matches on 'forInterface'
+ infos = [info for info in infos if info[0] == forInterface]
+ assert len(infos) == 1
+ registry = infos[0][2]
+ registry = ContextWrapper(registry, self.context)
+ assert registry
+ return registry
+
+ def _getSummaryFromRegistry(self, registry):
+ assert registry
+ # Return the summary of the first configuration in the registry
+ for info in registry.info():
+ return info['configuration'].usageSummary()
+ assert 0
+
+
+class ViewServiceView(_SharedBase):
"""Helper class for the default view on the Views service."""
@@ -96,38 +120,16 @@
if doDelete:
return self._delete(todo)
- def _getInfosFromKey(self, key):
- values = key.split(":")
- assert len(values) == 4, `values`
- viewName, forInterfaceName, presentationTypeName, layerName = values
- sm = getServiceManager(self.context)
- if forInterfaceName == "(Anything)":
- forInterface = None
- else:
- forInterface = sm.resolve(forInterfaceName)
- presentationType = sm.resolve(presentationTypeName)
- infos = self.context.getRegisteredMatching(forInterface,
- presentationType,
- viewName,
- layerName)
- # We only want exact matches on 'forInterface'
- return [info for info in infos if info[0] == forInterface]
-
def _activate(self, todo):
done = []
for key in todo:
- infos = self._getInfosFromKey(key)
- for info in infos:
- (forInterface, presentationType,
- registry, layer, viewName) = info
- registry = ContextWrapper(registry, self.context)
- obj = registry.active()
- if obj is None:
- assert registry
- # Activate the first registered configuration
- obj = registry.info()[0]['configuration']
- obj.status = Active
- done.append(key)
+ registry = self._getRegistryFromKey(key)
+ obj = registry.active()
+ if obj is None:
+ # Activate the first registered configuration
+ obj = registry.info()[0]['configuration']
+ obj.status = Active
+ done.append(self._getSummaryFromRegistry(registry))
if done:
return "Activated: " + ", ".join(done)
else:
@@ -136,15 +138,11 @@
def _deactivate(self, todo):
done = []
for key in todo:
- infos = self._getInfosFromKey(key)
- for info in infos:
- (forInterface, presentationType,
- registry, layer, viewName) = info
- registry = ContextWrapper(registry, self.context)
- obj = registry.active()
- if obj is not None:
- obj.status = Registered
- done.append(key)
+ registry = self._getRegistryFromKey(key)
+ obj = registry.active()
+ if obj is not None:
+ obj.status = Registered
+ done.append(self._getSummaryFromRegistry(registry))
if done:
return "Deactivated: " + ", ".join(done)
else:
@@ -156,25 +154,22 @@
# Check that none of the registrations are active
for key in todo:
- infos = self._getInfosFromKey(key)
- for info in infos:
- (forInterface, presentationType,
- registry, layer, viewName) = info
- registry = ContextWrapper(registry, self.context)
- assert registry
- if registry.active() is not None:
- errors.append(key)
- continue
- registries.append(registry)
+ registry = self._getRegistryFromKey(key)
+ if registry.active() is not None:
+ errors.append(self._getSummaryFromRegistry(key))
+ continue
+ registries.append(registry)
if errors:
return ("Can't delete active page%s: %s; "
"use the Deactivate button to deactivate" %
(len(errors) != 1 and "s" or "", ", ".join(errors)))
# Now delete the registrations
+ done = []
for registry in registries:
assert registry
assert registry.active() is None # Phase error
+ done.append(self._getSummaryFromRegistry(registry))
for info in registry.info():
conf = info['configuration']
conf.status = Unregistered
@@ -183,7 +178,7 @@
container = getAdapter(parent, IZopeContainer)
del container[name]
- return "Deleted: %s" % ", ".join([key for key in todo])
+ return "Deleted: %s" % ", ".join(done)
def configInfo(self):
"""Do a search, or (by default) return all view pages."""
@@ -213,6 +208,7 @@
registry = ContextWrapper(registry, self.context)
view = getView(registry, "ChangeConfigurations", self.request)
+ # XXX Why are we setting this unique prefix?
prefix = md5.new('%s %s' %
(forInterface, presentationType)).hexdigest()
view.setPrefix(prefix)
@@ -230,6 +226,7 @@
rec = {'forInterface': forInterface,
'presentationType': presentationType,
'shortType': shortType,
+ 'summary': self._getSummaryFromRegistry(registry),
'view': view,
'viewName': viewName,
'layer': layer,
@@ -254,3 +251,17 @@
super(PageConfigurationView, self).update()
if "UPDATE_SUBMIT" in self.request:
self.context.validate()
+
+class ConfigureView(_SharedBase):
+
+ def update(self):
+ key = self.request['key']
+ registry = self._getRegistryFromKey(key)
+ form = getView(registry, "ChangeConfigurations", self.request)
+ form.update()
+ return form
+
+ def summary(self):
+ key = self.request['key']
+ registry = self._getRegistryFromKey(key)
+ return self._getSummaryFromRegistry(registry)
=== Zope3/src/zope/app/browser/services/view.zcml 1.1 => 1.2 ===
--- Zope3/src/zope/app/browser/services/view.zcml:1.1 Wed Apr 30 18:06:31 2003
+++ Zope3/src/zope/app/browser/services/view.zcml Thu May 1 11:51:24 2003
@@ -3,13 +3,13 @@
<!-- View service -->
<page
- for = "zope.component.interfaces.IViewService"
- name = "index.html"
- template = "views.pt"
- permission="zope.ManageServices"
- class="zope.app.browser.services.view.ViewServiceView"
- menu="zmi_views" title="Views"
- />
+ for="zope.component.interfaces.IViewService"
+ name="index.html"
+ template="views.pt"
+ permission="zope.ManageServices"
+ class="zope.app.browser.services.view.ViewServiceView"
+ menu="zmi_views" title="Views"
+ />
<menuItem
for="zope.app.interfaces.container.IAdding"
@@ -19,6 +19,14 @@
/>
<!-- View pages -->
+
+ <page
+ for="zope.component.interfaces.IViewService"
+ name="configureView.html"
+ template="configureView.pt"
+ class=".view.ConfigureView"
+ permission="zope.ManageServices"
+ />
<editform
schema="zope.app.interfaces.services.view.IPageConfiguration"
=== Zope3/src/zope/app/browser/services/views.pt 1.2 => 1.3 ===
--- Zope3/src/zope/app/browser/services/views.pt:1.2 Thu May 1 10:46:26 2003
+++ Zope3/src/zope/app/browser/services/views.pt Thu May 1 11:51:24 2003
@@ -25,20 +25,13 @@
</td>
<td>
<a tal:condition="config/url" tal:attributes="href config/url">
- <span tal:content="config/viewName" /> for
- <span tal:content="config/forInterface" />
+ <span tal:replace="config/summary" />
</a>
- <span tal:condition="not:config/url">
- <span tal:content="config/viewName" /> for
- <span tal:content="config/forInterface" />
- </span>
- <br>
- layer=<span tal:content="config/layer" />,
- type=<span tal:content="config/shortType" />
- <!--
+ <span tal:condition="not:config/url" tal:replace="config/summary" />
+ </td>
+ <td>
<a href="." tal:attributes="href config/configurl">
(change registration)</a>
- -->
</td>
</tr>
</tbody>
@@ -46,19 +39,24 @@
<input type="submit" name="Activate" value="Activate" />
<input type="submit" name="Deactivate" value="Deactivate" />
+
<input type="submit" name="Delete" value="Delete" />
+
<input type="submit" name="Refresh" value="Refresh" />
</form>
<p><a href="../RegistrationManager/@@+/PageConfiguration=">
-Add a page to this view service</a></p>
+Add a page to this views service</a></p>
<h3>Search filter:</h3>
<form action="." method="GET">
<div class="row" tal:content="structure view/forInterface/row" />
+ <!-- presentationType search is not useful yet since we can
+ so far only register "pages", which are a browser-only concept.
<div class="row" tal:content="structure view/presentationType/row" />
+ -->
<div class="row">
<div class="controls">
<input type="submit" value="Refresh">