HiveBrain v1.2.0
Get Started
← Back to all entries
patterncssdjangoMinor

Todo app for displaying a list of tasks

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
appdisplayingtasksforlisttodo

Problem

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 %}
    {{ tasks.0 }}:
    
    {% for t in tasks.1 %}
        
            = 1 %}prio-medium{% endif %}
                {% if t.priority >= 2 %}prio-high{% endif %}
                ">
                {{ t.description }}
            
            {% if t.due_date %}
                due, 
                
                    {{ t.relative_due_date }}
                
            {% endif %}
            - 
            {% if not t.done %}
                Done!
            {% else %}
                Not done!
            {% endif %}
            - 
            Edit
        
    {% endfor %}
    
{% empty %}
    Cool! Nothing to do...
{% 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()?

Solution

-
I would suggest moving the CSS selection logic to a custom template tag or even a filter, e.g. {{ t.relative_due_date }}. After that your templates will look much cleaner and that logic would still belong to the presentation part of MVT (Model, View, Template).

-
You can split your tuple in the definition of the loop so that you don't redefine the tasks variable. {% for header, task_list in tasks %} ....

-
Use reverse URLs, no question about it. You'd hate the day you have to change them otherwise :) Go even further, use URL namespaces.

Context

StackExchange Code Review Q#746, answer score: 5

Revisions (0)

No revisions yet.