rdmo
rdmo copied to clipboard
Within Django views, implement conditions with "vectorized" variables
Description / Beschreibung
The Django-language allows defining conditions based on variables's values or on variables being empty.
That does not work for variables which can accept a vector of values.
Expected behaviour / Erwartetes Verhalten
A syntaxe such as {% if var %}
or {% if var.is_not.empty %}
or {% if var|length > 0 %}
should work correctly even if var
is allowed to be a collection.
These conditions should be evaluated as False
if the variable is empty and as True
if the variable has 1,2,3,... components.
Steps to reproduce / Schritte zum Reproduzieren
{% load view_tags %}
{% get_set 'project/dataset/id' as datasets %}
{% get_set 'project/partner/id' as partners %}
{% get_set 'project/funder/id' as funders %}
{% for dataset in datasets %}
{% get_set_value dataset 'project/dataset/preservation/repository_arrangements' as repository_arrangements %}
<p><i>Dataset {{ dataset.value }}:</i>
{% if repository_arrangements %}
Number of arrangements: {{ repository_arrangements|length }}
{% else %}
Empty List
{% endif %}
</p>
<p>{{ repository_arrangements }}</p>
{% endfor %}