Projet

Général

Profil

0001-wf-export_to_model-replace-deprecated-ET.getchildren.patch

Nicolas Roche, 12 décembre 2020 13:59

Télécharger (3,71 ko)

Voir les différences:

Subject: [PATCH] wf/export_to_model: replace deprecated ET.getchildren method

 wcs/wf/export_to_model.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
wcs/wf/export_to_model.py
438 438

  
439 439
    def apply_od_template_to_formdata(self, formdata):
440 440
        context = get_formdata_template_context(formdata)
441 441

  
442 442
        def process_styles(root):
443 443
            styles_node = root.find('{%s}styles' % OO_OFFICE_NS)
444 444
            if styles_node is None:
445 445
                return
446
            style_names = set([x.attrib.get('{%s}name' % OO_STYLE_NS) for x in styles_node.getchildren()])
446
            style_names = set([x.attrib.get('{%s}name' % OO_STYLE_NS) for x in styles_node])
447 447
            for style_name in ['Page_20_Title', 'Form_20_Title', 'Form_20_Subtitle',
448 448
                               'Field_20_Label', 'Field_20_Value']:
449 449
                # if any style name is defined, don't alter styles
450 450
                if style_name in style_names:
451 451
                    return
452 452
            for i, style_name in enumerate(['Field_20_Label', 'Field_20_Value',
453 453
                                            'Form_20_Subtitle', 'Form_20_Title', 'Page_20_Title']):
454 454
                style_node = ET.SubElement(styles_node, '{%s}style' % OO_STYLE_NS)
......
479 479
            for node in root.iter():
480 480
                nodes.append(node)
481 481
            for node in nodes:
482 482
                got_blank_lines = False
483 483
                if node.tag == SECTION_NODE and 'form_details' in node.attrib.get(SECTION_NAME, ''):
484 484
                    # custom behaviour for a section named form_details
485 485
                    # (actually any name containing form_details), create
486 486
                    # real odt markup.
487
                    for child in node.getchildren():
487
                    for child in node:
488 488
                        node.remove(child)
489 489
                    self.insert_form_details(node, formdata)
490 490

  
491 491
                # apply template to user-field-decl and update user-field-get
492 492
                if node.tag == USER_FIELD_DECL and STRING_VALUE in node.attrib:
493 493
                    node.attrib[STRING_VALUE] = process_text(node.attrib[STRING_VALUE])
494 494
                    if NAME in node.attrib:
495 495
                        user_field_values[node.attrib[NAME]] = node.attrib[STRING_VALUE]
......
525 525
                    # real paragraphs if we were inside a paragraph but then
526 526
                    # we would also need to copy its style and what not).
527 527
                    current_tail = node.tail or ''
528 528
                    node.tail = None
529 529
                    as_str = force_str(ET.tostring(node)).replace('\n\n',
530 530
                            2 * ('<nsa:line-break xmlns:nsa="%(ns)s"/>' % {'ns': OO_TEXT_NS}))
531 531
                    as_node = ET.fromstring(as_str)
532 532
                    node.text = as_node.text
533
                    for child in node.getchildren():
533
                    for child in node:
534 534
                        node.remove(child)
535
                    for child in as_node.getchildren():
535
                    for child in as_node:
536 536
                        node.append(child)
537 537
                    node.tail = current_tail
538 538

  
539 539
        outstream = BytesIO()
540 540
        transform_opendocument(self.model_file.get_file(), outstream,
541 541
                               process_root)
542 542
        outstream.seek(0)
543 543
        return outstream
544
-