[Erp5-report] r34390 luke - /erp5/trunk/products/ERP5Form/Tool/SelectionTool.py

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Apr 8 15:47:57 CEST 2010


Author: luke
Date: Thu Apr  8 15:47:54 2010
New Revision: 34390

URL: http://svn.erp5.org?rev=34390&view=rev
Log:
 - be more intelligent while navigating between objects and do not display non existing form
In case if in list there are document A and B, and A is viewed by used using
form Q, which is not available on B, it is better to show B with default view
instead of presenting unrelated and not existing form.

Modified:
    erp5/trunk/products/ERP5Form/Tool/SelectionTool.py

Modified: erp5/trunk/products/ERP5Form/Tool/SelectionTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Form/Tool/SelectionTool.py?rev=34390&r1=34389&r2=34390&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Form/Tool/SelectionTool.py [utf8] (original)
+++ erp5/trunk/products/ERP5Form/Tool/SelectionTool.py [utf8] Thu Apr  8 15:47:54 2010
@@ -588,6 +588,19 @@
         return getattr(aq_base(selection), 'stats', default_stats)
       return default_stats
 
+    def _getExistingFormId(self, document, form_id):
+      portal = document.getPortalObject()
+      for url in [q['url'] for q in portal.portal_actions\
+          .listFilteredActionsFor(document).get('object_view', [])]:
+        # XXX-Luke: As this is not possible to do form_id -> action_id the
+        # only way to know if form_id is implemented by action of document
+        # is to use string matching.
+        # Current matching is not perfect - if action url is defined like:
+        #     bla/bla/[form_id]?q
+        # it will not match. re hacker will be able to improve
+        if url.endswith(form_id):
+          return form_id
+      return 'view'
 
     security.declareProtected(ERP5Permissions.View, 'viewFirst')
     def viewFirst(self, selection_index='', selection_name='', form_id='view', REQUEST=None):
@@ -603,6 +616,7 @@
         if len(selection_list):
           o = selection_list[0]
           url = o.absolute_url()
+          form_id = self._getExistingFormId(o.getObject(), form_id)
         else:
           url = REQUEST.getURL()
       else:
@@ -625,6 +639,7 @@
         if len(selection_list):
           o = selection_list[-1]
           url = o.absolute_url()
+          form_id = self._getExistingFormId(o.getObject(), form_id)
         else:
           url = REQUEST.getURL()
       else:
@@ -647,6 +662,7 @@
         if len(selection_list):
           o = selection_list[(int(selection_index) + 1) % len(selection_list)]
           url = o.absolute_url()
+          form_id = self._getExistingFormId(o.getObject(), form_id)
         else:
           url = REQUEST.getURL()
       else:
@@ -669,6 +685,7 @@
         if len(selection_list):
           o = selection_list[(int(selection_index) - 1) % len(selection_list)]
           url = o.absolute_url()
+          form_id = self._getExistingFormId(o.getObject(), form_id)
         else:
           url = REQUEST.getURL()
       else:




More information about the Erp5-report mailing list