Commit 867e6044 authored by Tatuya Kamada's avatar Tatuya Kamada

* Fix

 when using selection_params with ReportSection,
 "listbox.get_value()" could not get selection_params from
 the SelectionTool.
 so removing whole 'render_prefix' to get selection_params.

 this bug is associated with r26403 refactoring

* Append
 - make Frames to enable "Hide and Show" according as
   FormBox 'enable' property
 - multi lines support such as Lines Field
 (TODO: unit testing)


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26505 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent df274d1b
...@@ -317,7 +317,7 @@ class ODFStrategy(Implicit): ...@@ -317,7 +317,7 @@ class ODFStrategy(Implicit):
def _replaceXmlByForm(self, element_tree=None, form=None, here=None, def _replaceXmlByForm(self, element_tree=None, form=None, here=None,
extra_context=None, ooo_builder=None): extra_context=None, ooo_builder=None):
field_list = form.get_fields() field_list = form.get_fields(include_disabled=1)
REQUEST = get_request() REQUEST = get_request()
for (count, field) in enumerate(field_list): for (count, field) in enumerate(field_list):
if isinstance(field, ListBox): if isinstance(field, ListBox):
...@@ -325,11 +325,14 @@ class ODFStrategy(Implicit): ...@@ -325,11 +325,14 @@ class ODFStrategy(Implicit):
listbox=field, listbox=field,
REQUEST=REQUEST) REQUEST=REQUEST)
elif isinstance(field, FormBox): elif isinstance(field, FormBox):
if not hasattr(here, field.get_value('formbox_target_id')):
continue
sub_form = getattr(here, field.get_value('formbox_target_id')) sub_form = getattr(here, field.get_value('formbox_target_id'))
content = self._replaceXmlByFormbox(element_tree=element_tree, content = self._replaceXmlByFormbox(element_tree=element_tree,
field_id=field.id, field=field,
form = sub_form, form=sub_form,
REQUEST=REQUEST) extra_context=extra_context,
ooo_builder=ooo_builder)
elif isinstance(field, ImageField): elif isinstance(field, ImageField):
element_tree = self._replaceXmlByImageField(element_tree=element_tree, element_tree = self._replaceXmlByImageField(element_tree=element_tree,
image_field=field, image_field=field,
...@@ -358,11 +361,15 @@ class ODFStrategy(Implicit): ...@@ -358,11 +361,15 @@ class ODFStrategy(Implicit):
reference_xpath = '//text:reference-mark[@text:name="%s"]' % field_id reference_xpath = '//text:reference-mark[@text:name="%s"]' % field_id
reference_list = element_tree.xpath(reference_xpath, namespaces=element_tree.nsmap) reference_list = element_tree.xpath(reference_xpath, namespaces=element_tree.nsmap)
if len(reference_list) > 0: if len(reference_list) > 0:
node = reference_list[0].getparent() paragraph_node = reference_list[0].getparent()
parent_node = paragraph_node.getparent()
# remove such a "bbb": <text:p>aaa<br/>bbb</text:p> # remove such a "bbb": <text:p>aaa<br/>bbb</text:p>
for child in node.getchildren(): if not isinstance(field_value, list):
for child in paragraph_node.getchildren():
child.tail = '' child.tail = ''
node.text = value paragraph_node.text = value
else:
self._appendParagraphsWithLineList(target_node=target_node, line_list=field_value)
return element_tree return element_tree
def _replaceNodeViaRangeReference(self, element_tree=None, field=None): def _replaceNodeViaRangeReference(self, element_tree=None, field=None):
...@@ -378,6 +385,7 @@ class ODFStrategy(Implicit): ...@@ -378,6 +385,7 @@ class ODFStrategy(Implicit):
if len(reference_list) is 0: if len(reference_list) is 0:
return element_tree return element_tree
target_node = reference_list[0] target_node = reference_list[0]
if not isinstance(field_value, list):
target_node.tail = value target_node.tail = value
for node in target_node.itersiblings(): for node in target_node.itersiblings():
end_tag_name = '{%s}reference-mark-end' % element_tree.nsmap['text'] end_tag_name = '{%s}reference-mark-end' % element_tree.nsmap['text']
...@@ -385,8 +393,40 @@ class ODFStrategy(Implicit): ...@@ -385,8 +393,40 @@ class ODFStrategy(Implicit):
if node.tag == end_tag_name and node.get(name_attribute) == field.id: if node.tag == end_tag_name and node.get(name_attribute) == field.id:
break break
node.tail = '' node.tail = ''
else:
self._appendParagraphsWithLineList(target_node=target_node, line_list=field_value)
return element_tree return element_tree
def _appendParagraphsWithLineList(self, target_node=None, line_list=None):
"""create paragraphs
example:
--
first line
second line
--
<p:text>
first line
</p:text>
<p:text>
second line
</p:text>
"""
paragraph_node = target_node.getparent()
parent_node = paragraph_node.getparent()
paragraph_list = []
for line in line_list:
p = deepcopy(paragraph_node)
for child in p.getchildren():
child.tail = ''
value = self._toUnicodeString(line)
p.text = value
paragraph_list.append(p)
paragraph_node_index = parent_node.index(paragraph_node)
parent_node.remove(paragraph_node)
for (index, paragraph) in enumerate(paragraph_list):
parent_node.insert(paragraph_node_index + 1, paragraph)
def _replaceXmlByReportSection(self, element_tree=None, extra_context=None, ooo_builder=None): def _replaceXmlByReportSection(self, element_tree=None, extra_context=None, ooo_builder=None):
if not extra_context.has_key('report_method') or extra_context['report_method'] is None: if not extra_context.has_key('report_method') or extra_context['report_method'] is None:
return element_tree return element_tree
...@@ -395,7 +435,6 @@ class ODFStrategy(Implicit): ...@@ -395,7 +435,6 @@ class ODFStrategy(Implicit):
portal_object = self.getPortalObject() portal_object = self.getPortalObject()
REQUEST = get_request() REQUEST = get_request()
request = extra_context.get('REQUEST', REQUEST) request = extra_context.get('REQUEST', REQUEST)
render_prefix = None
report_section_frame_xpath = '//draw:frame[@draw:name="%s"]' % report_method.__name__ report_section_frame_xpath = '//draw:frame[@draw:name="%s"]' % report_method.__name__
frame_list = element_tree.xpath(report_section_frame_xpath, namespaces=element_tree.nsmap) frame_list = element_tree.xpath(report_section_frame_xpath, namespaces=element_tree.nsmap)
...@@ -408,12 +447,10 @@ class ODFStrategy(Implicit): ...@@ -408,12 +447,10 @@ class ODFStrategy(Implicit):
if len(report_section_list) is 0: if len(report_section_list) is 0:
office_body.remove(frame_paragraph) office_body.remove(frame_paragraph)
return element_tree return element_tree
frame_paragraph_element_tree = deepcopy(frame_paragraph)
frame_paragraph_index = office_body.index(frame_paragraph) frame_paragraph_index = office_body.index(frame_paragraph)
temporary_element_tree = deepcopy(frame_paragraph) temporary_element_tree = deepcopy(frame_paragraph)
for (index, report_item) in enumerate(report_section_list): for (index, report_item) in enumerate(report_section_list):
render_prefix = 'x%s' % index report_item.pushReport(portal_object, render_prefix=None)
report_item.pushReport(portal_object, render_prefix = render_prefix)
here = report_item.getObject(portal_object) here = report_item.getObject(portal_object)
form_id = report_item.getFormId() form_id = report_item.getFormId()
form = getattr(here, form_id) form = getattr(here, form_id)
...@@ -426,7 +463,6 @@ class ODFStrategy(Implicit): ...@@ -426,7 +463,6 @@ class ODFStrategy(Implicit):
frame_paragraph_index=index, frame_paragraph_index=index,
frame_paragraph_element_tree=frame_paragraph_element_tree) frame_paragraph_element_tree=frame_paragraph_element_tree)
frame_paragraph_element_tree = self._replaceXmlByForm(element_tree=frame_paragraph_element_tree, frame_paragraph_element_tree = self._replaceXmlByForm(element_tree=frame_paragraph_element_tree,
form=form, form=form,
here=here, here=here,
...@@ -434,7 +470,7 @@ class ODFStrategy(Implicit): ...@@ -434,7 +470,7 @@ class ODFStrategy(Implicit):
ooo_builder=ooo_builder) ooo_builder=ooo_builder)
office_body.insert(frame_paragraph_index, frame_paragraph_element_tree) office_body.insert(frame_paragraph_index, frame_paragraph_element_tree)
frame_paragraph_index += 1 frame_paragraph_index += 1
report_item.popReport(portal_object, render_prefix = render_prefix) report_item.popReport(portal_object, render_prefix=None)
return element_tree return element_tree
def _setReportSectionFrameName(self, def _setReportSectionFrameName(self,
...@@ -450,22 +486,29 @@ class ODFStrategy(Implicit): ...@@ -450,22 +486,29 @@ class ODFStrategy(Implicit):
return return
report_section_frame[0].set(draw_name_attribute, report_section_frame_name) report_section_frame[0].set(draw_name_attribute, report_section_frame_name)
def _replaceXmlByFormbox(self, element_tree=None, field_id=None, form=None, REQUEST=None): def _replaceXmlByFormbox(self,
element_tree=None,
field=None,
form=None,
extra_context=None,
ooo_builder=None):
field_id = field.id
enabled = field.get_value('enabled')
draw_xpath = '//draw:frame[@draw:name="%s"]/draw:text-box/*' % field_id draw_xpath = '//draw:frame[@draw:name="%s"]/draw:text-box/*' % field_id
text_list = element_tree.xpath(draw_xpath, namespaces=element_tree.nsmap) text_list = element_tree.xpath(draw_xpath, namespaces=element_tree.nsmap)
if len(text_list) == 0: if len(text_list) == 0:
return element_tree return element_tree
parent = text_list[0].getparent() target_element = text_list[0]
parent.clear() frame_paragraph = target_element.getparent()
# this form.__call__() possibly has a side effect, office_body = frame_paragraph.getparent()
# so must clear the 'here' context for listBox.get_value() if not enabled:
box = form(REQUEST=REQUEST); office_body.remove(frame_paragraph)
REQUEST.set('here', None) return element_tree
node = etree.XML(box) self._replaceXmlByForm(element_tree=frame_paragraph,
# TODO style_copy form=form,
if node is not None: here=extra_context['here'],
for child in node.getchildren(): extra_context=extra_context,
parent.append(child) ooo_builder=ooo_builder)
return element_tree return element_tree
def _replaceXmlByImageField(self, element_tree=None, image_field=None, ooo_builder=None): def _replaceXmlByImageField(self, element_tree=None, image_field=None, ooo_builder=None):
......
...@@ -36,7 +36,7 @@ from lxml import etree ...@@ -36,7 +36,7 @@ from lxml import etree
import os import os
class TestFormPrintout(ERP5TypeTestCase): class TestFormPrintout(ERP5TypeTestCase):
run_all_test = 1 run_all_test = 0
def getTitle(self): def getTitle(self):
""" """
...@@ -52,12 +52,19 @@ class TestFormPrintout(ERP5TypeTestCase): ...@@ -52,12 +52,19 @@ class TestFormPrintout(ERP5TypeTestCase):
foo_file_path = os.path.join(os.path.dirname(__file__), foo_file_path = os.path.join(os.path.dirname(__file__),
'test_document', 'test_document',
'Foo_001.odt') 'Foo_001.odt')
foo2_file_path = os.path.join(os.path.dirname(__file__),
'test_document',
'Foo_002.odt')
foo_file = open(foo_file_path, 'rb') foo_file = open(foo_file_path, 'rb')
foo2_file = open(foo2_file_path, 'rb')
custom = self.portal.portal_skins.custom custom = self.portal.portal_skins.custom
addStyleSheet = custom.manage_addProduct['OFSP'].manage_addFile addStyleSheet = custom.manage_addProduct['OFSP'].manage_addFile
if custom._getOb('Foo_getODTStyleSheet', None) is None: if custom._getOb('Foo_getODTStyleSheet', None) is None:
addStyleSheet(id='Foo_getODTStyleSheet', file=foo_file, title='', addStyleSheet(id='Foo_getODTStyleSheet', file=foo_file, title='',
precondition='', content_type = 'application/vnd.oasis.opendocument.text') precondition='', content_type = 'application/vnd.oasis.opendocument.text')
if custom._getOb('Foo2_getODTStyleSheet', None) is None:
addStyleSheet(id='Foo2_getODTStyleSheet', file=foo2_file, title='',
precondition='', content_type = 'application/vnd.oasis.opendocument.text')
erp5OOo = custom.manage_addProduct['ERP5OOo'] erp5OOo = custom.manage_addProduct['ERP5OOo']
addOOoTemplate = erp5OOo.addOOoTemplate addOOoTemplate = erp5OOo.addOOoTemplate
if custom._getOb('Foo_viewAsOdt', None) is None: if custom._getOb('Foo_viewAsOdt', None) is None:
...@@ -565,10 +572,22 @@ class TestFormPrintout(ERP5TypeTestCase): ...@@ -565,10 +572,22 @@ class TestFormPrintout(ERP5TypeTestCase):
erp5form.addERP5Form(id='Foo2_view', title='Foo2') erp5form.addERP5Form(id='Foo2_view', title='Foo2')
foo2_view = custom.Foo2_view foo2_view = custom.Foo2_view
foo2_view.manage_addField('listbox_report', 'listbox report', 'ListBox') foo2_view.manage_addField('listbox', 'listbox', 'ListBox')
listbox_report = foo2_view.listbox_report listbox = foo2_view.listbox
message = listbox_report.ListBox_setPropertyList(
field_list_method = 'objectValues', createZODBPythonScript(
self.portal.portal_skins.custom,
'FooReport_getFooList',
'title,**kw',
r"""
foo_list = context.objectValues(portal_type='Foo Line')
for foo in foo_list:
foo.setTitle(title)
return foo_list
"""
)
message = listbox.ListBox_setPropertyList(
field_list_method = 'FooReport_getFooList',
field_portal_types = 'Foo Line | Foo Line', field_portal_types = 'Foo Line | Foo Line',
field_columns = 'id|ID\ntitle|Title\nquantity|Quantity\nstart_date|Date',) field_columns = 'id|ID\ntitle|Title\nquantity|Quantity\nstart_date|Date',)
self.failUnless('Set Successfully' in message) self.failUnless('Set Successfully' in message)
...@@ -581,21 +600,20 @@ from Products.ERP5Form.Report import ReportSection ...@@ -581,21 +600,20 @@ from Products.ERP5Form.Report import ReportSection
r1 = ReportSection(path=context.getPhysicalPath(), r1 = ReportSection(path=context.getPhysicalPath(),
form_id='Foo2_view', form_id='Foo2_view',
selection_report_list = ['']) selection_params={'title':'foo_04_Iteration_1'})
r2 = ReportSection(path=context.getPhysicalPath(), r2 = ReportSection(path=context.getPhysicalPath(),
form_id='Foo2_view', form_id='Foo2_view',
selection_report_list = ['']) selection_params={'title':'foo_04_Iteration_2'})
report_section_list = [r1, r2] report_section_list = [r1, r2]
return report_section_list return report_section_list
""" """
) )
test1 = self.portal.foo_module.test1 test1 = self.portal.foo_module.test1
test1.foo_1.setTitle('foo_04_Iteration')
foo_report_printout = test1.FooReport_viewAsPrintout foo_report_printout = test1.FooReport_viewAsPrintout
foo_report_printout.doSettings(REQUEST=None, foo_report_printout.doSettings(REQUEST=None,
title='', title='',
form_name='FooReport_view', form_name='FooReport_view',
template='Foo_getODTStyleSheet') template='Foo2_getODTStyleSheet')
odf_document = foo_report_printout() odf_document = foo_report_printout()
#test_output = open("/tmp/test_04_Iteratoin.odf", "w") #test_output = open("/tmp/test_04_Iteratoin.odf", "w")
...@@ -603,7 +621,7 @@ return report_section_list ...@@ -603,7 +621,7 @@ return report_section_list
self.assertTrue(odf_document is not None) self.assertTrue(odf_document is not None)
builder = OOoBuilder(odf_document) builder = OOoBuilder(odf_document)
content_xml = builder.extract("content.xml") content_xml = builder.extract("content.xml")
self.assertTrue(content_xml.find("foo_04_Iteration") > 0) self.assertTrue(content_xml.find("foo_04_Iteration_1") > 0)
content = etree.XML(content_xml) content = etree.XML(content_xml)
frame_xpath = '//draw:frame[@draw:name="FooReport_getReportSectionList"]' frame_xpath = '//draw:frame[@draw:name="FooReport_getReportSectionList"]'
frame_list = content.xpath(frame_xpath, namespaces=content.nsmap) frame_list = content.xpath(frame_xpath, namespaces=content.nsmap)
......
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