Commit 5e3d329a authored by Yusei Tahara's avatar Yusei Tahara

Support more than four dimensional matrix.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@37072 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9c12c73c
......@@ -199,6 +199,7 @@ class MatrixBoxWidget(Widget.Widget):
if context is None:
return ''
as_cell_range_script_id = field.get_value('as_cell_range_script_id')
extra_dimension_category_list_list = [None]
if as_cell_range_script_id:
lines = []
columns = []
......@@ -214,9 +215,17 @@ class MatrixBoxWidget(Widget.Widget):
elif len_dimension_list >= 3:
lines, columns, tabs = dimension_list[:3]
if len_dimension_list > 3:
raise NotImplementedError(
"Matrix box does not support %s dimensions" %
len_dimension_list)
extra_dimension_list = dimension_list[3:]
extra_dimension_category_label_dict = {}
extra_dimension_category_index_dict = {}
for extra_dimension in extra_dimension_list:
for index, (category, label) in enumerate(extra_dimension):
extra_dimension_category_label_dict[category] = label
extra_dimension_category_index_dict[category] = index
from Products.ERP5Type.Utils import cartesianProduct
extra_dimension_category_list_list = cartesianProduct(
[[category for category, label in extra_dimension] for extra_dimension in extra_dimension_list])
else:
lines = field.get_value('lines')
columns = field.get_value('columns')
......@@ -251,9 +260,21 @@ class MatrixBoxWidget(Widget.Widget):
url = REQUEST.URL
list_html = ''
k = 0
for extra_dimension_category_list in extra_dimension_category_list_list:
if extra_dimension_category_list is None:
extra_dimension_label = ''
extra_dimension_position = ()
extra_dimension_index = ''
extra_dimension_category_list = []
else:
extra_dimension_label = ','+','.join([extra_dimension_category_label_dict[category]
for category in extra_dimension_category_list])
extra_dimension_position = tuple([extra_dimension_category_index_dict[category]
for category in extra_dimension_category_list])
extra_dimension_index = '_'+'_'.join(map(str, extra_dimension_position))
# Create one table per tab
k = 0
for tab in tabs:
tab_id = tab[0]
if (tab_id is not None) and \
......@@ -267,10 +288,10 @@ class MatrixBoxWidget(Widget.Widget):
first_tab = tab[1] or ''
header = """\
<!-- Matrix Content -->
%s<br/>
<div class="matrixbox_label_tab">%s</div>
<div class="MatrixContent">
<table cellpadding="0" cellspacing="0" border="0">
""" % first_tab
""" % (first_tab+extra_dimension_label)
# Create the footer. This should be replaced by DTML
# And work as some kind of parameter
......@@ -324,7 +345,7 @@ class MatrixBoxWidget(Widget.Widget):
elif tab_id is None:
kw = [l[0], c[0]]
else:
kw = [l[0], c[0]] + tab_id
kw = [l[0], c[0]] + tab_id + extra_dimension_category_list
kwd = {}
kwd['base_id'] = cell_base_id
cell = cell_getter_method(*kw, **kwd)
......@@ -336,10 +357,10 @@ class MatrixBoxWidget(Widget.Widget):
my_field_id = '%s_%s' % (field.id, attribute_id)
if form.has_field(my_field_id):
my_field = form.get_field(my_field_id)
key = my_field.id + '_cell_%s_%s_%s' % (i,j,k)
key = my_field.id + '_cell_%s_%s_%s%s' % (i,j,k,extra_dimension_index)
if cell is not None:
attribute_value = my_field.get_value('default',
cell=cell, cell_index=kw, cell_position = (i,j,k))
cell=cell, cell_index=kw, cell_position = ((i,j,k)+extra_dimension_position))
if render_format=='html':
display_value = attribute_value
......@@ -372,7 +393,7 @@ class MatrixBoxWidget(Widget.Widget):
else:
attribute_value = my_field.get_value('default', cell=None,
cell_index=kw, cell_position=(i,j,k))
cell_index=kw, cell_position=((i,j,k)+extra_dimension_position))
if render_format == 'html':
if field_errors:
# Display previous value in case of any error
......@@ -442,6 +463,7 @@ class MatrixBoxValidator(Validator.Validator):
context = getattr(here,getter_method_id)()
if context is None:
return {}
extra_dimension_category_list_list = [None]
if as_cell_range_script_id:
lines = []
columns = []
......@@ -457,9 +479,17 @@ class MatrixBoxValidator(Validator.Validator):
elif len_dimension_list >= 3:
lines, columns, tabs = dimension_list[:3]
if len_dimension_list > 3:
raise NotImplementedError(
"Matrix box does not support %s dimensions" %
len_dimension_list)
extra_dimension_list = dimension_list[3:]
extra_dimension_category_label_dict = {}
extra_dimension_category_index_dict = {}
for extra_dimension in extra_dimension_list:
for index, (category, label) in enumerate(extra_dimension):
extra_dimension_category_label_dict[category] = label
extra_dimension_category_index_dict[category] = index
from Products.ERP5Type.Utils import cartesianProduct
extra_dimension_category_list_list = cartesianProduct(
[[category for category, label in extra_dimension] for extra_dimension in extra_dimension_list])
else:
lines = field.get_value('lines')
columns = field.get_value('columns')
......@@ -484,8 +514,20 @@ class MatrixBoxValidator(Validator.Validator):
tab_ids = [x[0] for x in tabs]
editable_attribute_ids = [x[0] for x in editable_attributes]
k = 0
result = {}
for extra_dimension_category_list in extra_dimension_category_list_list:
if extra_dimension_category_list is None:
extra_dimension_label = ''
extra_dimension_position = ()
extra_dimension_index = ''
extra_dimension_category_list = []
else:
extra_dimension_label = ','+','.join([extra_dimension_category_label_dict[category]
for category in extra_dimension_category_list])
extra_dimension_position = tuple([extra_dimension_category_index_dict[category]
for category in extra_dimension_category_list])
extra_dimension_index = '_'+'_'.join(map(str, extra_dimension_position))
k = 0
# Create one table per tab
for tab_id in tab_ids:
if (tab_id is not None) and \
......@@ -502,7 +544,7 @@ class MatrixBoxValidator(Validator.Validator):
elif tab_id is None:
kw = [l, c]
else:
kw = [l, c] + tab_id
kw = [l, c] + tab_id + extra_dimension_category_list
kw = tuple(kw)
kwd = {}
kwd['base_id'] = cell_base_id
......@@ -514,15 +556,15 @@ class MatrixBoxValidator(Validator.Validator):
if form.has_field(my_field_id):
my_field = form.get_field(my_field_id)
if my_field.get_value('editable'):
key = 'field_' + my_field.id + '_cell_%s_%s_%s' % (i,j,k)
key = 'field_' + my_field.id + '_cell_%s_%s_%s%s' % (i,j,k,extra_dimension_index)
attribute_value = my_field.get_value('default',
cell=cell, cell_index=kw, cell_position = (i,j,k))
cell=cell, cell_index=kw, cell_position = ((i,j,k)+extra_dimension_position))
value = None
try :
value = my_field.validator.validate(
my_field, key, REQUEST)
except ValidationError, err :
err.field_id = my_field.id + '_cell_%s_%s_%s' % (i,j,k)
err.field_id = my_field.id + '_cell_%s_%s_%s%s' % (i,j,k,extra_dimension_index)
error_list.append(err)
if (attribute_value != value or \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment