[Toaster] DRY RUN [Review Request] 4299 "recipes: View detailed information about a recipe"

Reyna, David david.reyna at windriver.com
Tue Jan 14 22:34:24 PST 2014


Hi Alex,

There is something seriously fragile about Django tags and filters. 

1) When I try to use “simple_tag”, all I get is “Invalid block tag: 'task_outcome_highlight', expected 'empty' or 'endfor', even for the most trivial tag:

@register.filter
def task_outcome_highlight(task)
    return 'class=error'

...and...

{% task_outcome_highlight task %}

2) I then tried filters. I first used a filter out of the Djago docs, and it worked.

WORKS:

@register.filter(name='cut')
def cut(value, arg):
    """Removes all values of arg from the given string"""
    return value.replace(arg, '')

...and...

{{ "1230456"|cut:"0" }}

3) However, if I make change to that filter, for example changing its name, I get nothing but filter format errors.

FAILS (when renamed to "cu"):

@register.filter(name='cu')
def cu (value, arg):
    """Removes all values of arg from the given string"""
    return value.replace(arg, '')

...and...

{{ "1230456"|cu:"0" }}

4) I have tried stopping and starting the server. If I rename the filter back to "cut", it will start working again.

I have spent hours on something that should be done in 10 minutes.

- David

========================

From: Damian, Alexandru [mailto:alexandru.damian at intel.com] 
Sent: Monday, January 13, 2014 5:43 AM
To: Reyna, David
Cc: Lerner, Dave; toaster at yoctoproject.org
Subject: Re: [Toaster] DRY RUN [Review Request] 4299 "recipes: View detailed information about a recipe"

Hi,

I have comments about the content of the patch, as well.
a). models.py; I am not very fond of having display code in the models, because it breaks the MVC separation. The display code should live in the templates, e.g.

    {% if task.outcome == Task.OUTCOME_FAILED %}class=error{% elif %} ... {%endif%}
If this is repeated elsewhere, like in this particular case, you should define a new tag in ./bitbake/lib/toaster/toastergui/templatetags/projecttags.py that returns the code:
@register.simple_tag
def task_outcome_highlight(task):
    if task.outcome == Task.OUTCOME_EXISTING:
        ret = ''
  .... etc ...
and then use it in the template:  {% task_outcome_highlight task %}
b). html format; please don't use tabs; use 4-space instead of a tab; this makes for a nice consistency with the HTML code, and fits the HTML code in page better.

c). recipe.html; please extend "basebuildpage.html" which fills in the breadcrumb and all the layout for viewing pages in a build context. see configvars.html for an example.
d). recipes.html; the latest versions of the basetable_top will automatically generate correct table header based on the context description; please don't include your own table header, but edit the page context  to correctly set the table data; see the build view / build.html as a how-to guide.
Hope this helps,
Alex





More information about the toaster mailing list