Author: jmorliaguet
Date: Tue Dec  6 13:55:21 2005
New Revision: 1966

Modified:
   cpsskins/branches/jmo-perspectives/browser/manager/views.py
   cpsskins/branches/jmo-perspectives/interfaces.py
   cpsskins/branches/jmo-perspectives/thememanager.py
Log:

- added an 'addTheme' method in the theme manager, that is also used in
  the theme manager view



Modified: cpsskins/branches/jmo-perspectives/browser/manager/views.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/browser/manager/views.py (original)
+++ cpsskins/branches/jmo-perspectives/browser/manager/views.py Tue Dec  6 
13:55:21 2005
@@ -45,8 +45,7 @@
         return getThemeManager()
 
     def getThemes(self):
-        return [item for item in list(self.context.values())
-                if ITheme.providedBy(item)]
+        return self.context.getThemes()
 
     def listThemeInfo(self):
         info = []
@@ -63,17 +62,9 @@
         """Creates a theme skeleton (mostly for demo purposes until some theme
         export / import functionality is available).
         """
-        container = self.context
-        chooser = INameChooser(container)
         theme = Theme()
-        name = chooser.chooseName('', theme)
+        name= self.context.addTheme(theme)
         theme.title = name.replace('-', ' ')
-        container[name] = theme
-
-        # register the theme as a local utility
-        theme_reg = UtilityRegistration(name, ITheme, theme)
-        container.registrationManager.addRegistration(theme_reg)
-        theme_reg.status = ActiveStatus
 
         # Add a page
         theme['page'] = ThemePage('Default page')

Modified: cpsskins/branches/jmo-perspectives/interfaces.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/interfaces.py    (original)
+++ cpsskins/branches/jmo-perspectives/interfaces.py    Tue Dec  6 13:55:21 2005
@@ -51,6 +51,9 @@
     def getElementById(id):
         """Return an element by its unique id. """
 
+    def addTheme(theme):
+        """Add a theme."""
+
     def getThemes():
         """Return the list of available themes."""
 

Modified: cpsskins/branches/jmo-perspectives/thememanager.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/thememanager.py  (original)
+++ cpsskins/branches/jmo-perspectives/thememanager.py  Tue Dec  6 13:55:21 2005
@@ -20,6 +20,7 @@
 from zope.app import zapi
 from zope.app.component.interfaces.registration import ActiveStatus
 from zope.app.component.site import SiteManagementFolder, UtilityRegistration
+from zope.app.container.interfaces import INameChooser
 from zope.app.intid import IntIds
 from zope.app.intid.interfaces import IIntIds
 from zope.app.traversing.api import getParent
@@ -121,18 +122,22 @@
     # Themes and pages
     ###################################################################
 
+    def addTheme(self, theme=None):
+        """Add a theme. Return the theme's name.
+        """
+        if not ITheme.providedBy(theme):
+            raise("Must specify a theme.")
+
+        name = INameChooser(self).chooseName(u'', theme)
+        self[name] = theme
+        # register the theme as a local utility
+        theme_reg = UtilityRegistration(name, ITheme, theme)
+        self.registrationManager.addRegistration(theme_reg)
+        theme_reg.status = ActiveStatus
+        return name
+
     def getThemes(self):
         """Return the list of themes
-
-        >>> from thememanager import ThemeManagement
-        >>> from elements.theme import Theme
-        >>> thememanager = ThemeManagement()
-        >>> thememanager.getThemes() == []
-        True
-        >>> theme = Theme()
-        >>> thememanager.__setitem__('theme1', theme)
-        >>> thememanager.getThemes() == [theme]
-        True
         """
         return [theme for name, theme in getUtilitiesFor(ITheme, self)]
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to