translator_directory.generate_docx ================================== .. py:module:: translator_directory.generate_docx Classes ------- .. autoapisummary:: translator_directory.generate_docx.FixedInplaceInlineImage translator_directory.generate_docx.Signature Functions --------- .. autoapisummary:: translator_directory.generate_docx.fill_docx_with_variables translator_directory.generate_docx.render_docx translator_directory.generate_docx.translator_functions translator_directory.generate_docx.gendered_greeting translator_directory.generate_docx.get_ticket_nr_of_translator translator_directory.generate_docx.parse_from_filename translator_directory.generate_docx.signature_for_mail_templates Module Contents --------------- .. py:function:: fill_docx_with_variables(original_docx: IO[bytes], t: onegov.translator_directory.models.translator.Translator, request: onegov.translator_directory.request.TranslatorAppRequest, signature_file: IO[bytes] | None = None, **kwargs: Any) -> tuple[dict[str, Any], bytes] Fills the variables in a docx file with the given key-value pairs. The original_docx template contains Jinja-Variables that map to keys in the template_variables dictionary. Returns A tuple containing two elements: - Variables that were found to be None or empty. - The rendered docx file (bytes). .. py:class:: FixedInplaceInlineImage(tpl, image_descriptor, width=None, height=None, anchor=None) Bases: :py:obj:`docxtpl.InlineImage` InlineImage adds images to .docx files, but additional tweaking was required for left margin alignment. We determined the precise values needed for alignment by manually aligning the image within a .docx file, saving the changes, and then comparing the updated document's XML with the previous version. .. py:method:: _insert_image() -> str .. py:method:: fix_inline_image_alignment(orig_xml: str) -> str Fixes the position of the image by setting the `distL` to zero. .. py:function:: render_docx(docx_template: docxtpl.DocxTemplate, template_variables: dict[str, Any]) -> bytes Creates the word file. template_variables: dictionary of values to find and replace in final word file. Values not present are simply ignored. .. py:function:: translator_functions(translator: onegov.translator_directory.models.translator.Translator) -> collections.abc.Iterator[str] .. py:function:: gendered_greeting(translator: onegov.translator_directory.models.translator.Translator) -> str .. py:function:: get_ticket_nr_of_translator(translator: onegov.translator_directory.models.translator.Translator, request: onegov.translator_directory.request.TranslatorAppRequest) -> str .. py:class:: Signature Bases: :py:obj:`NamedTuple` .. py:attribute:: sender_abbrev :type: str .. py:attribute:: sender_full_name :type: str .. py:attribute:: sender_function :type: str .. py:function:: parse_from_filename(abs_signature_filename: str) -> Signature Parses information from the filename. The delimiter is '__'. This is kind of implicit here, information about the user is stored in the filename of the signature image of the user. .. py:function:: signature_for_mail_templates(request: onegov.translator_directory.request.TranslatorAppRequest) -> onegov.org.models.GeneralFile | None The signature of the current user. It is an image that is manually uploaded. It should contain the string 'Unterschrift', as well as the first and last name of the user.