* owner: nobody => adamjforster
* status: new => assigned
* easy: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: adam@… (added)
* has_patch: 0 => 1
Comment:
I have added a patch that outputs readonly FileField (and it's subclasses
such as ImageField) values as links to the download file.
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:7>
* needs_tests: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:9>
Comment (by adamjforster):
I'm not sure how to test this, can someone else take a look?
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:10>
Comment (by akaariai):
You might want to check out the admin's Selenium test cases found from
django/contrib/admin/tests.py. Seems like the perfect fit for testing
this.
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:11>
Comment (by javiersanchez@…):
Let me suggest a small adding. Usually is not necessary to show the
complete path, but just the file name. This is trivial by "import os.path"
and applying "os.path.basename" as below:
return mark_safe(u'<a href="%s">%s</a>'
% (escape(value.url),
os.path.basename(force_unicode(value))))
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:12>
* status: assigned => new
* owner: adamjforster => paulcollins
* needs_tests: 1 => 0
Comment:
@adamjforster I'm grabbing this ticket since you called out for some help
writing tests. Please feel free to grab it back if you'd like. I removed
your check on for value.file, because it causes an IO exception (no such
file) during the unittests. I figured that testing for the actual
existence of the file wasn't really needed to generate the link to the
file.
@akaariai I've added the Selenium tests, but I'm not sure if that's the
fastest way to test that the field is rendering correctly in the admin.
Suggestions?
@javiersanchez I can update the patch for this but that would make this
particular interface inconsistent with the read/write interface. In the
current version the link is rendered the same way, though it's rendered by
different code.
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:13>
Comment (by paulcollins):
After some discussion with Julian I removed the Selenium tests and did
basically the same thing with the django.test.client
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:14>
Comment (by paulcollins):
Updated because julien was getting a unit test failure on his osx machine.
Is there a bug with assertContains(html=True)?
If this passes on his machine then there might be an issue in there. More
when I hear back from julien.
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:15>
* needs_better_patch: 0 => 1
Comment:
Thank you, Paul. I realized the test was failing for me because of the
hardcoded "media/" in the url path. Using the string variable
`STORAGE_URL` fixes that (see patch above).
I've also noticed that the same display logic is used on the changelist
when a file field is in `list_display`. It'd be great to write an extra
test to cover that test. Other than that, the patch looks great!
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:16>
* stage: Accepted => Design decision needed
Comment:
Replying to [comment:16 julien]:
> I've also noticed that the same display logic is used on the changelist
when a file field is in `list_display`.
[[BR]]
Uhoh. So this is something I completely missed. It seems that
display_for_field is implicitly expected to just return a text value, not
an HTML value.
If a read only file field is listed in the `list_display` then in the
admin the link to edit that object vanishes. The HTML ends up looking like
<a href='link to admin page'><a href='link to
file'>filepath/filename</a></a>. Worse, if it's the only thing listed in
`list_display` it leaves the end user no obvious way to go and actually
edit the object.
An icky feeling fix would be to go and put the special case logic for this
in contrib.admin.helpers.AdminReadonlyField.contents which is what's being
called to display it on the modify object page. After some discussion with
julien though, I'm kicking this back to DDN. Maybe at some point the
AdminReadonlyField class will be refactored to allow for this kind of
flexibility.
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:17>
* cc: thepapermen (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:18>
Comment (by anonymous):
+1
this feature would be very helpful
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:19>
Comment (by zout):
+1
Weird it isn't there, please include this in the next minor release
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:20>
Comment (by anonymous):
+1!
Really want to have this feature available!
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:21>
* stage: Design decision needed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:22>
* cc: riccardo.magliocchetti@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:23>
Comment (by paulcollins):
@aaugustin
So I see you've marked this as accepted. I can dig back into this issue
again and see if my horrible hack solution would even still apply here.
Assuming it does is that the direction I should move this in?
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:24>
Comment (by aaugustin):
I marked this ticket as "accepted" when we removed "design decision
needed"; it seemed more appropriate than closing it. But I haven't looked
at the patch.
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:25>
Comment (by synotna):
What needs to happen for this to finally make it into a release?
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:26>
Comment (by timgraham):
Submit a pull request on GitHub and uncheck "Patch needs improvement" so
the ticket appears in the review queue. Then find a friend to review the
patch and mark the ticket as "Ready for checkin".
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:27>
Comment (by rm_):
Opened pull request:
https://github.com/django/django/pull/4040
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:28>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:29>
* cc: cmawebsite@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:30>
* stage: Accepted => Ready for checkin
Comment:
Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:31>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"2be621e44c1b5b68c895383f3e20b1f17ddb447a"]:
{{{
#!CommitTicketReference repository=""
revision="2be621e44c1b5b68c895383f3e20b1f17ddb447a"
Fixed #14497 -- Improved admin widget for "read only" FileFields
Based on patch by Adam J Forster, Paul Collins, and Julien.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:32>
Comment (by Tim Graham <timograham@…>):
In [changeset:"4957b8a40615a082c9218c7c662fb8fccf46b14f"]:
{{{
#!CommitTicketReference repository=""
revision="4957b8a40615a082c9218c7c662fb8fccf46b14f"
[1.8.x] Fixed #14497 -- Improved admin widget for "read only" FileFields
Based on patch by Adam J Forster, Paul Collins, and Julien.
Backport of 2be621e44c1b5b68c895383f3e20b1f17ddb447a from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:33>
Comment (by Tim Graham <timograham@…>):
In [changeset:"07cfe1bd822f4108b5029aef1615a17000d0b0dc"]:
{{{
#!CommitTicketReference repository=""
revision="07cfe1bd822f4108b5029aef1615a17000d0b0dc"
Refs #14497 -- Handled empty readonly admin FileFields
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:34>
Comment (by Tim Graham <timograham@…>):
In [changeset:"343c0875338128dad162d4806fe908fb31404d14"]:
{{{
#!CommitTicketReference repository=""
revision="343c0875338128dad162d4806fe908fb31404d14"
[1.8.x] Refs #14497 -- Handled empty readonly admin FileFields
Backport of 07cfe1bd822f4108b5029aef1615a17000d0b0dc from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:35>
Comment (by collinanderson):
I also discovered that this takes precedence over list_display_links, but
I think I like the new behavior.
--
Ticket URL: <https://code.djangoproject.com/ticket/14497#comment:36>