Template tags and filters¶

JuliaBase core¶

You use these tags and filter with:

{% load juliabase %}


Tags¶

markdown_hint()

Tag for inserting a short remark that Markdown syntax must be used here, with a link to further information.

input_field(field)

Tag for inserting a field value into an HTML table as an editable field. It consists of two <td> elements, one for the label and one for the value, so it spans two columns. This tag is primarily used in templates of edit views. Example:

{% input_field deposition.number %}

error_list(form, form_error_title, outest_tag='<table>', colspan=1)

Includes a comprehensive error list for one particular form into the page. It is an HTML table, so take care that the tags are nested properly. Its template can be found in the file "error_list.html".

Parameters: form (forms.Form) – the bound form whose errors should be displayed; if None, nothing is generated form_error_title (str) – The title used for general error messages. These are not connected to one particular field but the form as a whole. Typically, they are generated in the is_referentially_valid functions. outest_tag (str) – May be "" or "
", with "" as the default. It is the outmost HTML tag which is generated for the error list. colspan (int) – the width of the table in the number of columns; necessary because those &%\$# guys of WHATWG have dropped colspan=”0”; see http://www.w3.org/Bugs/Public/show_bug.cgi?id=13770

Filters¶

get_really_full_name(user, anchor_type='http')

Unfortunately, Django’s get_full_name method for users returns the empty string if the user has no first and surname set. However, it’d be sensible to use the login name as a fallback then. This is realised here. See also jb_common.utils.get_really_full_name.

The optional parameter to this filter determines whether the name should be linked or not, and if so, how. There are three possible parameter values:

"http" (default)
The user’s name should be linked with his web page on JuliaBase
"mailto"
"plain"
There should be no link, the name is just printed as plain unformatted text.
markdown(value, margins='default')

Filter for formatting the value by assuming Markdown syntax. Embedded HTML tags are always escaped. Warning: You need at least Python Markdown 1.7 or later so that this works.

FixMe: Before Markdown sees the text, all named entities are replaced, see jb_common.utils.substitute_html_entities(). This creates a mild escaping problem. \&amp; becomes &amp;amp; instead of \&amp;. It can only be solved by getting python-markdown to replace the entities, however, I can’t easily do that without allowing HTML tags, too.

fancy_bool(boolean)

Filter for coverting a bool into a translated “Yes” or “No”.

urlquote(value)

Filter for quoting strings so that they can be used as parts of URLs. Note that also slashs »/« are escaped.

Also note that this filter is “not safe” because for example ampersands need to be further escaped.

urlquote_plus(value)

Filter for quoting URLs so that they can be used within other URLs. This is useful for added “next” URLs in query strings, for example:

<a href="{{ process.edit_url }}?next={{ sample.get_absolute_url|urlquote_plus }}"
>{% trans 'edit' %}</a>


Samples¶

You use these tags and filter with:

{% load samples_extras %}


Tags¶

verbose_name(parser, token)

Tag for retrieving the descriptive name for an instance attribute. For example:

{% verbose_name Deposition.pressure %}


will print “pressure”. Note that it will be translated for a non-English user. It is useful for creating labels. The model name may be of any model in any installed app. If two model names collide, the one of the firstly installed app is taken.

value_field(parser, token)

Tag for inserting a field value into an HTML table. It consists of two <td> elements, one for the label and one for the value, so it spans two columns. This tag is primarily used in templates of show views, especially those used to compile the sample history. Example:

{% value_field layer.base_pressure "W" 3 %}


The unit ("W" for “Watt”) is optional. If you have a boolean field, you can give "yes/no" as the unit, which converts the boolean value to a yes/no string (in the current language). For gas flow fields that should collapse if the gas wasn’t used, use "sccm_collapse". If not given but the model field has a unit set (i.e. ...QuantityField), that unit is used.

The number 3 is also optional. However, if it is set, the unit must be at least "". With this option you can set the number of significant digits of the value. The value will be rounded to match the number of significant digits.

split_field(*fields)

Tag for combining two or three input fields wich have the same label and help text. It consists of three or more <td> elements, one for the label and one for the input fields (at least two), so it spans multiple columns. This tag is primarily used in templates of edit views. Example:

{% split_field layer.voltage1 layer.voltage2 %}


The tag assumes that for from–to fields, the field name of the upper limit must end in "_end", and for ordinary multiple fields, the verbose name of the first field must end in a space-separated number or letter. For example, the verbose names may be "voltage 1", "voltage 2", and "voltage 3".

value_split_field(parser, token)

Tag for combining two or more value fields wich have the same label and help text. It consists of two <td> elements, one for the label and one for the value fields, so it spans two columns. This tag is primarily used in templates of show views, especially those used to compile the sample history. Example:

{% value_split_field layer.voltage_1 layer.voltage_2 "V" %}


The unit ("V" for “Volt”) is optional. If you have a boolean field, you can give "yes/no" as the unit, which converts the boolean value to a yes/no string (in the current language). For gas flow fields that should collapse if the gas wasn’t used, use "sccm_collapse". If not given but the model field has a unit set (i.e. ...QuantityField), that unit is used.

Filters¶

round(value, digits)

Filter for rounding a numeric value to a fixed number of significant digits. The result may be used for the quantity() filter below.

quantity(value, unit=None, autoescape=False)

Filter for pretty-printing a physical quantity. It converts 3.4e-3 into $$3.4\cdot10^{-3}$$. The number is the part that is actually filtered, while the unit is the optional argument of this filter. So, you may write:

{{ deposition.pressure|quantity:"mbar" }}


It is also possible to give a list of two values. This is formatted in a from–to notation.

get_really_full_name(user, anchor_type='http')

Unfortunately, Django’s get_full_name method for users returns the empty string if the user has no first and surname set. However, it’d be sensible to use the login name as a fallback then. This is realised here. See also samples.utils.views.get_really_full_name().

The optional parameter to this filter determines whether the name should be linked or not, and if so, how. There are three possible parameter values:

"http" (default)
The user’s name should be linked with his web page on JuliaBase
"mailto"
"plain"
There should be no link, the name is just printed as plain unformatted text.
get_safe_operator_name(user)

Return the name of the operator (with the markup generated by get_really_full_name and the "http" option) unless it is a confidential external operator.

timestamp(value, minimal_inaccuracy=0)

Filter for formatting the timestamp of a process properly to reflect the inaccuracy connected with this timestamp. It works not strictly only for models. In fact, any object with a timestamp field can be passed in. If no timestamp_inaccuracy field is present in the value, 0 (accuracy to the second) is assumed.

Instead of a model instance, a dict objects may be used as the input value. In this case, keys instead of attributes are looked up, but with the same names.

Parameters: value (models.Model or dict mapping str to object) – the model whose timestamp should be formatted minimal_inaccuracy (int) – minimal inaccuracy used for display the rendered timestamp str
markdown_samples(value, margins='default')

Filter for formatting the value by assuming Markdown syntax. Additionally, sample names and sample series names are converted to clickable links. Embedded HTML tags are always escaped. Warning: You need at least Python Markdown 1.7 or later so that this works.

FixMe: Before Markdown sees the text, all named entities are replaced, see samples.utils.views.substitute_html_entities. This creates a mild escaping problem. \&amp; becomes &amp;amp; instead of \&amp;. It can only be solved by getting python-markdown to replace the entities, however, I can’t easily do that without allowing HTML tags, too.

first_upper(value)

Filter for formatting the value to set the first character to uppercase.

sample_tags(sample, user)

Shows the sample’s tags. The tags are shortened. Moreover, they are suppressed if the user is not allowed to view them.

camel_case_to_human_text(value)

See jb_common.utils.base.camel_case_to_human_text for documentation.