Tags and filters available in aristotle templates¶
A number of convenience tags are available for performing common actions in custom templates.
Include the aristotle template tags in every template that uses them, like so:
{% load aristotle_tags %}
Available tags and filters¶
A tag for easily generating the link to an admin page for editing an item. For example:
<a href="{% adminEdit item %}">Advanced editor for {{item.name}}</a>
A filter that acts as a wrapper around
aristotle_mdr.perms.user_can_edit
. Returns true if the user has permission to edit the item, otherwise it returns False. If callinguser_can_edit
throws an exception it safely returns False.For example:
{% if myItem|can_edit:request.user %} {{ item }} {% endif %}
A filter that acts as a wrapper around
aristotle_mdr.perms.user_can_view
. Returns true if the user has permission to view the item, otherwise it returns False. If callinguser_can_view
throws an exception it safely returns False.For example:
{% if myItem|can_view:request.user %} {{ item }} {% endif %}
A filter that is a simple wrapper that applies the
aristotle_mdr.models.ConceptManager.visible(user)
for use in templates. Filtering on a DjangoQueryset
and passing in the current user as the argument returns a list (not aQueryset
at this stage) of only the items from theQueryset
the user can view.If calling
can_view_iter
throws an exception it safely returns an empty list.For example:
{% for item in myItems|can_view_iter:request.user %} {{ item }} {% endfor %}
A tag for easily generating the link to an admin page for “cloning” an item. For example:
<a href="{% clone item %}">Clone {{item.name}}</a>
Gets the appropriate help text or docstring for a model or field. Accepts 1 or 2 string arguments: If 1, returns the docstring for the given model in the specified app. If 2, returns the help_text for the field on the given model in the specified app.
Returns the complete download menu for a partcular item. It accepts the id of the item to make a download menu for, and the id must be of an item that can be downloaded, otherwise the links will show, but not work.
For example:
{% downloadMenu item %}
A tag for easily generating the link to an admin page for “cloning” an item. For example:
<a href="{% clone item %}">Clone {{item.name}}</a>
A filter that acts as a wrapper around
aristotle_mdr.perms.user_in_workgroup
. Returns true if the user has permission to administer the workgroup, otherwise it returns False. If callinguser_in_workgroup
throws an exception it safely returns False.For example:
{% if request.user|in_workgroup:workgroup %} {{ something }} {% endif %}
This is a filter that accepts a registration Authority and an item type and returns a list of tuples that contain all public items with a status of “Standard” or “Preferred Standard” in that Registration Authority only, as well as a the status object for that Authority.
The item type should consist of the name of the app the item is from and the name of the item itself separated by a period (
.
).This requires the django
django.contrib.contenttypes
app is installed.If calling
public_standards
throws an exception or the item type requested is not found it safely returns an empty list.For example:
{% for item, status in registrationAuthority|public_standards:'aristotle_mdr.DataElement' %} {{ item }} - made standard on {{ status.registrationDate }}. {% endfor %}
This tag takes the integer value of a state for a registration status and converts it to its text equivilent.
A simple ternary tag - it beats verbose if/else tags in templates for simple strings If the
condition
is ‘truthy’ returna
otherwise returnb
. For example:<a class="{% ternary item.is_public 'public' 'private' %}">{{item.name}}</a>
zws
or “zero width space” is used to insert a soft break near em-dashed. Since em-dashs are commonly used in Data Element Concept names, this helps them wrap in the right places.For example:
<h1>{% zws item.name %}</h1>