[Erp5-report] r16785 - in /erp5/trunk/products/ERP5Form: ./ tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Oct 2 18:52:35 CEST 2007
Author: rafael
Date: Tue Oct 2 18:52:35 2007
New Revision: 16785
URL: http://svn.erp5.org?rev=16785&view=rev
Log:
Improve the code readability. This also makes easy to test some methods.
Modified:
erp5/trunk/products/ERP5Form/PlanningBox.py
erp5/trunk/products/ERP5Form/tests/testPlanningBox.py
Modified: erp5/trunk/products/ERP5Form/PlanningBox.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Form/PlanningBox.py?rev=16785&r1=16784&r2=16785&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Form/PlanningBox.py (original)
+++ erp5/trunk/products/ERP5Form/PlanningBox.py Tue Oct 2 18:52:35 2007
@@ -1261,7 +1261,7 @@
# only the area that need to be rendered. This prevents from useless
# processing
# calculating main axis bounds
- self.getMainAxisInfo(self.main_axis_info, report_tree_list)
+ self.main_axis_info = self.getMainAxisInfo(report_tree_list)
# applying main axis selection
if report_tree_list != []:
report_tree_list=report_tree_list[self.main_axis_info['bound_start']:
@@ -1435,14 +1435,14 @@
# axis bounds to add only the blocs needed afterwards
# getting secondary_axis_occurence to define begin and end secondary_axis
# bounds (getting absolute size)
- self.getSecondaryAxisOccurence()
+ self.secondary_axis_occurence = self.getSecondaryAxisOccurence()
# XXX changing point of view to handle axis occurences : their are now
# handled by group, so that it is easy to recover group bounds in case the
# current rendering is calendar mode.
# now getting start & stop bounds (getting relative size to the current
# rendering)
- self.getSecondaryAxisInfo(self.secondary_axis_info)
+ self.secondary_axis_info = self.getSecondaryAxisInfo()
####### SAVING NEW PROPERTIES INTO REQUEST #######
if self.list_method is not None and self.render_format != 'list':
@@ -1548,16 +1548,17 @@
# saving resulting values.
self.calendar_mode = calendar_mode
self.calendar_range = calendar_range
- self.secondary_axis_occurence = secondary_axis_occurence
-
-
- def getSecondaryAxisInfo(self, axis_dict):
+ return secondary_axis_occurence
+
+
+ def getSecondaryAxisInfo(self):
"""
secondary_axis_ocurence holds couples of data (begin,end) related to
basicActivity blocks, and axis if the instance representing the sec axis.
it is now possible to recover begin and end value of the planning and then
apply selection informations to get start and stop.
"""
+ axis_dict = {}
use_dz = self.field.get_value('use_date_zoom')
# recovering zoom properties
axis_dict['zoom_start'] = int(self.params.get('zoom_start',0))
@@ -1648,10 +1649,10 @@
axis_dict['bound_begin']
self.params['zoom_level'] = axis_dict['zoom_level']
# everything is OK, returning 'true' flag
- return 1
-
-
- def getMainAxisInfo(self, axis_dict, report_tree_list):
+ return axis_dict
+
+
+ def getMainAxisInfo(self, report_tree_list):
"""
Getting main axis properties (total pages, current page, groups per page)
and setting selection bounds (start & stop).
@@ -1660,55 +1661,60 @@
case of report tree (if the first element is a sub group of a report for
example).
"""
- axis_dict['bound_axis_groups'] = self.field.get_value('main_axis_groups')
+ main_axis_dict = {}
+ main_axis_dict['bound_axis_groups'] = self.field.get_value('main_axis_groups')
# setting begin & end bounds
- axis_dict['bound_begin'] = 0
- axis_dict['bound_end'] = len(report_tree_list)
+ main_axis_dict['bound_begin'] = 0
+ # XXX rafael: this report_tree_list should be removed from here
+ main_axis_dict['bound_end'] = len(report_tree_list)
if self.render_format == 'list':
- axis_dict['bound_start'] = 0
- axis_dict['bound_stop'] = axis_dict['bound_end']
- axis_dict['bound_page_total'] = 1
- axis_dict['bound_page_current'] = 1
- axis_dict['bound_page_groups'] = 1
+ main_axis_dict['bound_start'] = 0
+ main_axis_dict['bound_stop'] = axis_dict['bound_end']
+ main_axis_dict['bound_page_total'] = 1
+ main_axis_dict['bound_page_current'] = 1
+ main_axis_dict['bound_page_groups'] = 1
else:
# recovering first group displayed on actual page
try:
# trying to recover from REQUEST
- axis_dict['bound_start'] = self.REQUEST.get('list_start')
- axis_dict['bound_start'] = int(axis_dict['bound_start'])
+ main_axis_dict['bound_start'] = self.REQUEST.get('list_start')
+ main_axis_dict['bound_start'] = int(main_axis_dict['bound_start'])
except (AttributeError, TypeError):
# recovering from params is case failed with REQUEST
- axis_dict['bound_start'] = self.params.get('list_start',0)
- if type(axis_dict['bound_start']) is type([]):
- axis_dict['bound_start'] = axis_dict['bound_start'][0]
- if axis_dict['bound_start'] is not None:
- axis_dict['bound_start'] = int(axis_dict['bound_start'])
- axis_dict['bound_start'] = max(axis_dict['bound_start'],0)
-
- if axis_dict['bound_start'] > axis_dict['bound_end']:
+ main_axis_dict['bound_start'] = self.params.get('list_start',0)
+ if type(main_axis_dict['bound_start']) is type([]):
+ main_axis_dict['bound_start'] = main_axis_dict['bound_start'][0]
+ if main_axis_dict['bound_start'] is not None:
+ main_axis_dict['bound_start'] = int(main_axis_dict['bound_start'])
+ main_axis_dict['bound_start'] = max(main_axis_dict['bound_start'],0)
+
+ if main_axis_dict['bound_start'] > main_axis_dict['bound_end']:
# new report_group is so small that previous if after the last element
- axis_dict['bound_start'] = axis_dict['bound_end']
+ main_axis_dict['bound_start'] = main_axis_dict['bound_end']
# updating start position to fit page size.
- axis_dict['bound_start'] -= \
- (axis_dict['bound_start'] % axis_dict['bound_axis_groups'])
+ main_axis_dict['bound_start'] -= \
+ (main_axis_dict['bound_start'] % main_axis_dict['bound_axis_groups'])
# setting last group displayed on page
- axis_dict['bound_stop'] = min (axis_dict['bound_end'],
- axis_dict['bound_start'] + axis_dict['bound_axis_groups'])
+ main_axis_dict['bound_stop'] = min (main_axis_dict['bound_end'],
+ main_axis_dict['bound_start'] + main_axis_dict['bound_axis_groups'])
# calculating total number of pages
- axis_dict['bound_page_total'] = int(max(axis_dict['bound_end'] - 1,0) / \
- axis_dict['bound_axis_groups']) + 1
+ main_axis_dict['bound_page_total'] = int(max(main_axis_dict['bound_end'] - 1,0) / \
+ main_axis_dict['bound_axis_groups']) + 1
# calculating current page number
- axis_dict['bound_page_current'] = int(axis_dict['bound_start'] / \
- axis_dict['bound_axis_groups']) + 1
+ main_axis_dict['bound_page_current'] = int(main_axis_dict['bound_start'] / \
+ main_axis_dict['bound_axis_groups']) + 1
# adjusting first group displayed on current page
- axis_dict['bound_start'] = min(axis_dict['bound_start'], max(0,
- (axis_dict['bound_page_total']-1) * axis_dict['bound_axis_groups']))
-
- self.params['list_lines'] = axis_dict['bound_axis_groups']
- self.params['list_start'] = axis_dict['bound_start']
+ main_axis_dict['bound_start'] = min(main_axis_dict['bound_start'], max(0,
+ (main_axis_dict['bound_page_total']-1) * main_axis_dict['bound_axis_groups']))
+
+ self.params['list_lines'] = main_axis_dict['bound_axis_groups']
+ self.params['list_start'] = main_axis_dict['bound_start']
+
+ return main_axis_dict
+
def buildGroupStructure(self):
"""
Modified: erp5/trunk/products/ERP5Form/tests/testPlanningBox.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Form/tests/testPlanningBox.py?rev=16785&r1=16784&r2=16785&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Form/tests/testPlanningBox.py (original)
+++ erp5/trunk/products/ERP5Form/tests/testPlanningBox.py Tue Oct 2 18:52:35 2007
@@ -40,7 +40,7 @@
from ZPublisher.HTTPRequest import FileUpload
from StringIO import StringIO
from Products.ERP5Form.Selection import Selection
-
+from DateTime import DateTime
class DummyFieldStorage:
"""A dummy FieldStorage to be wrapped in a FileUpload object.
@@ -116,12 +116,27 @@
self.assertEquals(info.info,'Title 0')
self.assertEquals(info.link , '/%s/foo_module/0/0' % self.getPortal().getId())
-
def stepCheckBasic(self, sequence = None, sequence_list = None, **kw):
basic = sequence.get('basic')
self.assertEquals(len(basic.report_groups), 1)
+ # Note that this test use the use_date_zoom enabled
+ sec_axis_info = basic.getSecondaryAxisInfo()
+ date = DateTime()
+ today = DateTime('%s/%s/%s' % (date.year(),date.month(),date.day()))
+ self.assertEquals(sec_axis_info['zoom_begin'], today)
+ self.assertEquals(sec_axis_info['zoom_end'], today+1)
+ self.assertEquals(sec_axis_info['bound_begin'], today)
+ self.assertEquals(sec_axis_info['bound_start'], today)
+ self.assertEquals(sec_axis_info['bound_end'], today+1)
+ self.assertEquals(sec_axis_info['bound_stop'], today+1)
+ self.assertEquals(sec_axis_info['zoom_start'], 0)
+ self.assertEquals(sec_axis_info['zoom_level'], 1.0)
+ self.assertEquals(sec_axis_info['bound_range'], 1.0)
+
+
for tree_list, activity_list,stat in basic.report_groups:
self.assertEquals(len(activity_list), 1)
+
def test_01(self, quiet=quiet, run=run_all_test):
if not run: return
More information about the Erp5-report
mailing list