Admin behavior: what is errors.items in change_form.html?

7 views
Skip to first unread message

nazar

unread,
Nov 3, 2008, 2:16:31 PM11/3/08
to Django users
I met some unusual behavior in my project in admin change form with
inlines. There is code in template change_form.html:

{% blocktrans count errors.items|length as counter %}Please correct
the error below.{% plural %}Please correct the errors below.{%
endblocktrans %}

Template can't evaluate 'errors.items' object.

As I saw in code there is no "items" attribute, method or dictionary
key in 'errors'.

Can anybody explain what is this and why it works?

Karen Tracey

unread,
Nov 3, 2008, 3:18:53 PM11/3/08
to django...@googlegroups.com

Looks like a bug.  The '.items' part just shouldn't be there.  As it is no matter whether there is a single or multiple errors the plural message is displayed.  Removing the .items (errors is a list type, not a dictionary) fixes things so that the singular message is displayed when there is only one error to be fixed.

Karen

nazar

unread,
Nov 4, 2008, 7:36:17 AM11/4/08
to Django users
Now I got it!!!

I had TEMPLATE_STRING_IF_INVALID = 'TEMPLATE_STRING_IF_INVALID'

So that 'items' was rendered as 'TEMPLATE_STRING_IF_INVALID' (and I
saw it clearly). And I met the bug, bacause gettext was unable to use
it as int parameter.

Now I cleared this: TEMPLATE_STRING_IF_INVALID = '' and bug
disappeared.

Karen Tracey

unread,
Nov 4, 2008, 8:02:42 AM11/4/08
to django...@googlegroups.com

Yes, the admin rather relies on TEMPLATE_STRING_IF_INVALID being empty.  See:

http://docs.djangoproject.com/en/dev/ref/templates/api/#invalid-template-variables
http://code.djangoproject.com/ticket/3579

However, this particular case is a genuine bug in the admin templates.  Even with an empty TEMPLATE_STRING_IF_INVALID, the wrong message is displayed when there is only one error to be corrected on the page.   I've opened a ticket to get that (and anywhere else in the admin that this construct is used) fixed:

http://code.djangoproject.com/ticket/9514

Karen

Reply all
Reply to author
Forward
0 new messages