Commit 96e20564 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Add to reports the possiblity to invoke a method on the report context in...

Add to reports the possiblity to invoke a method on the report context in order to find the object on which the form should be applied to. This is used by the new documentation system to build DocumentationHelper instances (which do not exist within the ZODB) for each URI of each report section.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17611 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9709052f
...@@ -66,7 +66,7 @@ def addERP5Report(self, id, title="", REQUEST=None): ...@@ -66,7 +66,7 @@ def addERP5Report(self, id, title="", REQUEST=None):
# respond to the add_and_edit button if necessary # respond to the add_and_edit button if necessary
add_and_edit(self, id, REQUEST) add_and_edit(self, id, REQUEST)
return '' return ''
class ERP5Report(ERP5Form): class ERP5Report(ERP5Form):
""" """
An ERP5Form which allows to aggregate a list of An ERP5Form which allows to aggregate a list of
...@@ -113,7 +113,7 @@ class ERP5Report(ERP5Form): ...@@ -113,7 +113,7 @@ class ERP5Report(ERP5Form):
# Default Attributes # Default Attributes
report_method = None report_method = None
# Special Settings # Special Settings
settings_form = create_settings_form() settings_form = create_settings_form()
...@@ -178,7 +178,7 @@ def manage_add_report(self, id, title="", unicode_mode=0, REQUEST=None): ...@@ -178,7 +178,7 @@ def manage_add_report(self, id, title="", unicode_mode=0, REQUEST=None):
class ReportSection: class ReportSection:
""" A section in an ERP5Report. """ A section in an ERP5Report.
ERP5 Reports are made of sections, which are some standards ERP5 Forms ERP5 Reports are made of sections, which are some standards ERP5 Forms
rendered in a single document. rendered in a single document.
To create a report section, you have to define which object will be To create a report section, you have to define which object will be
...@@ -188,15 +188,22 @@ class ReportSection: ...@@ -188,15 +188,22 @@ class ReportSection:
""" """
meta_type = "ReportSection" meta_type = "ReportSection"
security = ClassSecurityInfo() security = ClassSecurityInfo()
param_dict = {}
def __init__(self, path='', form_id='', def __init__(self, path='',
title=None, translated_title=None, level=1, form_id='',
selection_name=None, selection_params=None, method_id=None,
listbox_display_mode=None, selection_columns=None, title=None,
translated_title=None,
level=1,
param_list=None,
param_dict=None,
selection_name=None,
selection_params=None,
listbox_display_mode=None,
selection_columns=None,
selection_sort_order=None, selection_sort_order=None,
selection_report_path=None, selection_report_list=None): selection_report_path=None,
selection_report_list=None):
""" """
Initialize the line and set the default values Initialize the line and set the default values
Selected columns must be defined in parameter of listbox.render... Selected columns must be defined in parameter of listbox.render...
...@@ -205,7 +212,7 @@ class ReportSection: ...@@ -205,7 +212,7 @@ class ReportSection:
selection_report_path, the root category for this report selection_report_path, the root category for this report
selection_report_list, the list of unfolded categories (defaults to all) selection_report_list, the list of unfolded categories (defaults to all)
""" """
self.path = path self.path = path
self.form_id = form_id self.form_id = form_id
self.title = title self.title = title
...@@ -223,7 +230,10 @@ class ReportSection: ...@@ -223,7 +230,10 @@ class ReportSection:
self.selection_report_path = selection_report_path self.selection_report_path = selection_report_path
self.selection_report_list = selection_report_list self.selection_report_list = selection_report_list
self.saved_request_form = {} self.saved_request_form = {}
self.param_dict = param_dict or {}
self.param_list = param_list or []
self.method_id = method_id
security.declarePublic('getTitle') security.declarePublic('getTitle')
def getTitle(self): def getTitle(self):
return self.title return self.title
...@@ -243,26 +253,30 @@ class ReportSection: ...@@ -243,26 +253,30 @@ class ReportSection:
security.declarePublic('getObject') security.declarePublic('getObject')
def getObject(self, context): def getObject(self, context):
return context.getPortalObject().restrictedTraverse(self.path) object = context.getPortalObject().restrictedTraverse(self.path)
if self.method_id is not None:
object = getattr(object, self.method_id)(*self.param_list, **self.param_dict)
return object
security.declarePublic('getFormId') security.declarePublic('getFormId')
def getFormId(self): def getFormId(self):
return self.form_id return self.form_id
_no_parameter_ = [] _no_parameter_ = []
security.declarePublic('pushReport') security.declarePublic('pushReport')
def pushReport(self, context): def pushReport(self, context):
REQUEST = get_request() REQUEST = get_request()
for k,v in self.param_dict.items(): for k,v in self.param_dict.items():
self.saved_request[k] = REQUEST.form.get(k, self._no_parameter_) self.saved_request[k] = REQUEST.form.get(k, self._no_parameter_)
REQUEST.form[k] = v REQUEST.form[k] = v
portal_selections = context.portal_selections portal_selections = context.portal_selections
selection_list = [self.selection_name] selection_list = [self.selection_name]
if self.form_id and hasattr(context[self.form_id], 'listbox') : if self.getFormId() and hasattr(context[self.getFormId()], 'listbox') :
selection_list += [ selection_list += [
context[self.form_id].listbox.get_value('selection_name') ] context[self.getFormId()].listbox.get_value('selection_name') ]
# save report's selection and orignal form's selection, # save report's selection and orignal form's selection,
#as ListBox will overwrite it #as ListBox will overwrite it
for selection_name in selection_list : for selection_name in selection_list :
...@@ -311,7 +325,7 @@ class ReportSection: ...@@ -311,7 +325,7 @@ class ReportSection:
self.saved_request_form = REQUEST.form self.saved_request_form = REQUEST.form
REQUEST.form = {} REQUEST.form = {}
security.declarePublic('popReport') security.declarePublic('popReport')
def popReport(self, context): def popReport(self, context):
REQUEST = get_request() REQUEST = get_request()
...@@ -320,12 +334,12 @@ class ReportSection: ...@@ -320,12 +334,12 @@ class ReportSection:
del REQUEST.form[k] del REQUEST.form[k]
else: else:
REQUEST.form[k] = self.saved_request[k] REQUEST.form[k] = self.saved_request[k]
portal_selections = context.portal_selections portal_selections = context.portal_selections
selection_list = [] selection_list = []
if self.form_id and hasattr(context[self.form_id], 'listbox') : if self.getFormId() and hasattr(context[self.getFormId()], 'listbox') :
selection_list += [ selection_list += [
context[self.form_id].listbox.get_value('selection_name') ] context[self.getFormId()].listbox.get_value('selection_name') ]
selection_list += [self.selection_name] selection_list += [self.selection_name]
# restore report then form selection # restore report then form selection
for selection_name in selection_list: for selection_name in selection_list:
...@@ -363,9 +377,8 @@ class ReportSection: ...@@ -363,9 +377,8 @@ class ReportSection:
portal_selections.setSelectionSortOrder(selection_name, portal_selections.setSelectionSortOrder(selection_name,
self.saved_selections[selection_name]['sort_order'], self.saved_selections[selection_name]['sort_order'],
REQUEST=REQUEST) REQUEST=REQUEST)
REQUEST.form = self.saved_request_form REQUEST.form = self.saved_request_form
InitializeClass(ReportSection) InitializeClass(ReportSection)
allow_class(ReportSection) allow_class(ReportSection)
\ No newline at end of file
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