jazzband / django-floppyforms

Full control of form rendering in the templates.
http://django-floppyforms.readthedocs.org/
Other
839 stars 145 forks source link

Fields that don't directly inherit from django Field are broken #132

Closed levic closed 9 years ago

levic commented 10 years ago

The definition for DateTimeField is

class Field(forms.Field):
    widget = TextInput
    hidden_widget = HiddenInput

class DateTimeField(Field, forms.DateTimeField):
    widget = DateTimeInput

The problem is that django's DateTimeField overrides to_python().

Because floppyforms.Field is first in the inheritance hierarchy, the to_python() from djangoforms.Field wins over djangoforms.DateTimeField which means that you never end up with a submitted date value converted to a datetime object (and then validation fails)

I think floppyforms.Field should be a mixin and not inherit from anything

Gagaro commented 10 years ago

I think there may be the same issue for CheckboxInput widget (the only one inheriting from 2 classes). That may be why its __init__ and value_from_datadict are copy/pasted from the original one. (value_from_datadict is actually a bit different).

Gagaro commented 10 years ago

I just realized widgets are actually a bit trickier because Input is actually quite different from the django one.

gregmuellegger commented 9 years ago

Hi, I added some tests to the testsuite to check how the cleaning of the DateTimeField works. Please see this commit: https://github.com/gregmuellegger/django-floppyforms/commit/e78a32f58f88166cccc693fc7e0c744ac498c606

The test passes this test so I cannot verify your concerns. I also checked in the console the following:

In [1]: import floppyforms as forms

In [2]: forms.DateTimeField.mro()
Out[2]: 
[floppyforms.fields.DateTimeField,
 floppyforms.fields.Field,
 django.forms.fields.DateTimeField,
 django.forms.fields.BaseTemporalField,
 django.forms.fields.Field,
 object]
In [3]: forms.CheckboxInput.mro()
Out[3]: 
[floppyforms.widgets.CheckboxInput,
 floppyforms.widgets.Input,
 floppyforms.widgets.Widget,
 django.forms.widgets.CheckboxInput,
 django.forms.widgets.Widget,
 django.forms.widgets.NewBase,
 object]

So it seems that the method-resolution-order is correct and doesn't impose the problem you were expecting to be the root of your problem. So I think we can exclude this as a reason for your problem, but maybe we need to investigate further.

Do you have more details about your issue? With what version of django-floppyforms did you test this?

gregmuellegger commented 9 years ago

I'm closing off this issue because I don't have enough information to reproduce. Please feel free to re-open it if you this still bugs you.