[Erp5-report] r8679 - /erp5/trunk/products/ERP5Form/SelectionTool.py

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Jul 21 20:26:16 CEST 2006


Author: kevin
Date: Fri Jul 21 20:26:12 2006
New Revision: 8679

URL: http://svn.erp5.org?rev=8679&view=rev
Log:
Add two new listbox related method to get the first page and the last page of a multiple-page listbox.
Auto-delete of trailing spaces.

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

Modified: erp5/trunk/products/ERP5Form/SelectionTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Form/SelectionTool.py?rev=8679&r1=8678&r2=8679&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Form/SelectionTool.py (original)
+++ erp5/trunk/products/ERP5Form/SelectionTool.py Fri Jul 21 20:26:12 2006
@@ -26,8 +26,8 @@
 #
 ##############################################################################
 
-"""\
-ERP portal_selection tool.
+"""
+  ERP5 portal_selection tool.
 """
 
 from OFS.Traversable import NotFound
@@ -210,11 +210,11 @@
           return params
       else:
         return params
-    
-    # backward compatibility 
+
+    # backward compatibility
     security.declareProtected(ERP5Permissions.View, 'getSelectionParams')
     getSelectionParams = getSelectionParamsFor
-    
+
     security.declareProtected(ERP5Permissions.View, 'setSelectionParamsFor')
     def setSelectionParamsFor(self, selection_name, params, REQUEST=None):
       """
@@ -504,6 +504,48 @@
 
 
     # ListBox related methods
+
+    security.declareProtected(ERP5Permissions.View, 'firstPage')
+    def firstPage(self, listbox_uid, uids=None, REQUEST=None):
+      """
+        Access the first page of a list
+      """
+      if uids is None: uids = []
+      request = REQUEST
+      #form_id = request.form_id
+      selection_name = request.list_selection_name
+      selection = self.getSelectionFor(selection_name, REQUEST)
+      params = selection.getParams()
+      params['list_start'] = 0
+      selection.edit(params=params)
+      self.uncheckAll(selection_name, listbox_uid)
+      return self.checkAll(selection_name, uids, REQUEST=REQUEST)
+
+    security.declareProtected(ERP5Permissions.View, 'lastPage')
+    def lastPage(self, listbox_uid, uids=None, REQUEST=None):
+      """
+        Access the last page of a list
+      """
+      if uids is None: uids = []
+      request = REQUEST
+      #form_id = request.form_id
+      selection_name = request.list_selection_name
+      selection = self.getSelectionFor(selection_name, REQUEST)
+      params = selection.getParams()
+      # XXX This will not work if the number of lines shown in the listbox is greater
+      #       than the BIG_INT constan. Such a case has low probability but is not
+      #       impossible. If you are in this case, send me a mail ! -- Kev
+      BIG_INT = 10000000
+      last_page_start = BIG_INT
+      total_lines = request.form.get('total_size', BIG_INT)
+      if total_lines != BIG_INT:
+        lines_per_page  = params.get('list_lines', 1)
+        last_page_start = int(total_lines) - (int(total_lines) % int(lines_per_page))
+      params['list_start'] = last_page_start
+      selection.edit(params=params)
+      self.uncheckAll(selection_name, listbox_uid)
+      return self.checkAll(selection_name, uids, REQUEST=REQUEST)
+
     security.declareProtected(ERP5Permissions.View, 'nextPage')
     def nextPage(self, listbox_uid, uids=None, REQUEST=None):
       """
@@ -518,8 +560,7 @@
       lines = params.get('list_lines',0)
       start = params.get('list_start', 0)
       params['list_start'] = int(start) + int(lines)
-      selection.edit(params= params)
-
+      selection.edit(params=params)
       self.uncheckAll(selection_name, listbox_uid)
       return self.checkAll(selection_name, uids, REQUEST=REQUEST)
 
@@ -537,8 +578,7 @@
       lines = params.get('list_lines',0)
       start = params.get('list_start', 0)
       params['list_start'] = max(int(start) - int(lines), 0)
-      selection.edit(params= selection.params)
-
+      selection.edit(params=selection.params)
       self.uncheckAll(selection_name, listbox_uid)
       return self.checkAll(selection_name, uids, REQUEST=REQUEST)
 
@@ -551,21 +591,19 @@
       request = REQUEST
       #form_id = request.form_id
       selection_name = request.list_selection_name
-
       selection = self.getSelectionFor(selection_name, REQUEST=REQUEST)
       if selection is not None:
         params = selection.getParams()
         lines = params.get('list_lines',0)
         start = request.form.get('list_start',0)
-
         params['list_start'] = start
         selection.edit(params= selection.params)
-
       self.uncheckAll(selection_name, listbox_uid)
       return self.checkAll(selection_name, uids, REQUEST=REQUEST, query_string=query_string)
 
 
     # PlanningBox related methods
+
     security.declareProtected(ERP5Permissions.View, 'setZoomLevel')
     def setZoomLevel(self, uids=None, REQUEST=None):
       """
@@ -749,7 +787,7 @@
       return 'FlatListMode'
 
     security.declareProtected(ERP5Permissions.View, 'setListboxDisplayMode')
-    def setListboxDisplayMode(self, REQUEST, listbox_display_mode, 
+    def setListboxDisplayMode(self, REQUEST, listbox_display_mode,
                               selection_name=None, redirect=0,
                               form_id=None, query_string=None):
       """
@@ -763,8 +801,8 @@
       # This need to be cleaned
       # Beware, this fix may break the report system...
       # and we don't have test for this
-      # Possible fix: currently, display mode icon are implemented as 
-      # method. It could be easier to generate them as link (where we 
+      # Possible fix: currently, display mode icon are implemented as
+      # method. It could be easier to generate them as link (where we
       # can define explicitely parameters through the url).
       try:
         list_selection_name = request.list_selection_name
@@ -794,7 +832,7 @@
       else:
         flat_list_mode = 0
         domain_tree_mode = 0
-        report_tree_mode = 0      
+        report_tree_mode = 0
 
       selection.edit(flat_list_mode=flat_list_mode,
                      domain_tree_mode=domain_tree_mode,
@@ -815,7 +853,7 @@
         Set display of the listbox to FlatList mode
       """
       return self.setListboxDisplayMode(
-                       REQUEST=REQUEST, listbox_display_mode='FlatListMode', 
+                       REQUEST=REQUEST, listbox_display_mode='FlatListMode',
                        selection_name=selection_name, redirect=1)
 
     security.declareProtected(ERP5Permissions.View, 'setDomainTreeMode')
@@ -824,7 +862,7 @@
          Set display of the listbox to DomainTree mode
       """
       return self.setListboxDisplayMode(
-                       REQUEST=REQUEST, listbox_display_mode='DomainTreeMode', 
+                       REQUEST=REQUEST, listbox_display_mode='DomainTreeMode',
                        selection_name=selection_name, redirect=1)
 
     security.declareProtected(ERP5Permissions.View, 'setReportTreeMode')
@@ -867,8 +905,8 @@
       if len(value_list) == 0:
         value_list = self.getSelectionSelectedValueList(
                                             selection_name,
-                                            REQUEST=REQUEST, 
-                                            selection_method=selection_method, 
+                                            REQUEST=REQUEST,
+                                            selection_method=selection_method,
                                             context=context)
       return value_list
 
@@ -885,7 +923,7 @@
         We want to be sure that the selection did not change
       """
       # XXX To avoid the difference of the string representations of int and long,
-      # convert each element to a string. 
+      # convert each element to a string.
       object_uid_list = [str(x) for x in object_uid_list]
       object_uid_list.sort()
       new_md5_string = md5.new(str(object_uid_list)).hexdigest()
@@ -1071,10 +1109,10 @@
           # Checked current uid
           kw ={}
           kw[field.get_value('catalog_index')] = field_value
-          self.portal_selections.setSelectionParamsFor(selection_name, 
+          self.portal_selections.setSelectionParamsFor(selection_name,
                                                        kw.copy())
           self.portal_selections.setSelectionCheckedUidsFor(
-                                             selection_name, 
+                                             selection_name,
                                              current_uid_list)
           field_value = str(field_value).splitlines()
           REQUEST.form[field_key] = field_value
@@ -1112,7 +1150,7 @@
         kw['previous_form_id'] = form_id
         kw[field.get_value('catalog_index')] = field_value
         kw['portal_status_message'] = portal_status_message
-        kw['form_pickle'] = form_pickle   
+        kw['form_pickle'] = form_pickle
         kw['form_signature'] = form_signature
 
          # Empty the selection (uid)
@@ -1125,7 +1163,7 @@
 
     def _aq_dynamic(self, name):
       """
-        Generate viewSearchRelatedDocumentDialog0, 
+        Generate viewSearchRelatedDocumentDialog0,
                  viewSearchRelatedDocumentDialog1,... if necessary
       """
       aq_base_name = getattr(aq_base(self), name, None)
@@ -1154,17 +1192,17 @@
               sub_index = None
 
             # generate dynamicaly needed forwarder methods
-            def viewSearchRelatedDocumentDialogWrapper(self, form_id, 
+            def viewSearchRelatedDocumentDialogWrapper(self, form_id,
                                                        REQUEST=None, **kw):
               """
                 viewSearchRelatedDocumentDialog Wrapper
               """
-              LOG('SelectionTool.viewSearchRelatedDocumentDialogWrapper, kw', 
+              LOG('SelectionTool.viewSearchRelatedDocumentDialogWrapper, kw',
                   0, kw)
               return self.viewSearchRelatedDocumentDialog(
-                                   method_count, form_id, 
+                                   method_count, form_id,
                                    REQUEST=REQUEST, sub_index=sub_index, **kw)
-            setattr(self.__class__, name, 
+            setattr(self.__class__, name,
                     viewSearchRelatedDocumentDialogWrapper)
 
             klass = aq_base(self).__class__
@@ -1192,22 +1230,22 @@
     self.exception_uid_list=exception_uid_list
   def getObject(self):
     return self.object
-    
+
   def getIsPureSummary(self):
     return self.is_pure_summary
-    
+
   def getDepth(self):
     return self.depth
-    
+
   def getIsOpen(self):
     return self.is_open
-  
-  def getSelectDomainDict(self): 
+
+  def getSelectDomainDict(self):
     return self.select_domain_dict
-    
+
   def getExceptionUidList(self):
     return self.exception_uid_list
-  
+
 
 def makeTreeList(here, form, root_dict, report_path, base_category, depth, unfolded_list, form_id, selection_name, report_depth, is_report_opened=1, sort_on = (('id', 'ASC'),)):
   """
@@ -1274,7 +1312,7 @@
             for sub_zo in o.searchFolder(sort_on=sort_on):
               sub_o = sub_zo.getObject()
               if sub_o is not None and hasattr(aq_base(root), 'objectValues'):
-                exception_uid_list.append(sub_o.getUid())          
+                exception_uid_list.append(sub_o.getUid())
             tree_list += [TreeListLine(o, 1, depth, 1, selection_domain, exception_uid_list)] # Summary (open)
             if is_report_opened :
               tree_list += [TreeListLine(o, 0, depth, 0, selection_domain, exception_uid_list)] # List (contents, closed, must be strict selection)
@@ -1295,12 +1333,12 @@
         tree_list += [TreeListLine(o, 1, depth, 1, selection_domain, None)] # Summary (open)
         if is_report_opened :
           tree_list += [TreeListLine(o, 0, depth, 0, selection_domain, None)] # List (contents, closed, must be strict selection)
-        tree_list += makeTreeList(here, form, new_root_dict, report_path, base_category, depth + 1, 
-            unfolded_list, form_id, selection_name, report_depth, 
+        tree_list += makeTreeList(here, form, new_root_dict, report_path, base_category, depth + 1,
+            unfolded_list, form_id, selection_name, report_depth,
             is_report_opened=is_report_opened, sort_on=sort_on)
       else:
 
         tree_list += [TreeListLine(o, 1, depth, 0, selection_domain, None)] # Summary (closed)
-   
+
   return tree_list
 




More information about the Erp5-report mailing list