The main view in my (toy!) Todo app is, of course, to display the list of tasks. These are grouped by some criterion, and the tasks
structure below is actually a list of pairs (header, list of tasks).
{% for tasks in tasks %}
<p class="list-header">{{ tasks.0 }}:</p>
<ul>
{% for t in tasks.1 %}
<li>
<span class="
{% if t.priority >= 1 %}prio-medium{% endif %}
{% if t.priority >= 2 %}prio-high{% endif %}
">
{{ t.description }}
</span>
{% if t.due_date %}
due,
<span class="
{% if t.days_to_due_date < 15 %}date-soon{% endif %}
{% if t.days_to_due_date < 3 %}date-very-soon{% endif %}
{% if t.days_to_due_date < 0 %}date-overdue{% endif %}
">
{{ t.relative_due_date }}
</span>
{% endif %}
-
{% if not t.done %}
<a href="/yata/{{ t.id }}/mark_done/">Done!</a>
{% else %}
<a href="/yata/{{ t.id }}/mark_not_done/">Not done!</a>
{% endif %}
-
<a href="/yata/{{ t.id }}/edit/">Edit</a>
</li>
{% endfor %}
</ul>
{% empty %}
<p class="list-header">Cool! Nothing to do...</p>
{% endfor %}
In particular, I'm wondering if deciding which CSS class to assign is considered to be the view function's role, or if it's correct to put it in the template.
Similarly, I'm also wondering about the presence of several URLs in the template. Would they be better in the tasks
structure itself? Or should they be provided through some methods in the Task
class? After all, relative_due_date
is already a function that's only used for display (it returns a string like 'Yesterday', 'Tomorrow' or 'In 3 days'). And shouldn't I use reverse()
?