Author: jmorliaguet
Date: Wed May  3 17:41:53 2006
New Revision: 3032

Modified:
   cpsskins/branches/paris-sprint-2006/ui/manager/configure.zcml
   cpsskins/branches/paris-sprint-2006/ui/manager/themes_manager.pt
   cpsskins/branches/paris-sprint-2006/ui/manager/views.py
Log:

- added a button to enable/disable themes (i.e. register/unregister the 
  theme management folder utility)

  the current ZMI registration does not work:
  (http://www.zope.org/Collectors/Zope3-dev/597)




Modified: cpsskins/branches/paris-sprint-2006/ui/manager/configure.zcml
==============================================================================
--- cpsskins/branches/paris-sprint-2006/ui/manager/configure.zcml       
(original)
+++ cpsskins/branches/paris-sprint-2006/ui/manager/configure.zcml       Wed May 
 3 17:41:53 2006
@@ -18,6 +18,15 @@
       class=".ThemeManagerView">
 
       <page
+          name="enableThemes.html"
+          attribute="enableThemes"
+      />
+
+      <page
+          name="disableThemes.html"
+          attribute="disableThemes"
+      />
+      <page
           name="addTheme.html"
           attribute="addTheme"
       />

Modified: cpsskins/branches/paris-sprint-2006/ui/manager/themes_manager.pt
==============================================================================
--- cpsskins/branches/paris-sprint-2006/ui/manager/themes_manager.pt    
(original)
+++ cpsskins/branches/paris-sprint-2006/ui/manager/themes_manager.pt    Wed May 
 3 17:41:53 2006
@@ -1,6 +1,24 @@
 <html metal:use-macro="context/@@standard_macros/view">
   <body>
-    <div metal:fill-slot="body">
+    <div metal:fill-slot="body"
+         tal:define="enabled view/isEnabled">
+
+      <h4>Registration</h4>
+      <form tal:condition="not:enabled"
+            action="./@@enableThemes.html" method="post">
+        <p>
+          <strong style="color:red">Themes are currently disabled.</strong>
+          <button type="submit">Enable themes</button>
+        </p>
+      </form>
+
+      <form tal:condition="enabled"
+            action="./@@disableThemes.html" method="post">
+        <p>
+          <button type="submit">Disable themes</button>
+        </p>
+      </form>
+
       <h4>Themes</h4>
       <tal:block define="themes view/listThemeInfo">
         <ul>
@@ -13,7 +31,6 @@
         </ul>
         <p tal:condition="not:themes">No themes</p>
       </tal:block>
-
       <form action="./@@addTheme.html" method="post">
          <p>
            <button type="submit">Add a theme</button>

Modified: cpsskins/branches/paris-sprint-2006/ui/manager/views.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/ui/manager/views.py     (original)
+++ cpsskins/branches/paris-sprint-2006/ui/manager/views.py     Wed May  3 
17:41:53 2006
@@ -18,11 +18,15 @@
 __docformat__ = "reStructuredText"
 
 from zope.app import zapi
+from zope.component import getSiteManager
 from zope.interface import implements, Interface
+from zope.security.proxy import removeSecurityProxy
+from zope.traversing.api import getParent
 
 from cpsskins.elements.theme import Theme
 from cpsskins.ui.authoring.views import IAuthoring
 from cpsskins.utils import getThemeManager, addThemeSkeleton
+from cpsskins.thememanager import IThemeManagementFolder
 
 class IThemeManagerView(Interface):
 
@@ -34,6 +38,12 @@
         (id, title, url)
         """
 
+    def enableThemes():
+        """Enable themes."""
+
+    def disableThemes():
+        """Disable themes."""
+
 class ThemeManagerView:
     """Themes manager view.
     """
@@ -45,6 +55,30 @@
 
         self.tmutil = getThemeManager(context)
 
+    def _getSiteManager(self):
+        sm = getSiteManager(self.context)
+        if sm == self.context:
+            sm = getSiteManager(getParent(self.context))
+        return sm
+
+    def isEnabled(self):
+        sm = self._getSiteManager()
+        for r in sm.registeredUtilities():
+            if r.component == self.context:
+                return True
+        return False
+
+    def enableThemes(self):
+        sm = self._getSiteManager()
+        sm.registerUtility(removeSecurityProxy(self.context),
+                           IThemeManagementFolder)
+        self.request.response.redirect('@@themes-manager.html')
+
+    def disableThemes(self):
+        sm = self._getSiteManager()
+        sm.unregisterUtility(self.context, IThemeManagementFolder)
+        self.request.response.redirect('@@themes-manager.html')
+
     def getThemes(self):
         return self.tmutil.getThemes()
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to