Commit 3127f835 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

small optimisation.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@23833 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f102f8c0
...@@ -1378,8 +1378,9 @@ class ListBoxRenderer: ...@@ -1378,8 +1378,9 @@ class ListBoxRenderer:
param = unicode(param, self.getEncoding()) param = unicode(param, self.getEncoding())
# Obtain a search field, if any. # Obtain a search field, if any.
if self.getForm().has_field(alias): form = self.getForm()
search_field = self.getForm().get_field(alias) if form.has_field(alias):
search_field = form.get_field(alias)
else: else:
search_field = None search_field = None
...@@ -1513,6 +1514,7 @@ class ListBoxRenderer: ...@@ -1513,6 +1514,7 @@ class ListBoxRenderer:
for report_tree in report_tree_list: for report_tree in report_tree_list:
# Prepare query by defining selection report object. # Prepare query by defining selection report object.
report_tree_obj = report_tree.obj
# FIXME: this code needs optimization. The query should be delayed # FIXME: this code needs optimization. The query should be delayed
# as late as possible, because this code queries all data, even if # as late as possible, because this code queries all data, even if
...@@ -1527,14 +1529,14 @@ class ListBoxRenderer: ...@@ -1527,14 +1529,14 @@ class ListBoxRenderer:
# If the domain has a context_url, list_method or stat_method # If the domain has a context_url, list_method or stat_method
# parameters, we should use them instead of the ListBox ones when # parameters, we should use them instead of the ListBox ones when
# looking for objects in the domain. # looking for objects in the domain.
domain_context = report_tree.obj.getProperty('context_url', None) domain_context = report_tree_obj.getProperty('context_url', None)
if domain_context is not None: if domain_context is not None:
domain_context = context.restrictedTraverse(domain_context) domain_context = context.restrictedTraverse(domain_context)
else: else:
domain_context = context domain_context = context
domain_list_method = report_tree.obj.getProperty('list_method', domain_list_method = report_tree_obj.getProperty('list_method',
list_method) list_method)
domain_stat_method = report_tree.obj.getProperty('stat_method', domain_stat_method = report_tree_obj.getProperty('stat_method',
stat_method) stat_method)
if report_tree.is_pure_summary and self.showStat(): if report_tree.is_pure_summary and self.showStat():
...@@ -1546,7 +1548,7 @@ class ListBoxRenderer: ...@@ -1546,7 +1548,7 @@ class ListBoxRenderer:
# Query the stat. # Query the stat.
stat_brain = selection(method=domain_stat_method, context=domain_context, REQUEST=self.request) stat_brain = selection(method=domain_stat_method, context=domain_context, REQUEST=self.request)
domain_title = report_tree.obj.getTitle()# XXX Yusei Keep original domain title before overriding domain_title = report_tree_obj.getTitle()# XXX Yusei Keep original domain title before overriding
stat_result = {} stat_result = {}
for index, (k, v) in enumerate(self.getSelectedColumnList()): for index, (k, v) in enumerate(self.getSelectedColumnList()):
...@@ -1555,9 +1557,9 @@ class ListBoxRenderer: ...@@ -1555,9 +1557,9 @@ class ListBoxRenderer:
except IndexError: except IndexError:
stat_result[k] = '' stat_result[k] = ''
stat_context = report_tree.obj.asContext(**stat_result) stat_context = report_tree_obj.asContext(**stat_result)
# XXX yo thinks that this code below is useless, so disabled. # XXX yo thinks that this code below is useless, so disabled.
#absolute_url_txt = report_tree.obj.absolute_url() #absolute_url_txt = report_tree_obj.absolute_url()
#stat_context.absolute_url = lambda: absolute_url_txt #stat_context.absolute_url = lambda: absolute_url_txt
stat_context.domain_url = report_tree.domain_url stat_context.domain_url = report_tree.domain_url
report_section_list.append(ReportSection(is_summary = True, object_list = [stat_context], report_section_list.append(ReportSection(is_summary = True, object_list = [stat_context],
...@@ -1595,7 +1597,7 @@ class ListBoxRenderer: ...@@ -1595,7 +1597,7 @@ class ListBoxRenderer:
selection_domain = report_tree.selection_domain, selection_domain = report_tree.selection_domain,
depth = report_tree.depth)) depth = report_tree.depth))
else: else:
stat_context = report_tree.obj.asContext() stat_context = report_tree_obj.asContext()
#absolute_url_txt = s[0].absolute_url() #absolute_url_txt = s[0].absolute_url()
#stat_context.absolute_url = lambda : absolute_url_txt #stat_context.absolute_url = lambda : absolute_url_txt
stat_context.domain_url = report_tree.domain_url stat_context.domain_url = report_tree.domain_url
...@@ -1620,7 +1622,7 @@ class ListBoxRenderer: ...@@ -1620,7 +1622,7 @@ class ListBoxRenderer:
if report_tree.exception_uid_list is not None: if report_tree.exception_uid_list is not None:
# Display current parent domain. # Display current parent domain.
report_section_list.append(ReportSection(is_summary = False, report_section_list.append(ReportSection(is_summary = False,
object_list = [report_tree.obj], object_list = [report_tree_obj],
object_list_len = 1, object_list_len = 1,
is_open = report_tree.is_open, is_open = report_tree.is_open,
selection_domain = report_tree.selection_domain, selection_domain = report_tree.selection_domain,
...@@ -1895,20 +1897,21 @@ class ListBoxRendererLine: ...@@ -1895,20 +1897,21 @@ class ListBoxRendererLine:
Every processed value is guaranteed to be encoded in unicode. Every processed value is guaranteed to be encoded in unicode.
""" """
# If this is a report line without statistics, just return an empty result. # If this is a report line without statistics, just return an empty result.
renderer = self.renderer
if self.getObject() is None: if self.getObject() is None:
return [(None, '')] * len(self.renderer.getSelectedColumnList()) return [(None, '')] * len(renderer.getSelectedColumnList())
# Otherwise, evaluate each column. # Otherwise, evaluate each column.
stat_column_dict = dict(self.renderer.getStatColumnList()) stat_column_dict = dict(renderer.getStatColumnList())
_marker = [] _marker = []
value_list = [] value_list = []
selection = self.renderer.getSelection() selection = renderer.getSelection()
param_dict = self.renderer.getParamDict() param_dict = renderer.getParamDict()
# Embed the selection index. # Embed the selection index.
selection.edit(index = self.index) selection.edit(index = self.index)
for (sql, title), alias in zip(self.renderer.getSelectedColumnList(), self.renderer.getColumnAliasList()): for (sql, title), alias in zip(renderer.getSelectedColumnList(), renderer.getColumnAliasList()):
editable_field = None editable_field = None
original_value = None original_value = None
processed_value = None processed_value = None
...@@ -1952,7 +1955,7 @@ class ListBoxRendererLine: ...@@ -1952,7 +1955,7 @@ class ListBoxRendererLine:
brain = self.getBrain() brain = self.getBrain()
# Use a widget, if any. # Use a widget, if any.
editable_field = self.renderer.getEditableField(alias) editable_field = renderer.getEditableField(alias)
tales = False tales = False
if editable_field is not None: if editable_field is not None:
tales = editable_field.tales.get('default', '') tales = editable_field.tales.get('default', '')
...@@ -2015,7 +2018,7 @@ class ListBoxRendererLine: ...@@ -2015,7 +2018,7 @@ class ListBoxRendererLine:
if processed_value is None: if processed_value is None:
processed_value = u'' processed_value = u''
elif not isinstance(processed_value, unicode): elif not isinstance(processed_value, unicode):
processed_value = unicode(str(processed_value), self.renderer.getEncoding()) processed_value = unicode(str(processed_value), renderer.getEncoding())
value_list.append((original_value, processed_value)) value_list.append((original_value, processed_value))
...@@ -2030,16 +2033,18 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine): ...@@ -2030,16 +2033,18 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
where each tuple consists of a piece of HTML, the original value and a boolean value which represents where each tuple consists of a piece of HTML, the original value and a boolean value which represents
an error status. If the status is true, an error is detected. an error status. If the status is true, an error is detected.
""" """
editable_column_id_set = self.renderer.getEditableColumnIdSet() renderer = self.renderer
field_id = self.renderer.getId() request = renderer.request
form = self.renderer.getForm() editable_column_id_set = renderer.getEditableColumnIdSet()
error_dict = self.renderer.getFieldErrorDict() field_id = renderer.getId()
form = renderer.getForm()
error_dict = renderer.getFieldErrorDict()
brain = self.getBrain() brain = self.getBrain()
encoding = self.renderer.getEncoding() encoding = renderer.getEncoding()
url_column_dict = dict(self.renderer.getUrlColumnList()) url_column_dict = dict(renderer.getUrlColumnList())
selection = self.renderer.getSelection() selection = renderer.getSelection()
selection_name = self.renderer.getSelectionName() selection_name = renderer.getSelectionName()
ignore_layout = int(self.renderer.request.get('ignore_layout', 0)) ignore_layout = int(request.get('ignore_layout', 0))
ui_domain = 'erp5_ui' ui_domain = 'erp5_ui'
html_list = [] html_list = []
...@@ -2061,7 +2066,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine): ...@@ -2061,7 +2066,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
break break
for (original_value, processed_value), (sql, title), alias \ for (original_value, processed_value), (sql, title), alias \
in zip(self.getValueList(), self.renderer.getSelectedColumnList(), self.renderer.getColumnAliasList()): in zip(self.getValueList(), renderer.getSelectedColumnList(), renderer.getColumnAliasList()):
# By default, no error. # By default, no error.
error = False error = False
...@@ -2072,7 +2077,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine): ...@@ -2072,7 +2077,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
# XXX why don't we generate an input form when a widget is not defined? # XXX why don't we generate an input form when a widget is not defined?
editable_field = None editable_field = None
if not self.isSummary(): if not self.isSummary():
editable_field = self.renderer.getEditableField(alias) editable_field = renderer.getEditableField(alias)
# Prepare link value - we now use it for both static and field rendering # Prepare link value - we now use it for both static and field rendering
no_link = False no_link = False
...@@ -2127,7 +2132,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine): ...@@ -2127,7 +2132,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
if has_error: # If there is any error on listbox, we should use what the user has typed if has_error: # If there is any error on listbox, we should use what the user has typed
display_value = None display_value = None
else: else:
validated_value_dict = self.renderer.request.get(field_id, None) validated_value_dict = request.get(field_id, None)
if validated_value_dict is None: if validated_value_dict is None:
# If this is neither an error nor a validated listbox # If this is neither an error nor a validated listbox
# we should use the original value # we should use the original value
...@@ -2162,8 +2167,8 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine): ...@@ -2162,8 +2167,8 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
# the REQUEST into the brain. In addition, the define a # the REQUEST into the brain. In addition, the define a
# cell property on the request itself so that forms may # cell property on the request itself so that forms may
# use the 'cell' value (refer to get_value method in Form.py) # use the 'cell' value (refer to get_value method in Form.py)
cell_request = brain.asContext( REQUEST = self.renderer.request cell_request = brain.asContext( REQUEST = request
, form = self.renderer.request.form , form = request.form
, cell = brain , cell = brain
) )
if editable_field.get_value('enabled', REQUEST=cell_request): if editable_field.get_value('enabled', REQUEST=cell_request):
...@@ -2176,7 +2181,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine): ...@@ -2176,7 +2181,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
cell_html = '' cell_html = ''
else: else:
# If the brain does not support asContext (eg. it is None), no way # If the brain does not support asContext (eg. it is None), no way
self.renderer.request.cell = self.getObject() request.cell = self.getObject()
cell_request = brain cell_request = brain
if editable_field.get_value('enabled', REQUEST=cell_request): if editable_field.get_value('enabled', REQUEST=cell_request):
cell_html = editable_field.render( value = display_value cell_html = editable_field.render( value = display_value
...@@ -2309,7 +2314,7 @@ class ListBoxHTMLRenderer(ListBoxRenderer): ...@@ -2309,7 +2314,7 @@ class ListBoxHTMLRenderer(ListBoxRenderer):
list_method = self.getListMethod() list_method = self.getListMethod()
selection = self.getSelection() selection = self.getSelection()
if list_method is not None: if list_method is not None:
method_path = getPath(self.getContext()) + '/' + self.getListMethodName() method_path = '%s/%s' % (getPath(self.getContext()), self.getListMethodName())
list_url = '%s?selection_name=%s' % (self.getUrl(), self.getRequestedSelectionName()) list_url = '%s?selection_name=%s' % (self.getUrl(), self.getRequestedSelectionName())
selection_index = self.getSelectionIndex() selection_index = self.getSelectionIndex()
if selection_index is not None: if selection_index is not None:
...@@ -2464,7 +2469,7 @@ class ListBoxValidator(Validator.Validator): ...@@ -2464,7 +2469,7 @@ class ListBoxValidator(Validator.Validator):
# we can validate, so that we can use the same list # we can validate, so that we can use the same list
# as the one used for displaying the listbox # as the one used for displaying the listbox
for sql in editable_column_ids: for sql in editable_column_ids:
alias = '_'.join(sql.split('.')) alias = sql.replace('.', '_')
if '.' in sql: if '.' in sql:
property_id = '.'.join(sql.split('.')[1:]) # Only take trailing part property_id = '.'.join(sql.split('.')[1:]) # Only take trailing part
else: else:
...@@ -2505,7 +2510,7 @@ class ListBoxValidator(Validator.Validator): ...@@ -2505,7 +2510,7 @@ class ListBoxValidator(Validator.Validator):
o.uid = uid o.uid = uid
result[uid[4:]] = {} result[uid[4:]] = {}
for sql in editable_column_ids: for sql in editable_column_ids:
alias = '_'.join(sql.split('.')) alias = sql.replace('.', '_')
if '.' in sql: if '.' in sql:
property_id = '.'.join(sql.split('.')[1:]) # Only take trailing part property_id = '.'.join(sql.split('.')[1:]) # Only take trailing part
else: else:
...@@ -2551,7 +2556,7 @@ class ListBoxValidator(Validator.Validator): ...@@ -2551,7 +2556,7 @@ class ListBoxValidator(Validator.Validator):
o = object o = object
break break
for sql in editable_column_ids: for sql in editable_column_ids:
alias = '_'.join(sql.split('.')) alias = sql.replace('.', '_')
if '.' in sql: if '.' in sql:
property_id = '.'.join(sql.split('.')[1:]) # Only take trailing part property_id = '.'.join(sql.split('.')[1:]) # Only take trailing part
else: else:
......
...@@ -154,12 +154,13 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ): ...@@ -154,12 +154,13 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ):
if REQUEST is None: if REQUEST is None:
return return
if no_reset and REQUEST.form.has_key('reset'): form = REQUEST.form
REQUEST.form['noreset'] = REQUEST.form['reset'] # Kept for compatibility - might no be used anymore if no_reset and form.has_key('reset'):
del REQUEST.form['reset'] form['noreset'] = form['reset'] # Kept for compatibility - might no be used anymore
if no_report_depth and REQUEST.form.has_key('report_depth'): del form['reset']
REQUEST.form['noreport_depth'] = REQUEST.form['report_depth'] # Kept for compatibility - might no be used anymore if no_report_depth and form.has_key('report_depth'):
del REQUEST.form['report_depth'] form['noreport_depth'] = form['report_depth'] # Kept for compatibility - might no be used anymore
del form['report_depth']
if query_string is not None: if query_string is not None:
warnings.warn('DEPRECATED: _redirectToOriginalForm got called with a query_string. The variables must be passed in REQUEST.form.', warnings.warn('DEPRECATED: _redirectToOriginalForm got called with a query_string. The variables must be passed in REQUEST.form.',
...@@ -440,21 +441,22 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ): ...@@ -440,21 +441,22 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ):
# selection_name, sort_on and form_id params are kept only for bacward compatibilty # selection_name, sort_on and form_id params are kept only for bacward compatibilty
# as some test call setSelectionQuickSortOrder in url with these params # as some test call setSelectionQuickSortOrder in url with these params
listbox_id = None listbox_id = None
form = REQUEST.form
if sort_on is None: if sort_on is None:
listbox_id, sort_on = REQUEST.form["setSelectionQuickSortOrder"].split(".", 1) listbox_id, sort_on = form["setSelectionQuickSortOrder"].split(".", 1)
if form_id is None: if form_id is None:
if REQUEST is not None: if REQUEST is not None:
if REQUEST.form.has_key('dialog_id'): if form.has_key('dialog_id'):
form_id = REQUEST.form['dialog_id'] form_id = form['dialog_id']
else: else:
form_id = REQUEST.form['form_id'] form_id = form['form_id']
if listbox_id is not None: if listbox_id is not None:
selection_name_key = "%s_list_selection_name" %listbox_id selection_name_key = "%s_list_selection_name" %listbox_id
selection_name = REQUEST.form[selection_name_key] selection_name = form[selection_name_key]
elif selection_name is None: elif selection_name is None:
selection_name = REQUEST.form['selection_name'] selection_name = form['selection_name']
selection = self.getSelectionFor(selection_name, REQUEST=REQUEST) selection = self.getSelectionFor(selection_name, REQUEST=REQUEST)
if selection is not None: if selection is not None:
...@@ -477,8 +479,8 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ): ...@@ -477,8 +479,8 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ):
selection.edit(sort_on=new_sort_on) selection.edit(sort_on=new_sort_on)
if REQUEST is not None: if REQUEST is not None:
if REQUEST.form.has_key('listbox_uid') and \ if form.has_key('listbox_uid') and \
REQUEST.form.has_key('uids'): form.has_key('uids'):
self.uncheckAll(selection_name, REQUEST.get('listbox_uid')) self.uncheckAll(selection_name, REQUEST.get('listbox_uid'))
self.checkAll(selection_name, REQUEST.get('uids')) self.checkAll(selection_name, REQUEST.get('uids'))
......
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