Commit 430a99ac authored by Julien Muchembled's avatar Julien Muchembled

Do not use hasattr to test a persistent object

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43489 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6c322dc5
......@@ -322,12 +322,15 @@ class ReportSection:
selection_list = [self.selection_name]
# when the Form which is specified by form_id, has a listbox, make prefixed_selection_name.
# which is based on specified selection_name in the listbox.
if self.getFormId() and hasattr(context[self.getFormId()], 'listbox') :
selection_name = context[self.getFormId()].listbox.get_value('selection_name')
form_id = self.getFormId()
if form_id:
listbox = getattr(context[form_id], 'listbox', None)
if listbox is not None:
selection_name = listbox.get_value('selection_name')
if render_prefix is not None:
selection_name = '%s_%s' % (render_prefix, selection_name)
REQUEST.other['prefixed_selection_name'] = selection_name
selection_list += [selection_name]
selection_list.append(selection_name)
# save report's selection and orignal form's selection,
#as ListBox will overwrite it
for selection_name in filter(lambda x: x is not None, selection_list):
......@@ -387,10 +390,12 @@ class ReportSection:
portal_selections = context.portal_selections
selection_list = []
if self.getFormId() and hasattr(context[self.getFormId()], 'listbox') :
selection_name = context[self.getFormId()].listbox.get_value('selection_name')
selection_list += [selection_name]
selection_list += [self.selection_name]
form_id = self.getFormId()
if form_id:
listbox = getattr(context[form_id], 'listbox', None)
if listbox is not None:
selection_list.append(listbox.get_value('selection_name'))
selection_list.append(self.selection_name)
if self.temporary_selection:
for selection_name in selection_list:
if selection_name is not None:
......
......@@ -1151,15 +1151,13 @@ class ERP5ReportTestCase(ERP5TypeTestCase):
def getReportSectionList(self, context, report_name):
"""Get the list of report sections in a report called on context."""
report = getattr(context, report_name)
if hasattr(report, 'report_method'):
report_method = getattr(context, report.report_method)
return report_method()
else:
report_item_list = []
for reportbox in [field for field in report.get_fields()
if field.getRecursiveTemplateField().meta_type == 'ReportBox']:
report_item_list.extend(reportbox.render())
return report_item_list
report_method = getattr(report, 'report_method', None)
if report_method:
return getattr(context, report_method)()
return sum([field.render()
for field in report.get_fields()
if field.getRecursiveTemplateField().meta_type == 'ReportBox'],
[])
def getListBoxLineList(self, report_section):
"""Render the listbox in a report section, return None if no listbox exists
......
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