Skip to content

CxTowerTemplateMixin

  • _name: cx.tower.template.mixin
  • _description: Cetmix Tower template rendering mixin

Used to implement template rendering functions. Inherit in your model in case you want to render variable values in it.

Method render_code

Render record 'code' field using variables from kwargs Call to render recordset of the inheriting models Args: pythonic_mode (Bool): If True, all variables in kwargs are converted to strings and wrapped in double quotes. Default is False. **kwargs (dict): {variable: value, ...} Returns: dict {record_id: rendered_code, ...}

Method render_code_custom

Render custom code using variables from kwargs

This method renders a template string (code) using the variables provided in kwargs. If pythonic_mode is enabled, all variables are automatically converted to strings and enclosed in double quotes before rendering.

Args: code (Text): code to render (eg 'some {{ custom }} text') pythonic_mode (Bool): If True, all variables in kwargs are converted to strings and wrapped in double quotes. Default is False. **kwargs (dict): {variable: value, ...} Returns: rendered_code (text): The resulting string after rendering the template with the provided variables.

Method get_variables

Get the list of variables for templates Call to get variables for recordset of the inheriting models

Returns: dict {'record_id': {variables}...} NB: 'record_id' is String

Method get_variables_from_code

Get the list of variables for templates Call to get variables from custom code string

Args: code (Text) custom code (eg 'Custom {{ var }} {{ var2 }} ...') Returns: variables (List) variables (eg ['var','var2',..])