Accessing Metadata and Labels

TrialGrid allows Custom Properties (metadata) and Labels to be applied to objects. These can be accessed and included in Document Templates.

Custom Properties (Metadata)

Objects in the Object Model Reference which have a properties method may have associated metadata. The properties attribute surfaces this data as a python dictionary keyed by the lowercase name of the property.

{# Example for getting the value of a custom property called "SDTM Domain" from a set of forms #}
{% for form in draft.als_forms_set.order_by("OID") %}
  Form : {{ form.OID }}
  SDTM Domain : {{ form.properties["sdtm domain"].value }}  {# Note LOWER CASE #}
{% endfor %}

Note that objects may not have a value set for a particular metadata value. In that case the value returned will be "" (empty string) if the custom property exists. If a custom property of that name does not exist (i.e has not been defined for the URL or is mispelled), then the template generation will fail with an error.

One way to avoid an error if a custom property does not exist is to use the .get method and provide a fallback value:

{{ form.properties.get("no such property", {"value":"Doesn't exist"}).value }}

In addition to .value other attributes are also provided:

Name

Type

Description

name

string

The name of the Custom Property (with original case, e.g. "SDTM Domain")

description

string

The description of the Custom Property

display_order

integer

The display order for this Custom Property in relation to other custom properties for this kind of object

value

string

The actual value set for the custom property on this object instance

is_set

boolean

When an object does not have any value set for a custom property the value is returned as "" (empty string). This flag is set to False when there is no value present for the custom property.

value_type

string

One of "choice" or "text"

value_choices

List of string (or None if value_type is not "choice")

The possible values of a choice type (for value_type = "choice" only)

show_in_list

boolean

True if the custom property is set to be shown in object lists, False otherwise

With this information Templates can include lists of the custom properties defined for an object:

{# Use the .values() method of the python dictionary to loop through all the properties available for the object #}
{% for property in draft.Project.properties.values() %}
    <para>{{ property.name }} = {{ property.value }}</para>
    <para>{{ property.description }}</para>
{% endfor %}

Labels

URLs may define Labels which can be applied to objects including Drafts, Projects and Draft Objects (Forms, Edit Checks etc).

Objects which may have associated labels have a labels collection which is a list of ObjectLabels. Each ObjectLabel has a reference to the Label definition so you can get the name, color, description etc:

{% for object_label in draft.Project.labels %}
    <para>{{ object_label.label.name }} has color {{ object_label.label.color }}</para>
    <para>Description {{ object_label.label.description }}</para>
{% endfor %}