replace variables in OpenOffice user-field-decl values (#13129)
This commit is contained in:
parent
8f41ba6076
commit
0385bea31c
Binary file not shown.
Binary file not shown.
|
@ -38,6 +38,12 @@ from wcs.workflows import (WorkflowStatusItem, AttachmentEvolutionPart,
|
|||
template_on_formdata, register_item_class)
|
||||
from wcs.file_validation import has_file_validation, push_document
|
||||
|
||||
OO_TEXT_NS = 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'
|
||||
OO_OFFICE_NS = 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'
|
||||
USER_FIELD_DECL = '{%s}user-field-decl' % OO_TEXT_NS
|
||||
USER_FIELD_GET = '{%s}user-field-get' % OO_TEXT_NS
|
||||
STRING_VALUE = '{%s}string-value' % OO_OFFICE_NS
|
||||
NAME = '{%s}name' % OO_TEXT_NS
|
||||
|
||||
try:
|
||||
subprocess.check_call(['which', 'libreoffice'], stdout=open('/dev/null', 'w'))
|
||||
|
@ -360,9 +366,11 @@ class ExportToModel(WorkflowStatusItem):
|
|||
raise TemplatingError(_('Unknown error in the '
|
||||
'template: %s') % str(e))
|
||||
|
||||
|
||||
def apply_od_template_to_formdata(self, formdata):
|
||||
def process_root(root):
|
||||
# cache for keeping computed user-field-decl value around
|
||||
user_field_values = {}
|
||||
|
||||
def process_text(t):
|
||||
if isinstance(t, unicode):
|
||||
t = t.encode(get_publisher().site_charset)
|
||||
|
@ -370,6 +378,15 @@ class ExportToModel(WorkflowStatusItem):
|
|||
return unicode(t, get_publisher().site_charset)
|
||||
for node in root.iter():
|
||||
got_blank_lines = False
|
||||
# apply template to user-field-decl and update user-field-get
|
||||
if node.tag == USER_FIELD_DECL and STRING_VALUE in node.attrib:
|
||||
node.attrib[STRING_VALUE] = process_text(node.attrib[STRING_VALUE])
|
||||
if NAME in node.attrib:
|
||||
user_field_values[node.attrib[NAME]] = node.attrib[STRING_VALUE]
|
||||
if (node.tag == USER_FIELD_GET and NAME in node.attrib and
|
||||
node.attrib[NAME] in user_field_values):
|
||||
node.text = user_field_values[node.attrib[NAME]]
|
||||
|
||||
for attr in ('text', 'tail'):
|
||||
if not getattr(node, attr):
|
||||
continue
|
||||
|
|
Loading…
Reference in New Issue