Author: jmorliaguet
Date: Fri Jun 30 21:53:52 2006
New Revision: 3578

Modified:
   cpsskins/branches/paris-sprint-2006/standard/negotiation/page.py
   cpsskins/branches/paris-sprint-2006/standard/negotiation/perspective.py
   cpsskins/branches/paris-sprint-2006/utils.py

Log:

- added a guessPath function to guess the relative path + the method name from
  the context and the request



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    Fri Jun 
30 21:53:52 2006
@@ -19,8 +19,6 @@
 
 from zope.component import queryUtility
 from zope.interface import implements
-from zope.traversing.api import getPath
-from zope.traversing.interfaces import IPhysicallyLocatable
 
 from cpsskins.browser.negotiation.scheme import NegotiationScheme
 from cpsskins.elements.interfaces import IThemePage
@@ -31,6 +29,7 @@
 from cpsskins.standard.negotiation import IContextNegotiationScheme
 from cpsskins.standard.negotiation import ILocationNegotiationScheme
 from cpsskins.standard.negotiation import ICookieLocationNegotiationScheme
+from cpsskins.utils import guessPath
 
 class QueryParameter(NegotiationScheme):
     """Look for a page whose name is passed as a URL query parameter:
@@ -89,10 +88,7 @@
     implements(ILocationNegotiationScheme)
 
     def __call__(self):
-        context = self.context
-        nearest_site = IPhysicallyLocatable(context).getNearestSite()
-        path_info = self.request['PATH_INFO']
-        path = path_info[len(getPath(nearest_site)):]
+        path = guessPath(self.context, self.request)
         location = self.manager.getLocation(path, root=u'pages')
         if location is not None:
             page_name = location()

Modified: 
cpsskins/branches/paris-sprint-2006/standard/negotiation/perspective.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/standard/negotiation/perspective.py     
(original)
+++ cpsskins/branches/paris-sprint-2006/standard/negotiation/perspective.py     
Fri Jun 30 21:53:52 2006
@@ -26,6 +26,7 @@
 from cpsskins.standard.negotiation import ISessionNegotiationScheme
 from cpsskins.standard.negotiation import ILocationNegotiationScheme
 from cpsskins.standard.negotiation import ICookieLocationNegotiationScheme
+from cpsskins.utils import guessPath
 
 class Location(NegotiationScheme):
     """Look for a perspective among locations. The path is obtained from
@@ -34,9 +35,7 @@
     implements(ILocationNegotiationScheme)
 
     def __call__(self):
-        context = self.context
-        nearest_site = IPhysicallyLocatable(context).getNearestSite()
-        path = getPath(context)[len(getPath(nearest_site)):]
+        path = guessPath(self.context, self.request)
         location = self.manager.getLocation(path, root=u'perspectives')
         if location is not None:
             return location()

Modified: cpsskins/branches/paris-sprint-2006/utils.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/utils.py        (original)
+++ cpsskins/branches/paris-sprint-2006/utils.py        Fri Jun 30 21:53:52 2006
@@ -22,7 +22,8 @@
 from zope.component import getSiteManager, getGlobalSiteManager
 from zope.location.pickling import locationCopy
 from zope.security.proxy import removeSecurityProxy
-from zope.traversing.api import getParent
+from zope.traversing.api import getParent, getPath
+from zope.traversing.interfaces import IPhysicallyLocatable
 
 startTag = re.compile('<.*?>')
 classAttr = re.compile(' class="(.*?)"')
@@ -120,6 +121,15 @@
         res.append(part)
     return u''.join(res)
 
+def guessPath(context, request):
+    path = getPath(context) + u'/'
+    uri = request['REQUEST_URI']
+    pos = uri.find(path)
+    if pos > 0:
+        path = uri[pos:]
+    nearest_site = IPhysicallyLocatable(context).getNearestSite()
+    return path[len(getPath(nearest_site)):]
+
 def insertCSSClass(markup, css_class):
     """Insert a CSS class in the first tag of some HTML markup.
     """
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to