Skip to content

hertzforge.io.report_template

report_template

Save a report on its own, as a template another project can use.

A report is a list of blocks with symbolic bindings, such as @basis:Frf or @other:ShapeSet, so a report written without its project is a template: the same figures and text, bound again to whatever project loads it. The file is JSON with one marker key and the fields the project file keeps for a report (title, marking, marking color, blocks, and the report features when any are enabled; see native.save_report), under its own suffix, .hftemplate. A lab's house template therefore carries its choice of report features, and the laboratory's name, address and reproduction statement from the report's identification; never a report number, revision, status or issue record. A block whose binding does not resolve in the new project is an unbound card there, to be pointed at an object in the editor's pane, as an unbound block of a built-in template is.

Templates saved in templates_folder() are offered by Generate Report beside the built-in ones in every project. Older templates, under OLDER_SUFFIX with OLDER_MARKER, are read the same way and never written.

Functions:

Name Description
handles

True for a Report, which is written as a template: its blocks and

is_template_path

True for a path ending in SUFFIX or OLDER_SUFFIX.

sniff

True for a path ending in a template suffix, or a .json file whose

save

Write the report as a template (JSON).

load

Read a template as a Report, keeping only the laboratory's

templates_folder

The folder saved templates are kept in.

saved_templates

(name, path) for every template file in templates_folder(), sorted

Classes

Functions:

handles

handles(obj: Any) -> bool

True for a Report, which is written as a template: its blocks and bindings, no values.

is_template_path

is_template_path(path: str | PathLike) -> bool

True for a path ending in SUFFIX or OLDER_SUFFIX.

sniff

sniff(path: str | PathLike) -> bool

True for a path ending in a template suffix, or a .json file whose first 4096 characters hold a template marker.

A template suffix is claimed without being opened, so a damaged one reaches load and is refused with a reason rather than passed over. Other tools write .json, so that suffix is opened and checked.

save

save(report: Report, path: str | PathLike, unit_system: Any = None, **_ignored: Any) -> None

Write the report as a template (JSON).

unit_system is accepted because every exporter takes it, and is not used: a template holds no values, only what to draw and how to bind it. So the test dates a channel table block keeps (report.calibration) are left out: the next test is judged against its own date, never the last one's.

load

load(path: str | PathLike, **_ignored: Any) -> Report

Read a template as a Report, keeping only the laboratory's identification fields.

Raises ValueError when the file has no template marker, when features is not a list of keys, or when identity is not a mapping.

templates_folder

templates_folder() -> Path

The folder saved templates are kept in.

It is Hertzforge/Report Templates in the user's application data folder for the platform (~/Library/Application Support on macOS, APPDATA on Windows, XDG_DATA_HOME or ~/.local/share elsewhere), or the folder HERTZFORGE_TEMPLATES names when that environment variable is set. The folder is not created here; whatever writes to it creates it.

saved_templates

saved_templates() -> list[tuple[str, Path]]

(name, path) for every template file in templates_folder(), sorted by name, the newer suffix taken when a name has both; empty when the folder does not exist.