Coverage for gws-app/gws/base/template/__init__.py: 100%
2 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
1"""Templates.
3Templates generate content from data: HTML pages, feature descriptions, print
4layouts and other output. A template is identified by its ``subject``, which
5names the purpose it serves, for example ``feature.description``,
6``layer.description``, ``project.description``, ``project.home`` or
7``application.home``. Concrete template types are plugins: ``html``, ``text``,
8``map``, ``py`` and ``qgis``.
10Submodules:
12- ``core``: the base class for templates (``gws.Template``), with the common
13 ``Config`` options (``subject``, ``title``, ``mimeTypes``, ``pageSize``,
14 ``mapSize``, ``pageMargin``). If not configured, the map size defaults to
15 50 x 50 mm and the page size to A4 portrait. It prepares the template
16 arguments: the application, the subject, the locale with date, time and number
17 formatters, and the ``STRINGS`` dictionary with localized default strings.
18- ``manager``: the template manager (``gws.TemplateManager``), which finds
19 templates by subject and creates templates from file paths.
21Templates are configured in the ``templates`` list of objects such as layers,
22models, finders, projects and the application. The manager looks up a
23template by subject in a list of objects, in the given order, and falls back to
24the application templates. Templates the user may not use, or which cannot
25produce the requested MIME type, are skipped. A template file in an assets
26directory is turned into a template by its extension (``.cx.html``, ``.cx.py``,
27``.qgs`` and others, see ``manager.TEMPLATE_TYPES``).
29Example::
31 {
32 templates [
33 { subject "feature.title" type "html" text "{{name}}" }
34 { subject "feature.description" type "html" path "/data/templates/description.cx.html" }
35 ]
36 }
38Example::
40 tpl = root.app.templateMgr.find_template('feature.description', where=[layer, project], user=user)
41 if tpl:
42 res = tpl.render(gws.TemplateRenderInput(args={'feature': feature}, user=user))
43"""
45from .core import Config, Object, Props
46from . import manager