Commit d3697c0f authored by Romain Courteaud's avatar Romain Courteaud

Remove lambda functions.

Use isinstance instead of type.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6455 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 20e2ec24
############################################################################## ##############################################################################
# #
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2002, 2006 Nexedi SARL and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solanes <jp@nexedi.com> # Jean-Paul Smets-Solanes <jp@nexedi.com>
# Romain Courteaud <romain@nexedi.com>
# #
# WARNING: This program as such is intended to be used by professional # WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential # programmers who take the whole responsability of assessing all potential
...@@ -26,29 +27,22 @@ ...@@ -26,29 +27,22 @@
# #
############################################################################## ##############################################################################
import string
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.Formulator.DummyField import fields from Products.Formulator.DummyField import fields
from Products.Formulator import Widget, Validator from Products.Formulator import Widget, Validator
from Products.Formulator.Field import ZMIField from Products.Formulator.Field import ZMIField
from Products.Formulator.Form import BasicForm
from Products.Formulator.MethodField import BoundMethod
from Selection import Selection
from DateTime import DateTime
from Products.ERP5Type.Utils import getPath
from zLOG import LOG
class MatrixBoxWidget(Widget.Widget): class MatrixBoxWidget(Widget.Widget):
""" """
An UI widget which displays a matrix An UI widget which displays a matrix
A MatrixBoxWidget should be called 'matrixbox', if you don't do so, then A MatrixBoxWidget should be called 'matrixbox', if you don't do so, then
you may have some errors, or some strange problems, you have been Warned !!!! you may have some errors,
or some strange problems, you have been Warned !!!!
Don't forget that you can use tales expressions for every field, so this Don't forget that you can use tales expressions for every field, so this
is really usefull if you want to use fonctions instead of predefined variables. is really usefull if you want to use fonctions
instead of predefined variables.
A function is provided to A function is provided to
...@@ -56,7 +50,6 @@ class MatrixBoxWidget(Widget.Widget): ...@@ -56,7 +50,6 @@ class MatrixBoxWidget(Widget.Widget):
- modify a cell - modify a cell
""" """
property_names = Widget.Widget.property_names +\ property_names = Widget.Widget.property_names +\
['cell_base_id', 'cell_portal_type', ['cell_base_id', 'cell_portal_type',
...@@ -76,34 +69,51 @@ class MatrixBoxWidget(Widget.Widget): ...@@ -76,34 +69,51 @@ class MatrixBoxWidget(Widget.Widget):
columns = fields.ListTextAreaField('columns', columns = fields.ListTextAreaField('columns',
title="Columns", title="Columns",
description=( description=(
"""This defines columnes of the matrixbox. This should be a list of couples, """This defines columnes of the matrixbox.
couple[0] is the variation, and couple[1] is the name displayed to the user. This should be a list of couples,
For example (('color/bleu','bleu'),('color/red','red')), Required"""), couple[0] is the variation, and couple[1] is the name displayed
to the user.
For example (('color/bleu','bleu'),('color/red','red')),
Deprecated"""),
default=[], default=[],
required=0) required=0)
lines = fields.ListTextAreaField('lines', lines = fields.ListTextAreaField('lines',
title="Lines", title="Lines",
description=( description=(
"""This defines lines of the matrixbox. This should be a list of couples, """This defines lines of the matrixbox. This should be a list of couples,
couple[0] is the variation, and couple[1] is the name displayed to the user. couple[0] is the variation, and couple[1] is the name displayed
For example (('size/baby/02','baby/02'),('size/baby/03','baby/03')), Required"""), to the user.
For example (('size/baby/02','baby/02'),('size/baby/03','baby/03')),
Deprecated"""),
default=[], default=[],
required=0) required=0)
tabs = fields.ListTextAreaField('tabs', tabs = fields.ListTextAreaField('tabs',
title="Tabs", title="Tabs",
description=( description=(
"""This defines tabs. You can use it with the same way as Lines and Columns, """This defines tabs. You can use it with the same way as Lines
This is used only if you have more than 2 kinds of variations. Required"""), and Columns,
This is used only if you have more than 2 kinds of variations.
Deprecated"""),
default=[], default=[],
required=0) required=0)
# XXX ListTextAreaField ?
cell_range = fields.ListTextAreaField('cell_range',
title="Cell Range",
description=(
"""
This defines the range of the matrix.
"""),
default=[],
required=0)
getter_method = fields.StringField('getter_method', getter_method = fields.StringField('getter_method',
title='Getter method', title='Getter method',
description=(""" description=("""
You can specify a specific method in order to retrieve the context. You can specify a specific method in order to retrieve the context.
This field can be empty, if so the MatrixBox will use the default context."""), This field can be empty, if so the MatrixBox will use the default
context."""),
default='', default='',
required=0) required=0)
...@@ -112,7 +122,8 @@ class MatrixBoxWidget(Widget.Widget): ...@@ -112,7 +122,8 @@ class MatrixBoxWidget(Widget.Widget):
title='New Cell method', title='New Cell method',
description=(""" description=("""
You can specify a specific method in order to create cells. You can specify a specific method in order to create cells.
This field can be empty, if so the MatrixBox will use the default method : This field can be empty, if so the MatrixBox will use the default
method :
newCell."""), newCell."""),
default='', default='',
...@@ -121,7 +132,8 @@ class MatrixBoxWidget(Widget.Widget): ...@@ -121,7 +132,8 @@ class MatrixBoxWidget(Widget.Widget):
editable_attributes = fields.ListTextAreaField('editable_attributes', editable_attributes = fields.ListTextAreaField('editable_attributes',
title="Editable Properties", title="Editable Properties",
description=( description=(
"""A list of attributes which are set by hidden fields called matrixbox_attribute_name. This is used """A list of attributes which are set by hidden fields called
matrixbox_attribute_name. This is used
when we want to specify a value calculated for each cell"""), when we want to specify a value calculated for each cell"""),
default=[], default=[],
required=0) required=0)
...@@ -129,7 +141,8 @@ class MatrixBoxWidget(Widget.Widget): ...@@ -129,7 +141,8 @@ class MatrixBoxWidget(Widget.Widget):
global_attributes = fields.ListTextAreaField('global_attributes', global_attributes = fields.ListTextAreaField('global_attributes',
title="Global Properties", title="Global Properties",
description=( description=(
"""An optional list of globals attributes which are set by hidden fields and which are applied to each cell. """An optional list of globals attributes which are set by hidden
fields and which are applied to each cell.
This is used if we want to set the same value for every cell"""), This is used if we want to set the same value for every cell"""),
default=[], default=[],
required=0) required=0)
...@@ -137,7 +150,8 @@ class MatrixBoxWidget(Widget.Widget): ...@@ -137,7 +150,8 @@ class MatrixBoxWidget(Widget.Widget):
cell_base_id = fields.StringField('cell_base_id', cell_base_id = fields.StringField('cell_base_id',
title='Base id for cells', title='Base id for cells',
description=(""" description=("""
The Base id for cells : this is the name used to store cells, we usually, The Base id for cells : this is the name used to store cells,
we usually,
use names like : 'mouvement','path', ...."""), use names like : 'mouvement','path', ...."""),
default='cell', default='cell',
required=0) required=0)
...@@ -145,7 +159,8 @@ class MatrixBoxWidget(Widget.Widget): ...@@ -145,7 +159,8 @@ class MatrixBoxWidget(Widget.Widget):
cell_portal_type = fields.StringField('cell_portal_type', cell_portal_type = fields.StringField('cell_portal_type',
title='Portal Type for cells', title='Portal Type for cells',
description=(""" description=("""
The Portal Type for cells : This is the portal type used to construct a new cell."""), The Portal Type for cells : This is the portal type used to
construct a new cell."""),
default='Mapped Value', default='Mapped Value',
required=0) required=0)
...@@ -155,7 +170,6 @@ class MatrixBoxWidget(Widget.Widget): ...@@ -155,7 +170,6 @@ class MatrixBoxWidget(Widget.Widget):
"The cell range should be updated upon edit."), "The cell range should be updated upon edit."),
default=0) default=0)
def render(self, field, key, value, REQUEST, render_format='html'): def render(self, field, key, value, REQUEST, render_format='html'):
""" """
This is where most things happen. This method renders a list This is where most things happen. This method renders a list
...@@ -179,14 +193,16 @@ class MatrixBoxWidget(Widget.Widget): ...@@ -179,14 +193,16 @@ class MatrixBoxWidget(Widget.Widget):
editable_attributes = field.get_value('editable_attributes') editable_attributes = field.get_value('editable_attributes')
# This is required when we have no tabs # This is required when we have no tabs
if len(tabs) == 0: tabs = [(None,None)] if len(tabs) == 0:
tabs = [(None,None)]
# This is required when we have no columns # This is required when we have no columns
if len(columns) == 0: columns = [(None,None)] if len(columns) == 0:
columns = [(None,None)]
column_ids = map(lambda x: x[0], columns) column_ids = [x[0] for x in columns]
line_ids = map(lambda x: x[0], lines) line_ids = [x[0] for x in lines]
tab_ids = map(lambda x: x[0], tabs) tab_ids = [x[0] for x in tabs]
editable_attribute_ids = map(lambda x: x[0], editable_attributes) editable_attribute_ids = [x[0] for x in editable_attributes]
# THIS MUST BE REMOVED - WHY IS THIS BAD ? # THIS MUST BE REMOVED - WHY IS THIS BAD ?
# IT IS BAD BECAUSE TAB_IDS DO NOT DEFINE A RANGE.... # IT IS BAD BECAUSE TAB_IDS DO NOT DEFINE A RANGE....
...@@ -203,7 +219,8 @@ class MatrixBoxWidget(Widget.Widget): ...@@ -203,7 +219,8 @@ class MatrixBoxWidget(Widget.Widget):
# Create one table per tab # Create one table per tab
for tab in tabs: for tab in tabs:
tab_id = tab[0] tab_id = tab[0]
if type(tab_id) is not type(()) and type(tab_id) is not type([]) and tab_id is not None: if (tab_id is not None) and \
(not isinstance(tab_id, (list, tuple))):
tab_id = [tab_id] tab_id = [tab_id]
if render_format == 'list': if render_format == 'list':
...@@ -273,7 +290,8 @@ class MatrixBoxWidget(Widget.Widget): ...@@ -273,7 +290,8 @@ class MatrixBoxWidget(Widget.Widget):
#if column_id is None and tab_id is None: #if column_id is None and tab_id is None:
# kw = [] # kw = []
column_id = c[0] column_id = c[0]
if type(column_id) is not type(()) and type(column_id) is not type([]) and column_id is not None: if (column_id is not None) and \
(not isinstance(column_id, (list, tuple))):
column_id = [column_id] column_id = [column_id]
if column_id is None: if column_id is None:
kw = [l[0]] kw = [l[0]]
...@@ -368,16 +386,18 @@ class MatrixBoxValidator(Validator.Validator): ...@@ -368,16 +386,18 @@ class MatrixBoxValidator(Validator.Validator):
# This is required when we have no columns # This is required when we have no columns
if len(columns) == 0: columns = [(None,None)] if len(columns) == 0: columns = [(None,None)]
column_ids = map(lambda x: x[0], columns) # XXX Copy/Paste from render...
line_ids = map(lambda x: x[0], lines) column_ids = [x[0] for x in columns]
tab_ids = map(lambda x: x[0], tabs) line_ids = [x[0] for x in lines]
editable_attribute_ids = map(lambda x: x[0], editable_attributes) tab_ids = [x[0] for x in tabs]
editable_attribute_ids = [x[0] for x in editable_attributes]
k = 0 k = 0
result = {} result = {}
# Create one table per tab # Create one table per tab
for tab_id in tab_ids: for tab_id in tab_ids:
if type(tab_id) is not type(()) and type(tab_id) is not type([]) and tab_id is not None: if (tab_id is not None) and \
(not isinstance(tab_id, (list, tuple))):
tab_id = [tab_id] tab_id = [tab_id]
i = 0 i = 0
...@@ -434,8 +454,10 @@ class MatrixBox(ZMIField): ...@@ -434,8 +454,10 @@ class MatrixBox(ZMIField):
security.declareProtected('Access contents information', 'get_value') security.declareProtected('Access contents information', 'get_value')
def get_value(self, id, **kw): def get_value(self, id, **kw):
if id == 'default' and kw.get('render_format') in ('list', ): if id=='default' and kw.get('render_format') in ('list', ):
return self.widget.render(self, self.generate_field_key() , None , kw.get('REQUEST'), render_format=kw.get('render_format')) return self.widget.render(self, self.generate_field_key(), None,
kw.get('REQUEST'),
render_format=kw.get('render_format'))
else: else:
return ZMIField.get_value(self, id, **kw) return ZMIField.get_value(self, id, **kw)
...@@ -443,5 +465,3 @@ class MatrixBox(ZMIField): ...@@ -443,5 +465,3 @@ class MatrixBox(ZMIField):
import psyco import psyco
psyco.bind(MatrixBoxWidget.render) psyco.bind(MatrixBoxWidget.render)
psyco.bind(MatrixBoxValidator.validate) psyco.bind(MatrixBoxValidator.validate)
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