#7415 closed (fixed)
FileFields have wrong url in admin under Windows, when using upload_to path
Reported by: | Owned by: | Marty Alchin | |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Keywords: | windows filefield fs-rf-fixed | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Right now (revision 7612) AdminFileWidget is implemented this way:
if value: output.append('%s <a target="_blank" href="%s%s">%s</a> <br />%s ' % \ (_('Currently:'), settings.MEDIA_URL, value, value, _('Change:')))
The value in database contains \ as a path separator. It is shown as a url instead of needed / separator for urls. Works as is under Unix, but clearly not on Windows.
Model get_<field>_url() method gives the url with correct path separator. Perhaps it should be used in the link instead of value.
Attachments (1)
Change History (19)
comment:1 by , 16 years ago
comment:2 by , 16 years ago
Django creates the file path with '\' itself in database after uploading the file via admin.
comment:3 by , 16 years ago
Description: | modified (diff) |
---|
comment:4 by , 16 years ago
milestone: | → 1.0 |
---|
comment:5 by , 16 years ago
Keywords: | bug added |
---|---|
Triage Stage: | Unreviewed → Accepted |
I guess milestone 1.0 means accepted.
comment:6 by , 16 years ago
Owner: | changed from | to
---|
comment:7 by , 16 years ago
Keywords: | windows filefield added; bug removed |
---|---|
Needs tests: | set |
I fixed it on Windows using 'url.pathname2url()'. See patch.
Could someone test it on other platforms?
comment:8 by , 16 years ago
Triage Stage: | Accepted → Ready for checkin |
---|---|
Version: | newforms-admin → SVN |
comment:9 by , 16 years ago
Has patch: | set |
---|---|
Needs tests: | unset |
comment:11 by , 16 years ago
Keywords: | fs-rf added |
---|---|
milestone: | 1.0 → 1.0 beta |
Needs tests: | set |
Patch needs improvement: | set |
Triage Stage: | Ready for checkin → Accepted |
I'm not sure the proposed patch is the best approach for this, but I'll take a look at this as part of #5361, since most of the affected code is changing as part of that anyway.
comment:12 by , 16 years ago
IMHO, better approach is to always use / as path separator. This guarantees that the filesystem stuff works on different platforms (just getting the value from database and using it for something).
Fixed the same problem with fieldname = fieldname.replace(os.path.sep, "/") on the application side.
comment:13 by , 16 years ago
Keywords: | fs-rf-fixed added; fs-rf removed |
---|---|
Owner: | changed from | to
Status: | new → assigned |
The updated patch on #5361 addresses this issue, explicitly converting all slashes to forward slashes when saving to the database, and doing the same when displaying the URL, just in case older data is stored that way.
comment:14 by , 16 years ago
Cool, I agree that your approach of saving the paths with forward slashes in database is best here. One concern though, will that also work with pre-existing records, which have already been saved with backward slashes?
comment:15 by , 16 years ago
That alone won't solve the problem with existing data, but the conversion to forward slashes now happens when retrieving the URL, so it should all work out quite well. Feel free to give it a shot if you have some time, if you'd like to verify.
comment:16 by , 16 years ago
Correction. The existing patch on #5361 does not yet completely fix this issue. The next patch will have an update to AdminFileWidget
to take care of this properly.
comment:17 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
(In [8244]) File storage refactoring, adding far more flexibility to Django's file handling. The new files.txt document has details of the new features.
This is a backwards-incompatible change; consult BackwardsIncompatibleChanges for details.
Fixes #3567, #3621, #4345, #5361, #5655, #7415.
Many thanks to Marty Alchin who did the vast majority of this work.
As I know, it's better to define all paths with '/' not depending on platform - it is valid. I do so and have no such problem as you described.