Ticket #289: 289_error_list.diff

File 289_error_list.diff, 2.0 KB (added by paulsmith@…, 18 years ago)

error_list template tag

  • django/contrib/admin/templatetags/admin_modify.py

     
    245245        'class_names': " ".join(class_names),
    246246    }
    247247admin_field_line = register.inclusion_tag('admin/field_line.html', takes_context=True)(admin_field_line)
     248
     249def error_list(fields, error_dict):
     250    errors = []
     251    for err_field_name, err_messages in error_dict.items():
     252        error = {}
     253        for field in fields:
     254            if field.name == err_field_name:
     255                error['verbose_name'] = capfirst(field.verbose_name)
     256                error['messages'] = err_messages
     257            elif isinstance(field, models.fields.DateTimeField):
     258                parts = err_field_name.split("_")
     259                if parts[-1] in ["date", "time"] and '_'.join(parts[:-1]) == field.name:
     260                    error['verbose_name'] = capfirst("%s (%s)" % (field.verbose_name, parts[-1]))
     261                    error['messages'] = err_messages
     262        if not error:
     263            raise RuntimeError, "verbose field name error not found for: %s" % err_field_name
     264        errors.append(error)
     265    return {'error_list': errors}
     266error_list = register.inclusion_tag('admin/error_list.html')(error_list)
  • django/contrib/admin/templates/admin/change_form.html

     
    3131    <p class="errornote">
    3232    {% blocktrans count form.error_dict.items|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
    3333    </p>
     34    {% error_list opts.fields form.error_dict %}
    3435{% endif %}
    3536{% for bound_field_set in bound_field_sets %}
    3637   <fieldset class="module aligned {{ bound_field_set.classes }}">
Back to Top