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.append_asterisk_if_required(field)[source]

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

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

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

For example:

{% if myItem|can_add_status: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.get_status_from_dict(dictionary, current_status, key, with_icon=True)[source]

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.

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.state_to_text(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.user_can_view_statuses_revisions(user, ra)[source]

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 calling user_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 %}
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>