Commit 2ac4dc85 authored by Yusuke Muraoka's avatar Yusuke Muraoka

ERP5Report is splitted to normal ERP5Form and ReportBox

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28671 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 085c3b2f
......@@ -671,6 +671,7 @@ class ProxyField(ZMIField):
# defined by a TALES
if self._p_oid is None or self.tales['field_id'] or self.tales['form_id']:
return self._get_value(id, **kw)
# XXX: Are these disabled?
proxy_field = self.getTemplateField(cache=False)
if proxy_field is not None:
return proxy_field.get_value(id, **kw)
......
This diff is collapsed.
##############################################################################
#
# Copyright (c) 2009 Nexedi SARL and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solanes <jp@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from Globals import get_request
from AccessControl.ZopeGuards import guarded_getattr
from Products.Formulator import Widget, Validator
from Products.Formulator.Field import ZMIField
from Products.Formulator.DummyField import fields
class ReportBoxWidget(Widget.Widget):
property_names = list(Widget.Widget.property_names)
property_names.append('report_method')
# XXX this is only needed on bootstrap
default = fields.StringField('default',
title='Default',
description="",
default="",
required=0)
report_method = fields.StringField('report_method',
title='Report Method',
description="",
default="",
required=0)
def render_view(self, field, value, REQUEST=None, key='reportbox', render_prefix=None):
"""
"""
if REQUEST is None:
REQUEST = get_request()
return self.render(field, key, value, REQUEST)
def render(self, field, key, value, REQUEST, render_prefix=None):
"""
"""
form = getattr(field, 'aq_parent', None)
if form is not None:
obj = getattr(form, 'aq_parent', None)
else:
obj = None
if obj is not None:
report_method = guarded_getattr(obj, field['report_method'])
if callable(report_method):
return report_method()
class ReportBoxValidator(Validator.Validator):
def validate(self, field, key, REQUEST):
return True
class ReportBox(ZMIField):
meta_type = "ReportBox"
widget = ReportBoxWidget()
validator = ReportBoxValidator()
......@@ -37,6 +37,7 @@ from Globals import InitializeClass, DTMLFile, PersistentMapping, get_request
from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Tool.BaseTool import BaseTool
from Products.ERP5Type import Permissions as ERP5Permissions
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from Products.ERP5Form import _dtmldir
from Selection import Selection, DomainSelection
from ZPublisher.HTTPRequest import FileUpload
......@@ -1320,9 +1321,38 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ):
# XXX It would be good to add somthing here
# So that 2 anonymous users do not share the same selection
def getTemporarySelectionDict(self):
""" Temporary selections are used in push/pop nested scope,
to prevent from editting for stored selection in the scope.
Typically, it is used for ReportSection."""
tv = getTransactionalVariable(self)
return tv.setdefault('_temporary_selection_dict', {})
def pushSelection(self, selection_name):
selection = self.getSelectionFor(selection_name)
# a temporary selection is kept in transaction.
temp_selection = Selection()
if selection:
temp_selection.__dict__.update(selection.__dict__)
self.getTemporarySelectionDict()\
.setdefault(selection_name, []).append(temp_selection)
def popSelection(self, selection_name):
temporary_selection_dict = self.getTemporarySelectionDict()
if selection_name in temporary_selection_dict and \
temporary_selection_dict[selection_name]:
temporary_selection_dict[selection_name].pop()
def _getSelectionFromContainer(self, selection_name):
user_id = self._getUserId()
if user_id is None: return None
temporary_selection_dict = self.getTemporarySelectionDict()
if temporary_selection_dict and selection_name in temporary_selection_dict:
if temporary_selection_dict[selection_name]:
# focus the temporary selection in the most narrow scope.
return temporary_selection_dict[selection_name][-1]
if self.isMemcachedUsed():
return self._getMemcachedContainer().get('%s-%s' %
(user_id, selection_name))
......@@ -1333,6 +1363,14 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ):
def _setSelectionToContainer(self, selection_name, selection):
user_id = self._getUserId()
if user_id is None: return
temporary_selection_dict = self.getTemporarySelectionDict()
if temporary_selection_dict and selection_name in temporary_selection_dict:
if temporary_selection_dict[selection_name]:
# focus the temporary selection in the most narrow scope.
temporary_selection_dict[selection_name][-1] = selection
return
if self.isMemcachedUsed():
self._getMemcachedContainer().set('%s-%s' % (user_id, selection_name), aq_base(selection))
else:
......@@ -1360,7 +1398,9 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ):
else:
user_id = self._getUserId()
if user_id is None: return []
return self._getPersistentContainer(user_id).keys()
tv = getTransactionalVariable(self)
return list(set(self._getPersistentContainer(user_id).keys() + self.getTemporarySelectionDict().keys()))
def _getMemcachedContainer(self):
value = getattr(aq_base(self), '_v_selection_data', None)
......
......@@ -40,7 +40,7 @@ document_classes = updateGlobals( this_module, globals(),
permissions_module = Permissions)
# Define object classes and tools
import Form, FSForm, ListBox, MatrixBox, SelectionTool
import Form, FSForm, ListBox, ReportBox, MatrixBox, SelectionTool
import OOoChart, PDFTemplate, Report, PDFForm, ParallelListField
import PlanningBox, POSBox, FormBox, EditorField, ProxyField, DurationField
import RelationField, ImageField, MultiRelationField, MultiLinkField, InputButtonField
......@@ -86,6 +86,8 @@ def initialize( context ):
'www/StringField.gif')
FieldRegistry.registerField(ListBox.ListBox,
'www/StringField.gif')
FieldRegistry.registerField(ReportBox.ReportBox,
'www/StringField.gif')
FieldRegistry.registerField(PlanningBox.PlanningBox,
'www/StringField.gif')
FieldRegistry.registerField(MatrixBox.MatrixBox,
......
......@@ -625,6 +625,10 @@ class ZMIField(
return 1
except ImportError:
return 0
def getTemplateField(self):
return self
getRecursiveTemplateField = getTemplateField
Globals.InitializeClass(ZMIField)
PythonField = ZMIField # NOTE: for backwards compatibility
......
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