Draft Object List Template Context
The following additional context variables are available in templates with a scope of Draft Object List, on top of the values listed in Template Context. These Templates are run from the "Actions" menu of a Draft object listing and report on the objects in that listing.
Important
When running document templates in testing from the document template editor there is no listing behind the run, so selected_ids and filtered_ids are empty lists, selected_objects and filtered_objects are empty, search_text is an empty string, filter_labels is an empty list and filter_unlabelled is False. all_objects is the exception: it comes from the Draft rather than the listing, so it is populated in a test run and is the easiest way to see real data while developing a Template.
Important
filtered_ids and filtered_objects account for every filter on the listing, so the objects a report covers are always the ones the user can see. The search_text and filter_labels values below exist so a document can describe how it was filtered, and they only describe those two filters. A listing may have others active — for example the Edit Check list can be filtered by validity and bypass status — and those are not reported individually.
Name |
Description |
Example |
|---|---|---|
draft |
A draft reference. The root object from which Draft properties and sub objects can be accessed. |
Draft {{ draft.DraftName }}
|
object_type |
The name of the Object Type the Template reports on, e.g. "Form". |
Report on one {{ object_type }}
|
object_type_plural |
The plural name of the Object Type, e.g. "Forms". |
{{ object_type_plural }} Report
|
selected_ids |
Database ids of the records the user selected with the row checkboxes, in the order the listing was sorted in. Empty when nothing was selected. |
{{ selected_ids|length }} selected
|
selected_objects |
The selected objects themselves, already restricted to the Template's Object Type. Ordered by the object's own default order (for example Ordinal) rather than the order shown on screen — iterate selected_ids if the on-screen order matters. |
{% for obj in selected_objects %}
{{ obj }}
{% endfor %}
|
filtered_ids |
Database ids of every record matching the search and filters active on the listing — that is, every row the user could see, in the order the listing was sorted in. Not just the selected ones. |
{{ filtered_ids|length }} listed
|
filtered_objects |
The filtered objects themselves, restricted and ordered as selected_objects above. |
{% for obj in filtered_objects %}
{{ obj }}
{% endfor %}
|
all_objects |
Every object of the Template's Object Type in the Draft, whatever the user had selected or filtered to. Use it to report on the whole set and mark the rows the user picked out. For Custom Objects this is the only straightforward route to the type's objects, because draft.customobject_set holds every custom type at once. |
{% for obj in all_objects %}
{{ obj }}{% if obj.id in selected_ids %} *{% endif %}
{% endfor %}
|
search_text |
The contents of the "search" box on the listing the document was generated from. |
Active Search: {{ search_text or 'None' }}
|
filter_labels |
A list of Label names which the listing is being filtered by. Empty list if the listing is not being filtered by Label. |
{{ ", ".join(filter_labels) or 'None' }}
|
filter_unlabelled |
True when the Label filter's "-- No label --" option is selected, which is not a Label name and so does not appear in filter_labels. |
{% if filter_unlabelled %}Unlabelled only{% endif %}
|