
    9j.                         d Z ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddl
mZ dd	lmZ dd
lZ G d de      Z G d de      Zy
)z/
Created : 2021-07-30

@author: Eric Lapouyade
    )Document)	CT_SectPr)RELATIONSHIP_TYPE)CustomProperties)xpath)Composer)NS)etreeNc                       e Zd ZddZd Zy)SubdocComposerc                 *   | j                          |r1t        |      }|j                         D ]  }|j                  |        | j	                  |       |j
                  j                  D ]  }t        |t              r| j                  |j                  | j                  j                  |       | j                  ||       | j                  ||       | j                  ||       | j                  ||       | j!                  ||       | j#                  ||       | j%                  ||       | j'                  ||        | j)                  |       | j+                          | j-                          | j/                          | j1                  |       y)zrAttach docx parts instead of appending the whole document
        thus subdoc insertion can be delegated to jinja2N)reset_reference_mappingr   keysdissolve_fields_create_style_id_mappingelementbody
isinstancer   add_referenced_partspartdoc
add_stylesadd_numberingsrestart_first_numbering
add_imagesadd_diagrams
add_shapesadd_footnotes#remove_header_and_footer_referencesadd_styles_from_other_partsrenumber_bookmarksrenumber_docpr_idsrenumber_nvpicpr_idsfix_section_types)selfr   remove_property_fieldscpropsnamer   s         Z/var/www/html/eeg-assistent/abrechnung/venv/lib/python3.12/site-packages/docxtpl/subdoc.pyattach_partszSubdocComposer.attach_parts   sT    	$$& "%c*F -&&t,- 	%%c*{{'' 	CG'9-%%chhwGOOC)W-((g6OOC)c7+OOC)sG,44S'B	C 	((-!!!!#s#    c                    t        |d      }|D ]  }dt        j                  fdt        j                  fdt        j                  fdt        j
                  ffD ]  \  }}|j                  dt        d   d|      }|j                  j                  |   j                  }| j                  j                  j                  ||      }	|j                  dt        d   d||	         y )	Nz.//dgm:relIds[@r:dm]dmloqscs{r})r   RTDIAGRAM_DATADIAGRAM_LAYOUTDIAGRAM_QUICK_STYLEDIAGRAM_COLORSgetr	   r   relstarget_partr   	relate_toset)
r%   r   r   dgm_relsdgm_relitemrt_typedm_riddm_partnew_rids
             r)   r   zSubdocComposer.add_diagrams4   s    "89 
	AGr'r(()r--.r(()	" 	Ag !C$%?@((--/;;((--11'7C36@	A
	Ar+   N)T)__name__
__module____qualname__r*   r    r+   r)   r   r      s    $@Ar+   r   c                   6    e Zd ZdZd	dZd Zd Zd Zd Zd Z	y)
Subdocz4Class for subdocument to insert into master documentNc                    || _         |j                         | _        t        |      | _        |r1t        | j                        }|j                  | j                         y | j                  j                  | j                  _        y N)tplget_docxdocxr   subdocxr   r*   _part)r%   rM   docpathcomposes       r)   __init__zSubdoc.__init__G   sY    LLN	($TYY/G  .!%DLLr+   c                 .    t        | j                  |      S rL   )getattrrP   )r%   r(   s     r)   __getattr__zSubdoc.__getattr__Q   s    t||T**r+   c           	         | j                   j                  j                  j                  W| j                   j                  j                  j	                  | j                   j                  j                  j                         t        j                  ddt        j                  | j                   j                  j                  dd            }|S )Nz</?w:body[^>]*> unicodeF)encodingpretty_print)	rP   r   r   sectPrremoveresubr
   tostring)r%   xmls     r)   _get_xmlzSubdoc._get_xmlT   s    <<$$++7LL  %%,,T\\-A-A-F-F-M-MNffNN$$))IE
 
r+   c                 "    | j                         S rL   rc   r%   s    r)   __unicode__zSubdoc.__unicode__`       }}r+   c                 "    | j                         S rL   re   rf   s    r)   __str__zSubdoc.__str__c   rh   r+   c                 "    | j                         S rL   re   rf   s    r)   __html__zSubdoc.__html__f   rh   r+   rL   )
rE   rF   rG   __doc__rT   rW   rc   rg   rj   rl   rH   r+   r)   rJ   rJ   D   s#    >1+
r+   rJ   )rm   rO   r   	docx.oxmlr   docx.opc.constantsr   r4   docxcompose.propertiesr   docxcompose.utilsr   docxcompose.composerr   r	   lxmlr
   r_   r   objectrJ   rH   r+   r)   <module>ru      sB      6 3 # )    	.AX .Ab#V #r+   