Author: jmorliaguet
Date: Sun Jun 18 23:50:15 2006
New Revision: 3457

Removed:
   cpsskins/branches/paris-sprint-2006/standard/negotiation/theme.py
   cpsskins/branches/paris-sprint-2006/standard/negotiation/theme.zcml
Modified:
   cpsskins/branches/paris-sprint-2006/browser/negotiation/README.txt
   cpsskins/branches/paris-sprint-2006/browser/negotiation/views.py
   cpsskins/branches/paris-sprint-2006/elements/interfaces.py
   cpsskins/branches/paris-sprint-2006/elements/themepage.py
   cpsskins/branches/paris-sprint-2006/locations/interfaces.py
   cpsskins/branches/paris-sprint-2006/standard/negotiation/configure.zcml
   cpsskins/branches/paris-sprint-2006/standard/negotiation/page.py
   cpsskins/branches/paris-sprint-2006/standard/negotiation/page.zcml
   cpsskins/branches/paris-sprint-2006/thememanager.py
   cpsskins/branches/paris-sprint-2006/ui/screens/common/configure.zcml
   cpsskins/branches/paris-sprint-2006/ui/screens/common/page_tabs.pt
   cpsskins/branches/paris-sprint-2006/ui/screens/common/theme_tabs.pt
   cpsskins/branches/paris-sprint-2006/ui/screens/common/views.py
   cpsskins/branches/paris-sprint-2006/utils.py

Log:

- simplifications: the page negotiation is done only on a combination of a
  theme and page name separated by a ':'



Modified: cpsskins/branches/paris-sprint-2006/browser/negotiation/README.txt
==============================================================================
--- cpsskins/branches/paris-sprint-2006/browser/negotiation/README.txt  
(original)
+++ cpsskins/branches/paris-sprint-2006/browser/negotiation/README.txt  Sun Jun 
18 23:50:15 2006
@@ -79,40 +79,34 @@
     >>> negotiation = getMultiAdapter((root, request), INegotiation,
     ...                               name='negotiation')
 
-Themes
-------
+Pages
+-----
 
-To obtain the theme as a result of the negotiation the 'getTheme' method is
-used.
+To obtain the page as a result of the negotiation the 'getPage' method is used.
 
 If nothing is specified, the default theme is returned:
 
-    >>> theme = negotiation.getTheme()
-    >>> theme
-    Theme('Theme 1')
+    >>> page = negotiation.getPage()
+    >>> page.theme(), page
 
-    >>> manager.isDefault(theme)
-    True
 
+The page's name can be specified in the URL, by writing
+    ...?page=Theme-2:ThemePage
 
-The theme's name can be specified in the URL, by writing ...?theme=Theme-2
+    >>> request.form[u'page'] = u'Theme-2:ThemePage'
+    >>> page = negotiation.getPage()
+    >>> page.theme(), page
 
-    >>> request.form[u'theme'] = u'Theme-2'
-    >>> theme = negotiation.getTheme()
-    >>> theme
-    Theme('Theme 2')
-
-    >>> del request.form[u'theme']
+    >>> del request.form[u'page']
 
 
 The theme's name can also be specified in a cookie:
 
-    >>> request.response.setCookie('cpsskins_theme', u'Theme-3')
-    >>> theme = negotiation.getTheme()
-
-    TODO
+    >>> request.response.setCookie('cpsskins_page', u'Theme-3:ThemePage')
+    >>> page = negotiation.getPage()
+    >>> page.theme(), page
 
-    >>> request.response.expireCookie('cpsskins_theme')
+    >>> request.response.expireCookie('cpsskins_page')
 
 
 

Modified: cpsskins/branches/paris-sprint-2006/browser/negotiation/views.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/browser/negotiation/views.py    
(original)
+++ cpsskins/branches/paris-sprint-2006/browser/negotiation/views.py    Sun Jun 
18 23:50:15 2006
@@ -49,12 +49,6 @@
     # Themes and pages
     ###################################################################
 
-    def getTheme(self):
-        """Return the effective theme
-        (the one that will be effectively displayed)
-        """
-        return self.negotiate('theme')
-
     def getPage(self):
         """Return the effective page
         (the one that will be effectively displayed)

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  Sun Jun 18 
23:50:15 2006
@@ -185,6 +185,9 @@
         utility.)
         """
 
+    def theme():
+        """Return the theme in which the page is located."""
+
 class ITheme(ICanvas, IInnerNode, IComponents):
     """A 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   Sun Jun 18 
23:50:15 2006
@@ -48,12 +48,16 @@
         return tmutil.isDefault(self)
 
     def getPageName(self):
-        theme = getParent(self)
-        for k, v in getUtilitiesFor(IThemePage, theme):
+        for k, v in getUtilitiesFor(IThemePage, self.theme):
             if v == self:
                 return k
         return None
 
+    def getTheme(self):
+        return getParent(self)
+
     name = property(getPageName)
 
+    theme = property(getTheme)
+
 ThemePageFactory = Factory(ThemePage)

Modified: cpsskins/branches/paris-sprint-2006/locations/interfaces.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/locations/interfaces.py (original)
+++ cpsskins/branches/paris-sprint-2006/locations/interfaces.py Sun Jun 18 
23:50:15 2006
@@ -39,3 +39,8 @@
         title=u"Scope",
         )
 
+    def __call__():
+        """return the location's data"""
+
+    def __str__():
+        """Return the location's path"""

Modified: 
cpsskins/branches/paris-sprint-2006/standard/negotiation/configure.zcml
==============================================================================
--- cpsskins/branches/paris-sprint-2006/standard/negotiation/configure.zcml     
(original)
+++ cpsskins/branches/paris-sprint-2006/standard/negotiation/configure.zcml     
Sun Jun 18 23:50:15 2006
@@ -1,11 +1,6 @@
 <configure
     xmlns="http://namespaces.zope.org/zope";>
 
-  <!-- theme negotiation chain -->
-
-  <include file="theme.zcml" />
-
-
   <!-- page negotiation chain -->
 
   <include file="page.zcml" />

Modified: cpsskins/branches/paris-sprint-2006/standard/negotiation/page.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/standard/negotiation/page.py    
(original)
+++ cpsskins/branches/paris-sprint-2006/standard/negotiation/page.py    Sun Jun 
18 23:50:15 2006
@@ -32,7 +32,7 @@
 
 class QueryParameter(NegotiationScheme):
     """Look for a page whose name is passed as a URL query parameter:
-    ?theme=name
+    ?page=theme_name:page_name
     """
     implements(IQueryParameterNegotiationScheme)
 
@@ -87,5 +87,8 @@
     def __call__(self):
         context = self.context
         tmutil = getThemeManager(context)
-        return tmutil.getLocation(context, root=u'pages')
+        location = tmutil.getLocation(context, root=u'pages')
+        if location is not None:
+            page_name = location()
+            return tmutil.getPageByName(page_name)
 

Modified: cpsskins/branches/paris-sprint-2006/standard/negotiation/page.zcml
==============================================================================
--- cpsskins/branches/paris-sprint-2006/standard/negotiation/page.zcml  
(original)
+++ cpsskins/branches/paris-sprint-2006/standard/negotiation/page.zcml  Sun Jun 
18 23:50:15 2006
@@ -9,13 +9,13 @@
     />
 
     <scheme
-        class=".page.Cookie"
-        interface=".interfaces.ICookieNegotiationScheme"
+        class=".page.Location"
+        interface=".interfaces.ILocationNegotiationScheme"
     />
 
     <scheme
-        class=".page.Location"
-        interface=".interfaces.ILocationNegotiationScheme"
+        class=".page.Cookie"
+        interface=".interfaces.ICookieNegotiationScheme"
     />
 
     <scheme

Modified: cpsskins/branches/paris-sprint-2006/thememanager.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/thememanager.py (original)
+++ cpsskins/branches/paris-sprint-2006/thememanager.py Sun Jun 18 23:50:15 2006
@@ -281,8 +281,12 @@
         return None
 
     def getPageByName(self, name=u''):
-        for k, v in self.getUtilitiesFor(IThemePage):
-            if k == name:
+        theme_name, page_name = name.split(u':')
+        theme = self.getThemeByName(theme_name)
+        if theme is None:
+            return None
+        for k, v in theme.getUtilitiesFor(IThemePage):
+            if k == page_name:
                 return v
         return None
 

Modified: cpsskins/branches/paris-sprint-2006/ui/screens/common/configure.zcml
==============================================================================
--- cpsskins/branches/paris-sprint-2006/ui/screens/common/configure.zcml        
(original)
+++ cpsskins/branches/paris-sprint-2006/ui/screens/common/configure.zcml        
Sun Jun 18 23:50:15 2006
@@ -184,8 +184,8 @@
       />
 
       <page
-        name="setWorkTheme"
-        attribute="setWorkTheme"
+        name="setWorkPage"
+        attribute="setWorkPage"
       />
 
       <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  Sun Jun 
18 23:50:15 2006
@@ -1,14 +1,14 @@
 <ul class="tabs pageTabs"
   tal:define="tmutil context/@@getThemeManager;
               negotiation nocall:context/@@negotiation;
-              effective_theme negotiation/getTheme;
               effective_page negotiation/getPage;
-              pages effective_theme/getPages">
+              theme effective_page/theme;
+              pages theme/getPages">
   <tal:block repeat="page pages">
     <li tal:define="selected python: page == effective_page"
         tal:attributes="class python: selected and 'selected' or None">
       <a tal:content="python: page.title or 'No title'"
-         tal:attributes="href string:@@setWorkPage?name=${page/name}" /></li>
+         tal:attributes="href 
string:@@setWorkPage?name=${theme/name}:${page/name}" /></li>
   </tal:block>
   <li><a href="./@@addPage">+</a></li>
 </ul>

Modified: cpsskins/branches/paris-sprint-2006/ui/screens/common/theme_tabs.pt
==============================================================================
--- cpsskins/branches/paris-sprint-2006/ui/screens/common/theme_tabs.pt 
(original)
+++ cpsskins/branches/paris-sprint-2006/ui/screens/common/theme_tabs.pt Sun Jun 
18 23:50:15 2006
@@ -1,7 +1,8 @@
 <table class="topTabs" cellpadding="0" cellspacing="0" border="0" summary=""
   tal:define="tmutil context/@@getThemeManager;
               negotiation nocall:context/@@negotiation;
-              effective_theme negotiation/getTheme;
+              effective_page negotiation/getPage;
+              effective_theme effective_page/theme;
               themes tmutil/getThemes">
   <tr>
     <tal:block repeat="theme themes">
@@ -11,7 +12,7 @@
         </td>
         <td tal:attributes="class python: selected and 'tabselected' or 'tab'">
           <a tal:content="python: theme.title or 'No title'"
-             tal:attributes="href string:@@setWorkTheme?name=${theme/name}" />
+             tal:attributes="href string:@@setWorkPage?name=${theme/name}" />
           <img alt="" width="12" height="12" src="++resource++edit-12.png" />
         </td>
         <td tal:attributes="class python: selected and 'rtabselected' or 
'rtab'">

Modified: cpsskins/branches/paris-sprint-2006/ui/screens/common/views.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/ui/screens/common/views.py      
(original)
+++ cpsskins/branches/paris-sprint-2006/ui/screens/common/views.py      Sun Jun 
18 23:50:15 2006
@@ -127,8 +127,7 @@
         """
         negotiation = getMultiAdapter((self.context, self.request),
                                        INegotiation, 'negotiation')
-        theme_obj = negotiation.getTheme()
-        page = theme_obj.getDefaultPage()
+        page = negotiation.getPage()
         viewer = getMultiAdapter((page, self.request), IViewer)
         return viewer(engine=engine)
 
@@ -232,16 +231,13 @@
             session_info['perspective'] = perspective
         self._redirect()
 
-    def setWorkTheme(self, name=u''):
-        """Set the work theme.
-        """
-        response = self.request.response
-        response.setCookie('cpsskins_theme', name)
-        response.redirect('.')
-
     def setWorkPage(self, name=u''):
         """Set the work page.
         """
+        # only the theme is specified, set the default page
+        if u':' not in name:
+            theme = self.tmutil.getThemeByName(name)
+            name = u'%s:%s' % (name, theme.getDefaultPage().name)
         response = self.request.response
         response.setCookie('cpsskins_page', name)
         response.redirect('.')
@@ -262,7 +258,7 @@
         response = self.request.response
         negotiation = getMultiAdapter((self.context, self.request),
                                       INegotiation, 'negotiation')
-        theme = negotiation.getTheme()
+        theme, page = negotiation.getPage()
         page = ThemePage()
         self.tmutil.addPage(theme, page)
         response.redirect('.')

Modified: cpsskins/branches/paris-sprint-2006/utils.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/utils.py        (original)
+++ cpsskins/branches/paris-sprint-2006/utils.py        Sun Jun 18 23:50:15 2006
@@ -26,6 +26,8 @@
 from zope.security.proxy import removeSecurityProxy
 from zope.traversing.api import getParent
 
+from cpsskins.locations import Location
+
 startTag = re.compile('<.*?>')
 classAttr = re.compile(' class="(.*?)"')
 lineBreaks = re.compile('(\n|\r)')
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to