[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services/registration - registration.pt:1.1 __init__.py:1.11 configure.zcml:1.7

Fred L. Drake, Jr. fred at zope.com
Wed Sep 24 16:43:38 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/browser/services/registration
In directory cvs.zope.org:/tmp/cvs-serv8466/src/zope/app/browser/services/registration

Modified Files:
	__init__.py configure.zcml 
Added Files:
	registration.pt 
Log Message:
Added a new view to make it easier to support registration of objects
 that have at most one registration.


=== Added File Zope3/src/zope/app/browser/services/registration/registration.pt ===
<html metal:use-macro="context/@@standard_macros/page">
<body>
<div metal:fill-slot="body">

<form tal:attributes="action request/URL" method="POST"
      tal:define="ignored view/update">

  <div tal:condition="view/registered">
    <div tal:define="registration view/registration">
      <p i18n:translate="">This object is registered as:</p>
      <span tal:content="registration/usageSummary"
            class="usageSummary" />
      <br />
      <span tal:content="registration/implementationSummary"
            class="implementationSummary" />
      <br />
      <a tal:attributes="href registration/@@absolute_url"
         i18n:translate="">(modify)</a>

      <tal:block condition="view/active">
        <p i18n:translate="">This object is currently active.</p>
        <input type="submit" value="Deactivate" name="deactivate" />
      </tal:block>
      <tal:block condition="not:view/active">
        <p i18n:translate="">This object is currently inactive.</p>
        <input type="submit" value="Activate" name="activate" />
      </tal:block>
    </div>

    <hr />
    <a href="registrations.html" i18n:translate="">
      Advanced Options
    </a>

  </div>

  <div tal:condition="not:view/registered">
    <p i18n:translate="">This object is not currently active.</p>

    <p i18n:translate="">
      This object won't actually be used unless it is registered to
      perform a specific function and is activated.
    </p>

    <input type="submit" value="Register" name="activate" />
  </div>

</form>

</div>
</body>
</html>


=== Zope3/src/zope/app/browser/services/registration/__init__.py 1.10 => 1.11 ===
--- Zope3/src/zope/app/browser/services/registration/__init__.py:1.10	Sun Sep 21 13:30:57 2003
+++ Zope3/src/zope/app/browser/services/registration/__init__.py	Wed Sep 24 16:43:07 2003
@@ -22,15 +22,16 @@
 from zope.app.interfaces.browser.form import IBrowserWidget
 from zope.app.interfaces.container import INameChooser
 
+from zope.app.interfaces.services.registration import IComponentRegistration
 from zope.app.interfaces.services.registration import IRegistered
 from zope.app.interfaces.services.registration import UnregisteredStatus
-from zope.app.interfaces.services.registration import IComponentRegistration
+from zope.app.interfaces.services.registration import RegisteredStatus
 from zope.app.interfaces.services.registration import ActiveStatus
 from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
 from zope.app.traversing import getName, traverse
 from zope.component import getView, getServiceManager, getAdapter
 from zope.proxy import removeAllProxies
-from zope.publisher.browser import BrowserView
+from zope.app.publisher.browser import BrowserView
 from zope.interface import implements
 
 
@@ -76,6 +77,41 @@
             url = None
         item_dict['url'] = url
         return item_dict
+
+
+class RegistrationView(BrowserView):
+
+    def __init__(self, context, request):
+        super(RegistrationView, self).__init__(context, request)
+        useconfig = getAdapter(self.context, IRegistered)
+        self.registrations = useconfig.registrations()
+
+    def update(self):
+        """Make changes based on the form submission."""
+        if len(self.registrations) > 1:
+            self.request.response.redirect("registrations.html")
+            return
+        if "deactivate" in self.request:
+            self.registrations[0].status = RegisteredStatus
+        elif "activate" in self.request:
+            if not self.registrations:
+                # create a registration:
+                self.request.response.redirect("addRegistration.html")
+                return
+            self.registrations[0].status = ActiveStatus
+
+    def active(self):
+        return self.registrations[0].status == ActiveStatus
+
+    def registered(self):
+        return bool(self.registrations)
+
+    def registration(self):
+        """Return the first registration.
+
+        If there are no registrations, raises an error.
+        """
+        return self.registrations[0]
 
 
 class NameRegistered:


=== Zope3/src/zope/app/browser/services/registration/configure.zcml 1.6 => 1.7 ===
--- Zope3/src/zope/app/browser/services/registration/configure.zcml:1.6	Tue Sep  2 16:46:24 2003
+++ Zope3/src/zope/app/browser/services/registration/configure.zcml	Wed Sep 24 16:43:07 2003
@@ -96,7 +96,15 @@
       template="registered.pt"
       class=".NameRegistered"
       permission="zope.ManageServices"
-      menu="zmi_views" title="Registrations" 
+      />
+
+  <page
+      for="zope.app.interfaces.services.registration.IRegisterable"
+      name="registration.html"
+      template="registration.pt"
+      class=".RegistrationView"
+      permission="zope.ManageServices"
+      menu="zmi_views" title="Registration"
       />
 
 




More information about the Zope3-Checkins mailing list