Template#

class ansys.dynamicreporting.core.serverless.template.Template(*args, **kwargs)#

Bases: BaseModel

Base class for all report templates.

A Template represents a node in the report definition tree. Templates are organized as parent/child hierarchies, carry a report_type discriminator used for subclass dispatch, and store their configuration in a JSON-encoded params payload.

Concrete layouts and generators subclass Template and define their own convenience properties to access over the JSON params.

Methods

Template.add_filter([filter_str])

Append filter_str to the current item filter.

Template.add_params(new_params)

Merge new_params into the existing params dictionary.

Template.add_properties(new_props)

Alias for add_property().

Template.add_property(new_props)

Merge new_props into the existing properties sub-dictionary.

Template.add_sort_fields(sort_field)

Extend the existing sort field list with sort_field.

Template.add_tag(tag[, value])

Add or update a single tag.

Template.as_dict([recursive])

Serialize the model into a plain dictionary.

Template.create(**kwargs)

Factory-style creation that dispatches to the correct subclass.

Template.delete()

Delete this object from the database.

Template.filter(**kwargs)

Return a collection of templates, scoped by subclass report_type.

Template.find([query])

Search for templates using an ADR query string.

Template.get(**kwargs)

Retrieve a single template, scoped by subclass report_type.

Template.get_filter()

Return the raw item filter string.

Template.get_filter_mode()

Return the filter mode ('items', 'root_replace', or 'root_append').

Template.get_params()

Deserialize params into a Python dictionary.

Template.get_property()

Return the properties sub-dictionary from params (if present).

Template.get_sort_fields()

Return the configured sort fields list, if any.

Template.get_sort_selection()

Return the sort selection mode ('all', 'first', or 'last').

Template.get_tags()

Return the raw tag string stored on this object.

Template.reinit()

Reset the in-memory ORM state for this object.

Template.rem_tag(tag)

Remove a tag by key, if it exists.

Template.remove_tag(tag)

Alias for rem_tag() for backwards compatibility.

Template.render(*[, context, item_filter, ...])

Render the template to HTML.

Template.render_pdf(*[, context, ...])

Render the template to a PDF byte stream.

Template.reorder_child(...)

Move a child template to a new position in children.

Template.reorder_children()

Reorder the children list based on the children_order string.

Template.save(**kwargs)

Save the template, enforcing parent/child invariants.

Template.set_filter(filter_str)

Replace the current item filter with filter_str.

Template.set_filter_mode([value])

Set the filter mode.

Template.set_params(new_params)

Replace the current params dictionary.

Template.set_property(new_props)

Replace the properties sub-dictionary with new_props.

Template.set_sort_fields(sort_field)

Set the full list of sort fields.

Template.set_sort_selection([value])

Set the sort selection mode.

Template.set_tags(tag_str)

Replace all tags with the given tag string.

Template.to_dict()

Return a JSON-serializable dictionary for the full template tree.

Template.to_json(filename)

Dump the full template tree to a JSON file.

Template.update_children_order()

Update children_order from the current children list.

Attributes

Template.children_order

Comma-separated list of child GUIDs in desired order.

Template.db

Database alias in which this object is stored.

Template.item_filter

Default ADR query string used to select items for this template.

Template.master

Whether this template is a root (no parent).

Template.name

Human-readable name of the template.

Template.params

JSON-encoded parameter dictionary backing this template configuration.

Template.parent

Parent template in the hierarchy, or None for a root template.

Template.report_type

Canonical type string used for subclass dispatch and filtering.

Template.saved

Whether this object has been successfully saved to the database.

Template.tags

Tag string used to group and filter objects.

Template.type

Alias for report_type for parity with items.

Template.date

Template creation timestamp.

Template.children

Ordered list of child templates that form this template's subtree.

Template.guid

Globally unique identifier for this object.

exception DoesNotExist(extra_detail: str = None)#

Bases: ObjectDoesNotExistError

exception IntegrityError(extra_detail: str = None)#

Bases: IntegrityError

exception MultipleObjectsReturned(extra_detail: str = None)#

Bases: MultipleObjectsReturnedError

exception NotSaved(extra_detail: str = None)#

Bases: ObjectNotSavedError

add_filter(filter_str: str = '') None#

Append filter_str to the current item filter.

add_params(new_params: dict) None#

Merge new_params into the existing params dictionary.

add_properties(new_props: dict) None#

Alias for add_property().

add_property(new_props: dict) None#

Merge new_props into the existing properties sub-dictionary.

add_sort_fields(sort_field: list) None#

Extend the existing sort field list with sort_field.

children: list[Template]#

Ordered list of child templates that form this template’s subtree.

property children_order: str#

Comma-separated list of child GUIDs in desired order.

classmethod create(**kwargs)#

Factory-style creation that dispatches to the correct subclass.

When invoked directly on Template, the caller must supply a report_type kwarg matching one of the registered subclasses. Concrete subclasses inject their own report_type value.

date: datetime#

Template creation timestamp.

classmethod filter(**kwargs)#

Return a collection of templates, scoped by subclass report_type.

classmethod find(query: str = '', **kwargs)#

Search for templates using an ADR query string.

For typed subclasses, a t_types filter is not allowed in the query string; the subclass’s report_type is injected automatically instead.

classmethod get(**kwargs)#

Retrieve a single template, scoped by subclass report_type.

get_filter() str#

Return the raw item filter string.

get_filter_mode() str#

Return the filter mode ('items', 'root_replace', or 'root_append').

get_params() dict#

Deserialize params into a Python dictionary.

get_property() dict#

Return the properties sub-dictionary from params (if present).

get_sort_fields() list#

Return the configured sort fields list, if any.

get_sort_selection() str#

Return the sort selection mode ('all', 'first', or 'last').

item_filter: str = ''#

Default ADR query string used to select items for this template.

property master: bool#

Whether this template is a root (no parent).

name: str = ''#

Human-readable name of the template.

params: str = '{}'#

JSON-encoded parameter dictionary backing this template configuration.

parent: Template = None#

Parent template in the hierarchy, or None for a root template.

render(*, context=None, item_filter: str = '', request=None) str#

Render the template to HTML.

Parameters:
contextdict, optional

Additional context passed to the rendering engine.

item_filterstr, optional

ADR query string used to select Item instances.

requestHttpRequest, optional

Django request object, if available.

Returns:
str

Rendered HTML string for the report.

render_pdf(*, context=None, item_filter: str = '', request=None) bytes#

Render the template to a PDF byte stream.

Parameters:
contextdict, optional

Additional context passed to the rendering engine.

item_filterstr, optional

ADR query string used to select Item instances.

requestHttpRequest, optional

Django request object, if available.

Returns:
bytes

PDF document bytes.

Raises:
ADRException

If rendering or PDF generation fails.

reorder_child(target_child_template: Template, new_position: int) None#

Move a child template to a new position in children.

Parameters:
target_child_templateTemplate

Child template instance to move.

new_positionint

New index in the children list.

Raises:
TemplateReorderOutOfBounds

If new_position is not within [0, len(children)).

TemplateDoesNotExist

If the target template is not present in children.

reorder_children() None#

Reorder the children list based on the children_order string.

report_type: str = ''#

Canonical type string used for subclass dispatch and filtering.

save(**kwargs)#

Save the template, enforcing parent/child invariants.

This ensures:

  • If parent is set, it must already be saved.

  • All children must be Template instances and saved.

  • _children_order is updated from children.

  • _master is derived from whether a parent is present.

  • Any configured _properties are merged into params['properties'] before persisting.

set_filter(filter_str: str) None#

Replace the current item filter with filter_str.

set_filter_mode(value: str = 'items') None#

Set the filter mode.

Parameters:
value{“items”, “root_replace”, “root_append”}

How this template’s filter affects the overall report tree.

set_params(new_params: dict) None#

Replace the current params dictionary.

Parameters:
new_paramsdict

New parameter mapping to serialize. None is treated as an empty dict.

set_property(new_props: dict) None#

Replace the properties sub-dictionary with new_props.

set_sort_fields(sort_field: list) None#

Set the full list of sort fields.

Parameters:
sort_fieldlist

A list describing sorting criteria (field names, directions, etc.).

set_sort_selection(value: str = 'all') None#

Set the sort selection mode.

Parameters:
value{“all”, “first”, “last”}

Which subset of sorted items should be used downstream.

to_dict() dict#

Return a JSON-serializable dictionary for the full template tree.

to_json(filename: str) None#

Dump the full template tree to a JSON file.

Only root templates (no parent) can be exported. The resulting file is made read-only after writing.

property type: str#

Alias for report_type for parity with items.

update_children_order() None#

Update children_order from the current children list.

The order is stored as a comma-separated list of child GUIDs and is used to persist and later restore the ordering.