#14039: FileField special-casing breaks MultiValueField including a FileField
--------------------+-------------------------------------------------------
 Reporter:  carljm  |       Owner:  carljm    
   Status:  new     |   Milestone:            
Component:  Forms   |     Version:  SVN       
 Keywords:          |       Stage:  Unreviewed
Has_patch:  0       |  
--------------------+-------------------------------------------------------
 There are a couple places where !FileField is special-cased using {{{
 isinstance }}} in the forms code: specifically, in
 [[http://code.djangoproject.com/browser/django/trunk/django/forms/forms.py#L280
 BaseForm._clean_fields]], a !FileField's clean method is passed the
 initial value as well as the data, and in
 [[http://code.djangoproject.com/browser/django/trunk/django/forms/forms.py#L438
 BoundField.as_widget ]] the initial value is used as the rendered data
 even when the form is bound.

 This handling of !FileFields is correct, and makes them behave more
 naturally with redisplayed bound forms. But, as usual, the use of {{{
 isinstance }}} makes things more brittle than necessary. Specifically, in
 [[http://bitbucket.org/carljm/django-form-utils django-form-utils]] I've
 implemented a !ClearableFileField via !MultiValueField and !MultiWidget
 (because the !ClearableFileField contains both a !FileField and a checkbox
 for clearing it). The isinstance special-casing means the
 !ClearableFileField can't get the right behavior to parallel a !FileField
 (because it's not a !FileField subclass, it's a !MultiValueField subclass
 containing a !FileField).

 It would be better if the special !FileField behavior were implemented
 with a class attribute flag or a polymorphic method on Field, rather than
 an {{{ isinstance }}} check, so that any field could trigger the
 appropriate behavior regardless of its inheritance ancestry.

 (This is obviously low priority, not expecting anyone else to work on it,
 just recording it here as a I may find some time to work on a patch).

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14039>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to