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>
Add an asterisk symbol to the required fields of a form.
Usage:
{{ field | append_asterisk_if_required }}Thanks to Moses Koledoye: https://stackoverflow.com/questions/37389855/django-label-tag-required-asterisk
A filter that acts as a wrapper around
aristotle_mdr.perms.user_can_add_status
. Returns true if the user has permission to change status the item, otherwise it returns False. If callinguser_can_add_status
throws an exception it safely returns False.For example:
{% if myItem|can_add_status:request.user %} {{ item }} {% endif %}
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_supersede
. Returns true if the user has permission to supersede the item, otherwise it returns False. If callinguser_can_supersede
throws an exception it safely returns False.For example:
{% if myItem|can_supersede: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 %}
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 %}
Get the Status of a particular item from a dictionary mapping. :param dictionary: dictionary mapping that must contain key-value pairs where the key must correspond to the concept_id, and the value must correspond to the state id. :param current_status: string that represents the numerical form of the status object that belongs to the Data Element. :param key: string that represents the concept id to be looked up. :param with_icon: boolean value to add a Fontawesome icon. :return: HTML with the name of the corresponding status state.
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>
A filter that is a simple wrapper that applies the
aristotle_mdr.perms.user_can_view_statuses_revisions
Returns true if the user has permission to view the statuses reversion history, otherwise it returns False. If callinguser_can_view
throws an exception it safely returns False.If calling
user_can_view_statuses_revisions
throws an exception it safely returns False.For example:
{% if request.user|user_can_view_statuses_revisions:ra %} {{ item }} {% endif %}
Fetch newer items for an older item
Fetch older items for a newer item
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>