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):
def _replaceXmlByForm(self, element_tree=None, form=None, here=None,
extra_context=None, ooo_builder=None):
field_list = form.get_fields()
field_list = form.get_fields(include_disabled=1)
REQUEST = get_request()
for (count, field) in enumerate(field_list):
if isinstance(field, ListBox):
......@@ -325,11 +325,14 @@ class ODFStrategy(Implicit):
listbox=field,
REQUEST=REQUEST)
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'))
content = self._replaceXmlByFormbox(element_tree=element_tree,
field_id=field.id,
form = sub_form,
REQUEST=REQUEST)
field=field,
form=sub_form,
extra_context=extra_context,
ooo_builder=ooo_builder)
elif isinstance(field, ImageField):
element_tree = self._replaceXmlByImageField(element_tree=element_tree,
image_field=field,
......@@ -358,11 +361,15 @@ class ODFStrategy(Implicit):
reference_xpath = '//text:reference-mark[@text:name="%s"]' % field_id
reference_list = element_tree.xpath(reference_xpath, namespaces=element_tree.nsmap)
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>
for child in node.getchildren():
child.tail = ''
node.text = value
if not isinstance(field_value, list):
for child in paragraph_node.getchildren():
child.tail = ''
paragraph_node.text = value
else:
self._appendParagraphsWithLineList(target_node=target_node, line_list=field_value)
return element_tree
def _replaceNodeViaRangeReference(self, element_tree=None, field=None):
......@@ -378,15 +385,48 @@ class ODFStrategy(Implicit):
if len(reference_list) is 0:
return element_tree
target_node = reference_list[0]
target_node.tail = value
for node in target_node.itersiblings():
end_tag_name = '{%s}reference-mark-end' % element_tree.nsmap['text']
name_attribute = '{%s}name' % element_tree.nsmap['text']
if node.tag == end_tag_name and node.get(name_attribute) == field.id:
break
node.tail = ''
if not isinstance(field_value, list):
target_node.tail = value
for node in target_node.itersiblings():
end_tag_name = '{%s}reference-mark-end' % element_tree.nsmap['text']
name_attribute = '{%s}name' % element_tree.nsmap['text']
if node.tag == end_tag_name and node.get(name_attribute) == field.id:
break
node.tail = ''
else:
self._appendParagraphsWithLineList(target_node=target_node, line_list=field_value)
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):
if not extra_context.has_key('report_method') or extra_context['report_method'] is None:
return element_tree
......@@ -395,7 +435,6 @@ class ODFStrategy(Implicit):
portal_object = self.getPortalObject()
REQUEST = get_request()
request = extra_context.get('REQUEST', REQUEST)
render_prefix = None
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)
......@@ -408,12 +447,10 @@ class ODFStrategy(Implicit):
if len(report_section_list) is 0:
office_body.remove(frame_paragraph)
return element_tree
frame_paragraph_element_tree = deepcopy(frame_paragraph)
frame_paragraph_index = office_body.index(frame_paragraph)
temporary_element_tree = deepcopy(frame_paragraph)
for (index, report_item) in enumerate(report_section_list):
render_prefix = 'x%s' % index
report_item.pushReport(portal_object, render_prefix = render_prefix)
report_item.pushReport(portal_object, render_prefix=None)
here = report_item.getObject(portal_object)
form_id = report_item.getFormId()
form = getattr(here, form_id)
......@@ -426,7 +463,6 @@ class ODFStrategy(Implicit):
frame_paragraph_index=index,
frame_paragraph_element_tree=frame_paragraph_element_tree)
frame_paragraph_element_tree = self._replaceXmlByForm(element_tree=frame_paragraph_element_tree,
form=form,
here=here,
......@@ -434,7 +470,7 @@ class ODFStrategy(Implicit):
ooo_builder=ooo_builder)
office_body.insert(frame_paragraph_index, frame_paragraph_element_tree)
frame_paragraph_index += 1
report_item.popReport(portal_object, render_prefix = render_prefix)
report_item.popReport(portal_object, render_prefix=None)
return element_tree
def _setReportSectionFrameName(self,
......@@ -450,22 +486,29 @@ class ODFStrategy(Implicit):
return
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
text_list = element_tree.xpath(draw_xpath, namespaces=element_tree.nsmap)
if len(text_list) == 0:
return element_tree
parent = text_list[0].getparent()
parent.clear()
# this form.__call__() possibly has a side effect,
# so must clear the 'here' context for listBox.get_value()
box = form(REQUEST=REQUEST);
REQUEST.set('here', None)
node = etree.XML(box)
# TODO style_copy
if node is not None:
for child in node.getchildren():
parent.append(child)
target_element = text_list[0]
frame_paragraph = target_element.getparent()
office_body = frame_paragraph.getparent()
if not enabled:
office_body.remove(frame_paragraph)
return element_tree
self._replaceXmlByForm(element_tree=frame_paragraph,
form=form,
here=extra_context['here'],
extra_context=extra_context,
ooo_builder=ooo_builder)
return element_tree
def _replaceXmlByImageField(self, element_tree=None, image_field=None, ooo_builder=None):
......
......@@ -36,7 +36,7 @@ from lxml import etree
import os
class TestFormPrintout(ERP5TypeTestCase):
run_all_test = 1
run_all_test = 0
def getTitle(self):
"""
......@@ -52,12 +52,19 @@ class TestFormPrintout(ERP5TypeTestCase):
foo_file_path = os.path.join(os.path.dirname(__file__),
'test_document',
'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')
foo2_file = open(foo2_file_path, 'rb')
custom = self.portal.portal_skins.custom
addStyleSheet = custom.manage_addProduct['OFSP'].manage_addFile
if custom._getOb('Foo_getODTStyleSheet', None) is None:
addStyleSheet(id='Foo_getODTStyleSheet', file=foo_file, title='',
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']
addOOoTemplate = erp5OOo.addOOoTemplate
if custom._getOb('Foo_viewAsOdt', None) is None:
......@@ -565,37 +572,48 @@ class TestFormPrintout(ERP5TypeTestCase):
erp5form.addERP5Form(id='Foo2_view', title='Foo2')
foo2_view = custom.Foo2_view
foo2_view.manage_addField('listbox_report', 'listbox report', 'ListBox')
listbox_report = foo2_view.listbox_report
message = listbox_report.ListBox_setPropertyList(
field_list_method = 'objectValues',
foo2_view.manage_addField('listbox', 'listbox', 'ListBox')
listbox = foo2_view.listbox
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_columns = 'id|ID\ntitle|Title\nquantity|Quantity\nstart_date|Date',)
self.failUnless('Set Successfully' in message)
createZODBPythonScript(
self.portal.portal_skins.custom,
'FooReport_getReportSectionList',
'',
self.portal.portal_skins.custom,
'FooReport_getReportSectionList',
'',
r"""
from Products.ERP5Form.Report import ReportSection
r1 = ReportSection(path=context.getPhysicalPath(),
form_id='Foo2_view',
selection_report_list = [''])
selection_params={'title':'foo_04_Iteration_1'})
r2 = ReportSection(path=context.getPhysicalPath(),
form_id='Foo2_view',
selection_report_list = [''])
selection_params={'title':'foo_04_Iteration_2'})
report_section_list = [r1, r2]
return report_section_list
"""
)
test1 = self.portal.foo_module.test1
test1.foo_1.setTitle('foo_04_Iteration')
foo_report_printout = test1.FooReport_viewAsPrintout
foo_report_printout.doSettings(REQUEST=None,
title='',
form_name='FooReport_view',
template='Foo_getODTStyleSheet')
template='Foo2_getODTStyleSheet')
odf_document = foo_report_printout()
#test_output = open("/tmp/test_04_Iteratoin.odf", "w")
......@@ -603,7 +621,7 @@ return report_section_list
self.assertTrue(odf_document is not None)
builder = OOoBuilder(odf_document)
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)
frame_xpath = '//draw:frame[@draw:name="FooReport_getReportSectionList"]'
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