[Erp5-report] r19769 - /experimental/Experimental/patches/ERP5Form_ListBox_line_marking.py

nobody at svn.erp5.org nobody at svn.erp5.org
Sun Mar 9 04:38:55 CET 2008


Author: mikolaj
Date: Sun Mar  9 04:38:55 2008
New Revision: 19769

URL: http://svn.erp5.org?rev=19769&view=rev
Log:
Added listbox line colouring functionality (it's possible to define a script name in formulator - that script should return a css name that should take care of colouring)

Added:
    experimental/Experimental/patches/ERP5Form_ListBox_line_marking.py

Added: experimental/Experimental/patches/ERP5Form_ListBox_line_marking.py
URL: http://svn.erp5.org/experimental/Experimental/patches/ERP5Form_ListBox_line_marking.py?rev=19769&view=auto
==============================================================================
--- experimental/Experimental/patches/ERP5Form_ListBox_line_marking.py (added)
+++ experimental/Experimental/patches/ERP5Form_ListBox_line_marking.py Sun Mar  9 04:38:55 2008
@@ -1,0 +1,180 @@
+##############################################################################
+#
+# Copyright (c) 2008 ERP5 Polska Sp. z o.o. All Rights Reserved.
+#                    Mikolaj Antoszkiewicz <mikolaj at erp5.pl>
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+##############################################################################
+
+from Products.Formulator.DummyField import fields
+from Products.ERP5Form.ListBox import lazyMethod
+
+from zLOG import LOG, INFO
+
+
+from Products.ERP5Form.ListBox import ListBoxWidget 
+
+ListBoxWidget.marking_method = fields.StringField('marking_method',
+                        	    		title="Marking Method",
+                          				description=('Name of script colorizing listbox lines.'),
+                          				default='',
+                          				required=0) 
+ListBoxWidget.property_names.append('marking_method')
+
+
+from Products.ERP5Form.ListBox import ListBoxRenderer
+
+def getMarkingMethodName(self):
+      """Returns ers match
+      """
+      marking_method = self.field.get_value('marking_method')
+      try:
+        name = getattr(marking_method, 'method_name')
+      except AttributeError:
+        name = marking_method
+      return name or None
+
+ListBoxRenderer.getMarkingMethodName = lazyMethod(getMarkingMethodName)
+
+
+def getMarkingMethod(self):
+      """Return the marking method object.
+      """
+      marking_method_name = self.getMarkingMethodName()
+  
+      if marking_method_name is not None:
+        try:
+          marking_method = getattr(self.getContext(), marking_method_name)
+        except AttributeError, KeyError:
+          marking_method = None
+      else:
+        marking_method = None
+ 
+      return marking_method
+ 
+ListBoxRenderer.getMarkingMethod = lazyMethod(getMarkingMethod)
+
+def ListBoxRenderer_query(self):
+      """Get report sections and construct a list of lines. Note that this method has a side
+      effect in the selection, and the renderer object itself.
+      """
+      start = self.getLineStart()
+      max_lines = self.getMaxLineNumber()
+      report_section_list = self.getReportSectionList()
+      param_dict = self.getParamDict()
+
+      # Set the total number of objects.
+      self.total_size = sum([s.object_list_len for s in report_section_list])
+
+      # Calculuate the start and the end offsets, and set the page numbers.
+      if max_lines == 0:
+        end = self.total_size
+        self.total_pages = 1
+        self.current_page = 0
+      else:
+        self.total_pages = int(max(self.total_size - 1, 0) / max_lines) + 1
+        if start >= self.total_size:
+          start = max(self.total_size - 1, 0)
+        start -= (start % max_lines)
+        self.current_page = int(start / max_lines)
+        end = min(start + max_lines, self.total_size)
+        param_dict['list_start'] = start
+        param_dict['list_lines'] = max_lines
+        selection = self.getSelection()
+        selection.edit(params = param_dict)
+
+      # Make a list of lines.
+      line_class = self.getLineClass()
+      line_list = []
+
+      try:
+        section_index = 0
+        current_section_base_index = 0
+        current_section = report_section_list[0]
+        current_section_size = current_section.object_list_len
+        for i in range(start, end):
+          # Make sure we go to the right section.
+          while current_section_base_index + current_section_size <= i:
+            current_section_base_index += current_section_size
+            section_index += 1
+            current_section = report_section_list[section_index]
+            current_section_size = current_section.object_list_len
+
+          offset = i - current_section_base_index + current_section.offset
+          if current_section.is_summary:
+            index = None
+          elif self.isReportTreeMode():
+            index = offset
+          else:
+            index = i
+
+          marking_method = self.getMarkingMethod()
+          if marking_method is not None:
+            marking_css = marking_method(current_section.object_list[offset].getObject())
+          else:
+            marking_css = ''
+
+          #LOG('ListBox', 0, 'current_section.__dict__ = %r' % (current_section.__dict__,))
+          line = line_class(renderer = self,
+                            obj = current_section.object_list[offset],
+                            index = index,
+                            is_summary = current_section.is_summary,
+                            context = current_section.context,
+                            is_open = current_section.is_open,
+                            selection_domain = current_section.selection_domain,
+                            depth = current_section.depth,
+                            domain_title = current_section.domain_title,
+                            marking_css = marking_css)
+          line_list.append(line)
+      except IndexError:
+        # If the report section list is empty, nothing to do.
+        pass
+
+      return line_list
+
+ListBoxRenderer.query = ListBoxRenderer_query
+
+from Products.ERP5Form.ListBox import ListBoxRendererLine
+
+def ListBoxRendererLine___init__(self, renderer = None, obj = None, index = 0, is_summary = False, context = None,
+                 is_open = False, selection_domain = None, depth = 0, domain_title=None, marking_css = ''):
+      """In reality, the object is a brain or a brain-like object.
+      """
+      self.renderer = renderer
+      self.obj = obj
+      self.index = index
+      self.is_summary = is_summary
+      self.context = context
+      self.is_open = is_open
+      self.selection_domain = selection_domain
+      self.depth = depth
+      self.domain_title = domain_title
+      self.marking_css = marking_css
+
+def ListBoxRendererLine_getMarkingCssName(self):
+      """Return name of css used for marking listbox line.
+      """
+      return self.marking_css
+
+ListBoxRendererLine.__init__ = ListBoxRendererLine___init__
+ListBoxRendererLine.getMarkingCssName = ListBoxRendererLine_getMarkingCssName




More information about the Erp5-report mailing list