docxhelper.py

This module contains classes and functions for generating DocX documents from HTML used for exporting reports.

Function definitions:

class apps.utils.docxhelper.HTMLToDocXParser[source]

Bases: HTMLParser.HTMLParser

Class for parsing HTML to Docx

set_body(body)[source]

Initalize the DocX document by setting the body

Args:
  • body: the DocX body
handle_starttag(tag, attrs)[source]

Handles a starttag in the HTML. Converts a predefined list of tags to the corresponding DocX definitions.

Args:
  • tag: the name of the HTML tag
  • attr: optional attrs coupled to the HTML tag
handle_endtag(tag)[source]

Handles a endtag in the HTML. Converts a predefined list of tags to the corresponding DocX definitions:

Args:
  • tag: the name of the HTML tag
handle_data(data)[source]

Adds text to the DocX document

Args:
  • data: the data/text to add to the document
handle_entityref(name)[source]

Handle special HTML entities

Args:
  • name: the name of the HTML entity
apps.utils.docxhelper.convertHtmlToDocX(sourceHtml)[source]

Wrapper function for converting HTML to DocX

Args:
  • sourceHtml: the HTML to convert
Returns:
A response instance with the DocX document included
apps.utils.docxhelper.render_to_DocX(request, body)[source]

Shortcut function for rendering the HTML template and create DocX

Args:
  • request: the initial request
  • body: the body with the text to be exported
Returns:
A response instance with the DocX document included