django.forms grievances - funkybob/django-reformation GitHub Wiki

Form

  • File and non-file data is handled separately. The separation is due to the similarly poor request.POST request.FILES request.GET API.

  • Repeated view boilerplate.

      def view(request):
        if request.method == 'POST':
          form1 = Form1(request.POST, request.FILES)
          form2 = Form2(request.POST, request.FILES)
          is_valid = (form1.is_valid(), form2.is_valid())
          if is_valid():
            foo = form1.save(commit=False)
            foo.bar = form2.save()
            foo.save()
            ...
        else:
          form1 = Form1()
          form2 = Form2()
        ...
    
  • With any non-trivial project, you'll probably use multiple Form classes to divide up a complicated form. Validating the separate pieces within a view introduces lots of boilerplate.

  • Cross-form validation is awkward and not really supported.

  • Should validation go in the model or the form? It's not really clear.

Field

  • required differs in name from Widget.is_required
  • .validate() vs .run_validators()
  • .clean() does not take an initial argument, except for FileField
  • .prepare_value() is very generic, and is only used in one field. If we are to think of a field as being a data container + validator, perhaps it would make sense for .prepare_value() to be amalgamated into Widget?

MultiValueField

  • Required validation is applied indiscriminately to the fields, this makes optional fields impossible.
  • Validation is embedded within .clean(), rather than being part of .validate() or .run_validators()
  • .validate() has been overwritten with blank implementation

Widget

  • .value_from_datadict() is sometimes used to do to_python() style processing (e.g. CheckboxInput)
  • It's not obvious where marshaling functionality should be performed.
  • Most widgets have horrible templating embedded within their .render()

HiddenInput

  • errors for hidden inputs are hard-coded to render as "(Hidden field %(fieldname)s) %s(error)s)"

Media

  • Does not support anything other then CSS/JS. What about JavaScript templates?
  • Does not support inline JS or CSS, only files.

FileField

  • Special-cased by Form to pass initial argument.