How to use the docxcompose.properties.SimpleField function in docxcompose

To help you get started, we’ve selected a few docxcompose examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 4teamwork / docxcompose / tests / test_properties.py View on Github external
def test_identifies_simple_fields_correctly(self):
        document = Document(docx_path('outdated_docproperty_with_umlauts.docx'))
        properties = CustomProperties(document).find_docprops_in_document()

        assert 1 == len(properties), \
            'input should contain 1 simple field docproperty'

        prop = properties[0]
        assert u'F\xfc\xfc' == prop.name
        assert isinstance(prop, SimpleField)
github 4teamwork / docxcompose / docxcompose / properties.py View on Github external
def _find_docprops_in(self, element, name=None):
        # First we search for the simple fields:
        sfield_nodes = xpath(
            element,
            u'.//w:fldSimple[contains(@w:instr, \'DOCPROPERTY \')]')

        docprops = [SimpleField(sfield_node) for sfield_node in sfield_nodes]

        # Now for the complex fields
        cfield_nodes = xpath(
            element,
            u'.//w:instrText[contains(.,\'DOCPROPERTY \')]')

        docprops.extend([ComplexField(cfield_node) for cfield_node in cfield_nodes])

        if name is not None:
            docprops = filter(lambda prop: prop.name == name, docprops)
        return docprops