add a fieldset.errors dictionary to use in templates

Bug #348288 reported by Felipe 'chronos' Prenholato
4
Affects Status Importance Assigned to Milestone
django-form-utils
Fix Committed
Wishlist
Unassigned

Bug Description

I propose with one patch a change that allow to have a fieldset.errors, that is a dict grouping all errors of fieldset fields.
Example:

form = EnhancedForm({})
for fs in form:
print fs.errors

Example output:
{'category': {'errorlist': [u'This field is required.'], 'label': u'Category'},
 'manufacturer': {'errorlist': [u'This field is required.'], 'label': u'Manufacturer'}}

The great use is in templates:

{% for errors in fieldset.errors.itervalues %}
    {% if forloop.first %}
        <ul class="errors">
    {% endif %}
    <li>{{ errors.label }}: {% for e in errors.errorlist %}{{ e }}{% if not forloop.last %}, {% endif %}{% endfor %}</li>
    {% if forloop.last %}
        </ul>
    {% endif %}
{% endfor %}

I attach the patch and generic template that I using this change.

Revision history for this message
Felipe 'chronos' Prenholato (chronossc) wrote :
Revision history for this message
Felipe 'chronos' Prenholato (chronossc) wrote :
Revision history for this message
Carl Meyer (carljm) wrote :

Good idea. I would prefer to see the fieldset errors be a property calculated on demand rather than assigned at FieldSet creation, but I can easily make that change. Thanks!

Changed in django-form-utils:
importance: Undecided → Wishlist
status: New → Confirmed
Revision history for this message
Carl Meyer (carljm) wrote :

Fixed in trunk r15.

Changed in django-form-utils:
status: Confirmed → Fix Committed
Revision history for this message
artur mwaigaryan (mwai53) wrote :

Bug Descritption:

SyntaxError at /admin/
EOL while scanning string literal (admin.py, line 6)
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.3
Exception Type: SyntaxError
Exception Value:
EOL while scanning string literal (admin.py, line 6)
Exception Location: /usr/local/lib/python2.6/dist-packages/django/utils/importlib.py in import_module, line 35

and here is the admin.py file:
from django.contrib import admin
from django import forms

from form_utils.fields import ClearableFileField

class ClearableFileFieldsAdmin(admin.ModelAdmin):

    def formfield_for_dbfield(self, db_field, **kwargs):
        field =
        super(ClearableFileFieldsAdmin,self).formfield_for_dbfield(
            db_field, **kwargs)
        if isinstance(field, forms.FileField):
            field = ClearableFileField(field)
        return field

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.