Commit cf57eb76 authored by Jean-Paul Smets's avatar Jean-Paul Smets

New Report feature. New API for ListBox Line (Stat and not State)


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2619 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e764b435
......@@ -44,7 +44,7 @@ from copy import copy
from Acquisition import aq_base, aq_inner, aq_parent, aq_self
from zLOG import LOG
from Globals import InitializeClass, Persistent, Acquisition
from Globals import InitializeClass, Persistent, Acquisition, get_request
from Products.PythonScripts.Utility import allow_class
import random
......@@ -434,6 +434,13 @@ class ListBoxWidget(Widget.Widget):
default='',
required=1)
def render_view(self, field, value, REQUEST=None, render_format='html', key='listbox'):
"""
Returns
"""
if REQUEST is None: REQUEST=get_request()
return self.render(field, key, value, REQUEST, render_format=render_format)
def render(self, field, key, value, REQUEST, render_format='html'):
"""
This is where most things happen. This method renders a list
......@@ -909,7 +916,10 @@ class ListBoxWidget(Widget.Widget):
stat_context = s[0].asContext(**stat_result)
stat_context.absolute_url = lambda x: s[0].absolute_url()
stat_context.domain_url = s[0].getRelativeUrl()
report_sections += [(s[0].id, 1, s[2], [stat_context], 1, s[3], s[4], stat_context, 0)]
section_title = s[0].getTitle()
section_title = translate('content', section_title, default=section_title.decode('utf-8'))
section_title = section_title.encode('utf-8')
report_sections += [(s[0].getTitle(), 1, s[2], [stat_context], 1, s[3], s[4], stat_context, 0)]
# report id, is_summary, depth, object_list, object_list_len, XX, XX, report_object, start, stop
else:
# Prepare query
......@@ -947,15 +957,15 @@ class ListBoxWidget(Widget.Widget):
if object_list_len and s[3]:
# Display object data at same level as category selector
# If this domain is open
report_sections += [ (s[0].id, 0, s[2], [object_list[0]], 1, s[3], s[4], stat_context, 0) ]
report_sections += [ (s[0].getTitle(), 0, s[2], [object_list[0]], 1, s[3], s[4], stat_context, 0) ]
report_sections += [ (None, 0, s[2], object_list, object_list_len - 1, s[3], s[4], None, 1) ]
else:
if exception_uid_list is not None:
# Display current parent domain
report_sections += [ (s[0].id, 0, s[2], [s[0]], 1, s[3], s[4], stat_context, 0) ]
report_sections += [ (s[0].getTitle(), 0, s[2], [s[0]], 1, s[3], s[4], stat_context, 0) ]
else:
# No data to display
report_sections += [ (s[0].id, 0, s[2], [None], 1, s[3], s[4], stat_context, 0) ]
report_sections += [ (s[0].getTitle(), 0, s[2], [None], 1, s[3], s[4], stat_context, 0) ]
# Reset original value
selection.edit(report = None)
......@@ -1353,7 +1363,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
title_listboxline = ListBoxLine()
title_listboxline.markTitleLine()
for cname in columns:
title_listboxline.addColumn( cname[0].encode('utf-8'), cname[1].encode('utf-8'))
title_listboxline.addColumn( cname[0], cname[1].encode('utf-8'))
listboxline_list.append(title_listboxline)
section_index = 0
......@@ -1421,7 +1431,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
section_char = '-'
list_body = list_body + \
"""<td class="%s" align="left" valign="middle"><a href="portal_selections/foldReport?report_url=%s&form_id=%s&list_selection_name=%s">%s%s%s</a></td>
""" % (td_css, getattr(stat_context,'domain_url',''), form.id, selection_name, '&nbsp;&nbsp;' * current_section[2], section_char, section_name)
""" % (td_css, getattr(stat_context,'domain_url',''), form.id, selection_name, '&nbsp;&nbsp;' * current_section[2], section_char, translate('content', section_name, default=section_name.decode('utf-8')))
if render_format == 'list':
......@@ -1440,7 +1450,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
section_char = '+'
list_body = list_body + \
"""<td class="%s" align="left" valign="middle"><a href="portal_selections/unfoldReport?report_url=%s&form_id=%s&list_selection_name=%s">%s%s%s</a></td>
""" % (td_css, getattr(stat_context,'domain_url',''), form.id, selection_name, '&nbsp;&nbsp;' * current_section[2], section_char, section_name)
""" % (td_css, getattr(stat_context,'domain_url',''), form.id, selection_name, '&nbsp;&nbsp;' * current_section[2], section_char, translate('content', section_name, default=section_name.decode('utf-8')))
if render_format == 'list':
......@@ -1664,7 +1674,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
if 'nbsp' in attribute_value_tmp:
attribute_value_tmp = None
current_listboxline.addColumn( property_id , attribute_value_tmp)
current_listboxline.addColumn( cname[0] , attribute_value_tmp)
else:
# Check if url_columns defines a method to retrieve the URL.
......@@ -1718,7 +1728,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
if 'nbsp' in attribute_value_tmp:
attribute_value_tmp = None
current_listboxline.addColumn( property_id , attribute_value_tmp)
current_listboxline.addColumn( cname[0] , attribute_value_tmp)
list_body = list_body + '</tr>'
......@@ -1794,16 +1804,17 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
if 'nbsp' in value_tmp:
value_tmp = None
current_listboxline.addColumn( column[1] , value_tmp )
current_listboxline.addColumn( column[0] , value_tmp )
else:
list_body += '<td class="Data">&nbsp;</td>'
#if render_format == 'list': current_listboxline.addColumn( column[1] , None)
if render_format == 'list': current_listboxline.addColumn( None , None)
if render_format == 'list':
current_listboxline.addColumn( column[0] , None)
except:
list_body += '<td class="Data">&nbsp;</td>'
#if render_format == 'list': current_listboxline.addColumn( column[1] , None)
if render_format == 'list': current_listboxline.addColumn( None , None)
if render_format == 'list': current_listboxline.addColumn( extended_columns[n][0] , None)
list_body += '</tr>'
if render_format == 'list':
......@@ -2152,8 +2163,8 @@ class ListBoxLine:
"""
self.setListboxLineContentMode('StatLine')
security.declarePublic('isStateLine')
def isStateLine(self):
security.declarePublic('isStatLine')
def isStatLine(self):
"""
Returns 1 is this line contains no data but only stats
"""
......
......@@ -26,7 +26,9 @@
#
##############################################################################
from Globals import InitializeClass, PersistentMapping, DTMLFile
from copy import copy
from Globals import InitializeClass, PersistentMapping, DTMLFile, get_request
from AccessControl import Unauthorized, getSecurityManager, ClassSecurityInfo
from Products.PythonScripts.Utility import allow_class
from Products.Formulator.DummyField import fields
......@@ -180,7 +182,10 @@ class ReportSection:
param_dict = {}
def __init__(self, path='', form_id='view', param_dict=None ):
def __init__(self, path='', form_id='view',
title=None, translated_title=None, level=1,
selection_name=None, selection_params=None, listbox_display_mode=None,
selection_columns=None, selection_sort_order=None ):
"""
Initialize the line and set the default values
Selected columns must be defined in parameter of listbox.render...
......@@ -188,7 +193,15 @@ class ReportSection:
self.path = path
self.form_id = form_id
if param_dict is not None: self.param_dict = param_dict
self.title = title
self.translated_title = translated_title
self.level = level
self.saved_request = {}
self.selection_name = selection_name
self.selection_params = selection_params
self.listbox_display_mode = listbox_display_mode
self.selection_columns = selection_columns
self.selection_sort_order = selection_sort_order
#security.declarePublic('__getitem__')
#def __getitem__(self, column_id):
......@@ -198,6 +211,14 @@ class ReportSection:
def getTitle(self):
return self.title
security.declarePublic('getTranslatedTitle')
def getTranslatedTitle(self):
return self.translated_title
security.declarePublic('getLevel')
def getLevel(self):
return self.level
security.declarePublic('getPath')
def getPath(self):
return self.path
......@@ -210,9 +231,56 @@ class ReportSection:
def getFormId(self):
return self.form_id
security.declarePublic('getParamDict')
def getParamDict(self):
return self.param_dict
_no_parameter_ = []
security.declarePublic('pushRequest')
def pushReport(self, context):
REQUEST = get_request()
for k,v in self.param_dict.items():
self.saved_request[k] = REQUEST.form.get(k, self._no_parameter_)
REQUEST.form[k] = v
if self.selection_name is not None:
portal_selections = context.portal_selections
if self.listbox_display_mode is not None:
self.saved_display_mode = portal_selections.getListboxDisplayMode(self.selection_name, REQUEST=REQUEST)
portal_selections.setListboxDisplayMode(REQUEST, self.listbox_display_mode,
selection_name=self.selection_name)
if self.selection_params is not None:
self.saved_params = portal_selections.getSelectionParams(self.selection_name, REQUEST=REQUEST)
portal_selections.setSelectionParamsFor(self.selection_name,
self.selection_params, REQUEST=REQUEST)
if self.selection_columns is not None:
self.saved_columns = portal_selections.getSelectionColumns(self.selection_name, REQUEST=REQUEST)
portal_selections.setSelectionColumns(self.selection_name, self.selection_columns,
REQUEST=REQUEST)
if self.selection_sort_order is not None:
self.saved_sort_order = portal_selections.getSelectionSortOrder(self.selection_name, REQUEST=REQUEST)
portal_selections.setSelectionSortOrder(self.selection_name, self.selection_sort_order,
REQUEST=REQUEST)
security.declarePublic('popRequest')
def popReport(self, context):
REQUEST = get_request()
for k,v in self.param_dict.items():
if self.saved_request[k] is self._no_parameter_:
del REQUEST.form[k]
else:
REQUEST.form[k] = self.saved_request[k]
if self.selection_name is not None:
portal_selections = context.portal_selections
if self.listbox_display_mode is not None:
portal_selections.setListboxDisplayMode(REQUEST, self.saved_display_mode,
selection_name=self.selection_name)
if self.param_dict is not None:
portal_selections.setSelectionParamsFor(self.selection_name,
self.saved_params, REQUEST=REQUEST)
if self.selection_columns is not None:
portal_selections.setSelectionColumns(self.selection_name, self.saved_columns,
REQUEST=REQUEST)
if self.selection_sort_order is not None:
portal_selections.setSelectionSortOrder(self.selection_name, self.saved_sort_order,
REQUEST=REQUEST)
InitializeClass(ReportSection)
allow_class(ReportSection)
......@@ -620,15 +620,26 @@ class SelectionTool( UniqueObject, SimpleItem ):
referer = referer.replace('report_depth:int=', 'noreport_depth:int=')
return request.RESPONSE.redirect(referer)
security.declareProtected(ERP5Permissions.View, 'getListboxDisplayMode')
def getListboxDisplayMode(self, selection_name, REQUEST=None):
if REQUEST is None:
REQUEST = get_request()
selection = self.getSelectionFor(selection_name, REQUEST)
if getattr(selection, 'report_tree_mode', 0):
return 'ReportTreeMode'
elif getattr(selection, 'domain_tree_mode', 0):
return 'DomainTreeMode'
return 'FlatListMode'
security.declareProtected(ERP5Permissions.View, 'setListboxDisplayMode')
def setListboxDisplayMode(self, REQUEST,listbox_display_mode):
def setListboxDisplayMode(self, REQUEST,listbox_display_mode, selection_name=None):
"""
Toogle display of the listbox
"""
request = REQUEST
selection_name = request.list_selection_name
if selection_name is None: selection_name = request.list_selection_name
selection = self.getSelectionFor(selection_name, REQUEST)
if listbox_display_mode == 'FlatListMode':
......@@ -643,6 +654,10 @@ class SelectionTool( UniqueObject, SimpleItem ):
flat_list_mode = 0
domain_tree_mode = 0
report_tree_mode = 1
else:
flat_list_mode = 0
domain_tree_mode = 0
report_tree_mode = 0
selection.edit(flat_list_mode=flat_list_mode,domain_tree_mode=domain_tree_mode,
report_tree_mode=report_tree_mode)
......@@ -653,36 +668,38 @@ class SelectionTool( UniqueObject, SimpleItem ):
selection.edit(params = params)
referer = request['HTTP_REFERER']
referer = referer.replace('noreset=', 'reset=')
referer = referer.replace('noreset:int=', 'reset:int=')
referer = referer.replace('reset=', 'noreset=')
referer = referer.replace('reset:int=', 'noreset:int=')
return request.RESPONSE.redirect(referer)
security.declareProtected(ERP5Permissions.View, 'setFlatListMode')
def setFlatListMode(self, REQUEST):
def setFlatListMode(self, REQUEST, selection_name=None):
"""
Set display of the listbox to FlatList mode
"""
return self.setListboxDisplayMode(REQUEST=REQUEST,listbox_display_mode='FlatListMode')
return self.setListboxDisplayMode(REQUEST=REQUEST, listbox_display_mode='FlatListMode', selection_name=selection_name)
security.declareProtected(ERP5Permissions.View, 'setDomainTreeMode')
def setDomainTreeMode(self, REQUEST):
def setDomainTreeMode(self, REQUEST, selection_name=None):
"""
Set display of the listbox to DomainTree mode
"""
return self.setListboxDisplayMode(REQUEST=REQUEST,listbox_display_mode='DomainTreeMode')
return self.setListboxDisplayMode(REQUEST=REQUEST,listbox_display_mode='DomainTreeMode', selection_name=selection_name)
security.declareProtected(ERP5Permissions.View, 'setReportTreeMode')
def setReportTreeMode(self, REQUEST):
def setReportTreeMode(self, REQUEST, selection_name=None):
"""
Set display of the listbox to ReportTree mode
"""
return self.setListboxDisplayMode(REQUEST=REQUEST,listbox_display_mode='ReportTreeMode')
return self.setListboxDisplayMode(REQUEST=REQUEST,listbox_display_mode='ReportTreeMode',selection_name=selection_name)
security.declareProtected(ERP5Permissions.View, 'getSelectionSelectedValueList')
def getSelectionSelectedValueList(self, selection_name, REQUEST=None, selection_method=None, context=None):
......
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