Opened 17 years ago
Closed 13 years ago
#5893 closed New feature (fixed)
FilePathField doesn't support folders
Reported by: | Alex Gaynor | Owned by: | Alex Gaynor |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Normal | Keywords: | enhancement |
Cc: | tonightslastsong@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
FilePathField(both the model field and the form field) only allows for selecting files, not folders. I have attached a fix to the problem which adds allow_files and allow_folders options, both of which default to true. This applies to both trunk and newforms-admin(which hasn't updated the FilePathField to use newforms, for whatever reason).
Attachments (14)
Change History (27)
by , 17 years ago
comment:1 by , 17 years ago
Keywords: | enhancement added; new-forms FilePathField removed |
---|---|
Needs documentation: | set |
Needs tests: | set |
Patch needs improvement: | set |
Triage Stage: | Unreviewed → Design decision needed |
Version: | SVN → newforms-admin |
by , 17 years ago
Attachment: | diff.3.diff added |
---|
Cleaned up the if/elif brackets, also appended folders first
by , 17 years ago
Attachment: | diff.4.diff added |
---|
Added an assert to make sure either allow_files or allow_folders is true
comment:2 by , 17 years ago
Component: | Admin interface → django.newforms |
---|---|
Version: | newforms-admin → SVN |
This does not apply to only newforms-admin. This is a newforms and trunk problem that newforms-admin will inherit if it is approved for inclusion.
comment:3 by , 17 years ago
Needs documentation: | unset |
---|---|
Needs tests: | unset |
Patch needs improvement: | unset |
by , 17 years ago
Attachment: | allow_folders.2.diff added |
---|
Now fix_os_paths
is applied to the output of the new tests
comment:4 by , 16 years ago
Owner: | changed from | to
---|
by , 16 years ago
Attachment: | allow_folders.4.diff added |
---|
by , 15 years ago
Attachment: | filepath-folders.diff added |
---|
comment:5 by , 15 years ago
Owner: | changed from | to
---|---|
Triage Stage: | Design decision needed → Accepted |
comment:7 by , 15 years ago
Owner: | changed from | to
---|---|
Patch needs improvement: | set |
Hey Alex -- First, the file containing the new test was just converted to unit tests. Can you convert the new test?
Also I'm not sure about the asserts. For the model field I'd expect that contradiction to be be caught during validation. I see there are a couple of asserts in that file for auto field stuff, but it seems most errors of this sort are caught instead in get_validation_errors
in django/core/management/validate.py. Is there some reason you went with an assert here instead?
For the form field, there are other such nonsensical argument combos that we just don't check for. The user is left with a form that can't ever validate (e.g. IntegerField with max_value lower than min_value), but that's what they asked for. Perhaps not as helpful as we could be, but using assert to catch invalid arg combos passed into Django just doesn't seem to fit in with the rest of the code...is there some reason this case is special and should be handled differently than other similar cases?
comment:9 by , 15 years ago
Cc: | added |
---|
comment:10 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
by , 13 years ago
Attachment: | filepath-flolders-final.diff added |
---|
Final patch (note to others, please don't review/commit; this is an example patch for a "contributing to django" event).
Interesting proposal. My suggestions (apart from the need for docs & tests):
allow_folders
to default toFalse
(to keep the current default behaviour)choices
Patch should also be applied against newforms-admin, which is a bit of a problem since this field hasn't been updated to newforms yet - #5894.