[Erp5-report] r18571 - /erp5/trunk/products/ERP5/Document/WebSite.py

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Dec 31 23:29:28 CET 2007


Author: jp
Date: Mon Dec 31 23:29:27 2007
New Revision: 18571

URL: http://svn.erp5.org?rev=18571&view=rev
Log:
First implementation of a generic reverse URL API. It is now possible to find which section a document has been published in, all this without any configuration.

Modified:
    erp5/trunk/products/ERP5/Document/WebSite.py

Modified: erp5/trunk/products/ERP5/Document/WebSite.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/WebSite.py?rev=18571&r1=18570&r2=18571&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/WebSite.py (original)
+++ erp5/trunk/products/ERP5/Document/WebSite.py Mon Dec 31 23:29:27 2007
@@ -30,6 +30,7 @@
 
 from Products.ERP5.Document.WebSection import WebSection, WEBSECTION_KEY
 from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface, Cache
+from Products.ERP5Type.Cache import CachingMethod
 
 from Globals import get_request
 from Persistence import Persistent
@@ -148,7 +149,7 @@
         BeforeTraverse.registerBeforeTraverse(item, WebSiteTraversalHook(), handle)
       WebSection.manage_afterAdd(self, item, container)
 
-    # Experimental methods 
+    security.declareProtected(Permissions.AccessContentsInformation, 'getPermanentURLList')
     def getPermanentURLList(self, document):
       """
         Return a list of URLs which exist in the site for
@@ -158,4 +159,48 @@
         all documents in each of them to build a reverse
         mapping of getPermanentURL
       """
-      pass
+      return map(lambda x:x.getPermanentURL(document), self.getWebSectionValueList())
+
+    security.declareProtected(Permissions.AccessContentsInformation, 'getWebSectionValueList')
+    def getWebSectionValueList(self, document):
+      """
+        Returns a list of sections which a given document is
+        part of.
+
+        This could be implemented either by testing all sections
+        and building a cache or by using the predicate API
+        to find which sections apply.
+      """
+      def getWebSectionUidList(section):
+        result = [section.getUid()]
+        for o in section.contentValues(portal_type='Web Section'):
+          result.extend(getWebSectionUidList(o))
+        return result
+
+      _getWebSectionUidList = CachingMethod(getWebSectionUidList,
+                         id='WebSite._getWebSectionUidList',
+                         cache_factory='erp5_content_medium')
+
+      section_list = self.portal_domains.searchPredicateList(document, 
+                        portal_type='Web Section',
+                        uid=_getWebSectionUidList(self))
+
+      section_dict = {}
+
+      for section in section_list:
+        section_dict[section.getPhysicalPath()] = section
+
+      # Eliminate path
+      for section in section_list:
+        path = section.getPhysicalPath()
+        for i in range(0, len(path)-1):
+          sub_path = path[0:i]
+          if section_dict.has_key(sub_path):
+            del section_dict[sub_path]
+
+      section_list = section_dict.values()
+
+      # Sort by Index
+      section_list.sort(lambda x,y: cmp(x.getIntIndex(), y.getIntIndex()))
+
+      return section_list




More information about the Erp5-report mailing list