Author: jmorliaguet Date: Thu Jun 29 16:44:00 2006 New Revision: 3558 Added: cpsskins/branches/paris-sprint-2006/ftests/test_themestructure.py (contents, props changed) Modified: cpsskins/branches/paris-sprint-2006/controllers/themepage.py cpsskins/branches/paris-sprint-2006/doc/theme-structure.txt cpsskins/branches/paris-sprint-2006/elements/element.py cpsskins/branches/paris-sprint-2006/elements/interfaces.py cpsskins/branches/paris-sprint-2006/elements/theme.py cpsskins/branches/paris-sprint-2006/elements/themepage.py cpsskins/branches/paris-sprint-2006/thememanager.py cpsskins/branches/paris-sprint-2006/ui/screens/common/page_tabs.pt
Log: - added some tests on default themes / pages Modified: cpsskins/branches/paris-sprint-2006/controllers/themepage.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/controllers/themepage.py (original) +++ cpsskins/branches/paris-sprint-2006/controllers/themepage.py Thu Jun 29 16:44:00 2006 @@ -18,7 +18,7 @@ __docformat__ = "reStructuredText" from zope.interface import implements -from zope.traversing.api import getName, getParent +from zope.traversing.api import getName from cpsskins.controllers import Controller from cpsskins.controllers.interfaces import IController @@ -35,12 +35,11 @@ """ element = self.element tmutil = getThemeManager(element) - if tmutil.getDefaultPage() is None: + theme = element.getTheme() + if tmutil.getDefaultPage(theme) is None: tmutil.setAsDefault(element) - theme = getParent(element) theme.registerUtility(element, IThemePage, getName(element)) - IPresentable(element).addPresentation() def removed(self): @@ -49,5 +48,6 @@ element = self.element getThemeManager(element).removeFormats(element) - theme = getParent(element) + theme = element.getTheme() theme.unregisterUtility(element, IThemePage, getName(element)) + Modified: cpsskins/branches/paris-sprint-2006/doc/theme-structure.txt ============================================================================== --- cpsskins/branches/paris-sprint-2006/doc/theme-structure.txt (original) +++ cpsskins/branches/paris-sprint-2006/doc/theme-structure.txt Thu Jun 29 16:44:00 2006 @@ -3,7 +3,9 @@ THEME MANAGEMENT FOLDER ======================= -:: +Themes are located inside a Theme Management Folder. + +The folder structure is:: + themes ( .../++etc++site/defaut/themes ) | @@ -28,5 +30,127 @@ + Presets | + Snapshots + | + + Locations + +Setup: + + >>> root = getRootFolder() + + >>> from cpsskins.tests.setup import addThemeManager + >>> from cpsskins.tests.setup import makeSite + >>> from cpsskins.utils import addThemeSkeleton + + >>> tmutil = addThemeManager(root, makeSite(root)) + + >>> def inspect(): + ... for theme in tmutil.getThemes(): + ... print '- %s (default: %s)' % (theme.title, + ... tmutil.isDefault(theme)) + ... for page in theme.getPages(): + ... print ' |_ %s (default: %s)' % \ + ... (page.title, tmutil.isDefault(page)) + + +We add a theme skeleton, this creates a default theme with a default page. + + >>> themes = addThemeSkeleton(tmutil) + + >>> inspect() + - Theme (default: True) + |_ Default page (default: True) + + >>> theme1 = tmutil.getDefaultTheme() + >>> theme1 + Theme('Theme') + +we create and add a second theme: + + >>> from cpsskins.elements.theme import Theme + >>> theme2 = Theme(u'Theme 2') + + >>> tmutil.addTheme(theme2) + u'Theme-2' + + >>> inspect() + - Theme (default: True) + |_ Default page (default: True) + - Theme 2 (default: False) + +the default theme is still the first theme: + + >>> tmutil.getDefaultTheme() + Theme('Theme') + + >>> theme1.isDefault(), theme2.isDefault() + (True, False) + +themes have siblings: + + >>> theme2.getSiblings() + [Theme('Theme')] + + >>> theme1.getSiblings() + [Theme('Theme 2')] + +a theme has pages: + + >>> theme1.getPages() + [ThemePage('Default page')] + +we create and add a page to the second theme: + + >>> from cpsskins.elements.themepage import ThemePage + >>> page1 = ThemePage('Page 1') + >>> tmutil.addPage(theme2, page1) + 'ThemePage' + + >>> inspect() + - Theme (default: True) + |_ Default page (default: True) + - Theme 2 (default: False) + |_ Page 1 (default: True) + +we add a second page to the second theme: + + >>> page2 = ThemePage('Page 2') + >>> tmutil.addPage(theme2, page2) + 'ThemePage-2' + + >>> inspect() + - Theme (default: True) + |_ Default page (default: True) + - Theme 2 (default: False) + |_ Page 2 (default: False) + |_ Page 1 (default: True) + +pages have siblings: + + >>> page1.getSiblings() + [ThemePage('Page 2')] + + >>> page2.getSiblings() + [ThemePage('Page 1')] + +we can set the second theme as the default theme: + + >>> tmutil.setAsDefault(theme2) + >>> inspect() + - Theme (default: False) + |_ Default page (default: True) + - Theme 2 (default: True) + |_ Page 2 (default: False) + |_ Page 1 (default: True) + +we can set the second page as the default page: + + >>> tmutil.setAsDefault(page2) + >>> inspect() + - Theme (default: False) + |_ Default page (default: True) + - Theme 2 (default: True) + |_ Page 2 (default: True) + |_ Page 1 (default: False) + Modified: cpsskins/branches/paris-sprint-2006/elements/element.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/elements/element.py (original) +++ cpsskins/branches/paris-sprint-2006/elements/element.py Thu Jun 29 16:44:00 2006 @@ -40,6 +40,9 @@ def __init__(self): super(Node, self)._init__() + def getSiblings(self): + raise NotImplementedError + class InnerNode(OrderedContainer, Node): """An inner node is a node that has children. """ Modified: cpsskins/branches/paris-sprint-2006/elements/interfaces.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/elements/interfaces.py (original) +++ cpsskins/branches/paris-sprint-2006/elements/interfaces.py Thu Jun 29 16:44:00 2006 @@ -37,6 +37,9 @@ class INode(IElement): """A generic tree node""" + def getSiblings(self): + """Return the list of siblings""" + class IInnerNode(INode, IOrderedContainer): """An inner node has children""" Modified: cpsskins/branches/paris-sprint-2006/elements/theme.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/elements/theme.py (original) +++ cpsskins/branches/paris-sprint-2006/elements/theme.py Thu Jun 29 16:44:00 2006 @@ -71,6 +71,9 @@ return k return None + def getSiblings(self): + return [p for p in getThemeManager(self).getThemes() if p is not self] + name = property(getThemeName) ThemeFactory = Factory(Theme) Modified: cpsskins/branches/paris-sprint-2006/elements/themepage.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/elements/themepage.py (original) +++ cpsskins/branches/paris-sprint-2006/elements/themepage.py Thu Jun 29 16:44:00 2006 @@ -56,6 +56,10 @@ def getTheme(self): return getParent(self) + def getSiblings(self): + theme = self.getTheme() + return [p for p in theme.getPages() if p is not self] + name = property(getPageName) theme = property(getTheme) Added: cpsskins/branches/paris-sprint-2006/ftests/test_themestructure.py ============================================================================== --- (empty file) +++ cpsskins/branches/paris-sprint-2006/ftests/test_themestructure.py Thu Jun 29 16:44:00 2006 @@ -0,0 +1,32 @@ +############################################################################## +# +# Copyright (c) 2005-2006 Nuxeo and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# +############################################################################## +"""Theme structure tests + +$Id$ +""" +__docformat__ = "reStructuredText" + +import unittest + +from zope.app.testing.functional import FunctionalDocFileSuite + +from cpsskins.tests.setup import setUp + +def test_suite(): + return unittest.TestSuite(( + FunctionalDocFileSuite('../doc/theme-structure.txt', setUp=setUp), + )) + +if __name__ == '__main__': + unittest.main(defaultTest='test_suite') Modified: cpsskins/branches/paris-sprint-2006/thememanager.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/thememanager.py (original) +++ cpsskins/branches/paris-sprint-2006/thememanager.py Thu Jun 29 16:44:00 2006 @@ -95,6 +95,9 @@ def addPage(theme, page, name): """Add a page.""" + def isDefault(object): + """Return true if the object is used by default.""" + def getThemes(): """Return the list of available themes.""" @@ -113,8 +116,8 @@ def getDefaultTheme(): """Return the default theme.""" - def getDefaultPage(): - """Return the default page.""" + def getDefaultPage(theme): + """Return the default page of a theme.""" def removeFormats(object): """Remove the formats of an element""" @@ -278,6 +281,10 @@ def setAsDefault(self, object=None): relations = self.getRelationStorage() relations.add(MonadicRelation(isDefault, object)) + defaults = [] + for o in object.getSiblings(): + defaults.extend(relations.search(predicate=isDefault, first=o)) + relations.remove(defaults) def getDefaultTheme(self): for theme in self.getThemes(): @@ -285,10 +292,7 @@ return theme return None - def getDefaultPage(self): - theme = self.getDefaultTheme() - if theme is None: - return None + def getDefaultPage(self, theme): for page in theme.getPages(): if page.isDefault(): return page Modified: cpsskins/branches/paris-sprint-2006/ui/screens/common/page_tabs.pt ============================================================================== --- cpsskins/branches/paris-sprint-2006/ui/screens/common/page_tabs.pt (original) +++ cpsskins/branches/paris-sprint-2006/ui/screens/common/page_tabs.pt Thu Jun 29 16:44:00 2006 @@ -11,7 +11,8 @@ <ins class="model" tal:content="page/@@getModelInfo" /> <img tal:attributes="id string:p${page/identifier}" alt="" width="12" height="12" src="++resource++edit-12.png" /> - <a tal:attributes="href string:@@setPage?name=${theme/name}:${page/name}" + <a tal:attributes="href string:@@setPage?name=${theme/name}:${page/name}; + style python: tmutil.isDefault(page) and 'text-decoration: underline' or nothing" tal:content="python: page.title or 'No title'" /></li> </tal:block> <li><a tal:attributes="href string:./@@addPage?theme_name=${theme/name}">+</a></li> -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins