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

aristotle_mdr.templatetags.aristotle_tags.adminEdit(item)[source]

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>
aristotle_mdr.templatetags.aristotle_tags.can_change_status(item, user)[source]

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 calling user_can_supersede throws an exception it safely returns False.

For example:

{% if myItem|can_supersede:request.user %}
  {{ item }}
{% endif %}
aristotle_mdr.templatetags.aristotle_tags.can_edit(item, user)[source]

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 calling user_can_edit throws an exception it safely returns False.

For example:

{% if myItem|can_edit:request.user %}
  {{ item }}
{% endif %}
aristotle_mdr.templatetags.aristotle_tags.can_supersede(item, user)[source]

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 calling user_can_supersede throws an exception it safely returns False.

For example:

{% if myItem|can_supersede:request.user %}
  {{ item }}
{% endif %}
aristotle_mdr.templatetags.aristotle_tags.can_view(item, user)[source]

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 calling user_can_view throws an exception it safely returns False.

For example:

{% if myItem|can_view:request.user %}
  {{ item }}
{% endif %}
aristotle_mdr.templatetags.aristotle_tags.can_view_iter(qs, user)[source]

A filter that is a simple wrapper that applies the aristotle_mdr.models.ConceptManager.visible(user) for use in templates. Filtering on a Django Queryset and passing in the current user as the argument returns a list (not a Queryset at this stage) of only the items from the Queryset 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 %}
aristotle_mdr.templatetags.aristotle_tags.doc(item, field=None)[source]

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.

aristotle_mdr.templatetags.aristotle_tags.downloadMenu(item)[source]

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 %}
aristotle_mdr.templatetags.aristotle_tags.in_workgroup(user, workgroup)[source]

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 calling user_in_workgroup throws an exception it safely returns False.

For example:

{% if request.user|in_workgroup:workgroup %}
  {{ something }}
{% endif %}
aristotle_mdr.templatetags.aristotle_tags.public_standards(regAuth, itemType='aristotle_mdr._concept')[source]

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 %}
aristotle_mdr.templatetags.aristotle_tags.stateToText(state)[source]

This tag takes the integer value of a state for a registration status and converts it to its text equivilent.

aristotle_mdr.templatetags.aristotle_tags.ternary(condition, a, b)[source]

A simple ternary tag - it beats verbose if/else tags in templates for simple strings If the condition is ‘truthy’ return a otherwise return b. For example:

<a class="{% ternary item.is_public 'public' 'private' %}">{{item.name}}</a>
aristotle_mdr.templatetags.aristotle_tags.visible_superseded_by_items(item, user)[source]

Fetch newer items for an older item

aristotle_mdr.templatetags.aristotle_tags.visible_supersedes_items(item, user)[source]

Fetch older items for a newer item

aristotle_mdr.templatetags.aristotle_tags.zws(string)[source]

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>