0001-replace-variables-in-OpenOffice-user-field-decl-valu.patch
wcs/wf/export_to_model.py | ||
---|---|---|
38 | 38 |
template_on_formdata, register_item_class) |
39 | 39 |
from wcs.file_validation import has_file_validation, push_document |
40 | 40 | |
41 |
OO_TEXT_NS = 'urn:oasis:names:tc:opendocument:xmlns:text:1.0' |
|
42 |
OO_OFFICE_NS = 'urn:oasis:names:tc:opendocument:xmlns:office:1.0' |
|
43 |
USER_FIELD_DECL = '{%s}user-field-decl' % OO_TEXT_NS |
|
44 |
USER_FIELD_GET = '{%s}user-field-get' % OO_TEXT_NS |
|
45 |
STRING_VALUE = '{%s}string-value' % OO_OFFICE_NS |
|
46 |
NAME = '{%s}name' % OO_TEXT_NS |
|
41 | 47 | |
42 | 48 |
try: |
43 | 49 |
subprocess.check_call(['which', 'libreoffice'], stdout=open('/dev/null', 'w')) |
... | ... | |
360 | 366 |
raise TemplatingError(_('Unknown error in the ' |
361 | 367 |
'template: %s') % str(e)) |
362 | 368 | |
363 | ||
364 | 369 |
def apply_od_template_to_formdata(self, formdata): |
365 | 370 |
def process_root(root): |
371 |
# cache for keeping computed user-field-decl value around |
|
372 |
user_field_values = {} |
|
373 | ||
366 | 374 |
def process_text(t): |
367 | 375 |
if isinstance(t, unicode): |
368 | 376 |
t = t.encode(get_publisher().site_charset) |
... | ... | |
370 | 378 |
return unicode(t, get_publisher().site_charset) |
371 | 379 |
for node in root.iter(): |
372 | 380 |
got_blank_lines = False |
381 |
# apply template to user-field-decl and update user-field-get |
|
382 |
if node.tag == USER_FIELD_DECL and STRING_VALUE in node.attrib: |
|
383 |
node.attrib[STRING_VALUE] = process_text(node.attrib[STRING_VALUE]) |
|
384 |
if NAME in node.attrib: |
|
385 |
user_field_values[node.attrib[NAME]] = node.attrib[STRING_VALUE] |
|
386 |
if (node.tag == USER_FIELD_GET and NAME in node.attrib and |
|
387 |
node.attrib[NAME] in user_field_values): |
|
388 |
node.text = user_field_values[node.attrib[NAME]] |
|
389 | ||
373 | 390 |
for attr in ('text', 'tail'): |
374 | 391 |
if not getattr(node, attr): |
375 | 392 |
continue |
376 |
- |