diff --git a/django/contrib/admin/util.py b/django/contrib/admin/util.py
index 61182a6..ba94280 100644
a
|
b
|
def display_for_field(value, field):
|
329 | 329 | return formats.number_format(value, field.decimal_places) |
330 | 330 | elif isinstance(field, models.FloatField): |
331 | 331 | return formats.number_format(value) |
| 332 | elif isinstance(field, models.FileField): |
| 333 | return mark_safe(u'<a href="%s">%s</a>' |
| 334 | % (escape(value.url), |
| 335 | escape(force_unicode(value)))) |
332 | 336 | else: |
333 | 337 | return smart_unicode(value) |
334 | 338 | |
diff --git a/tests/regressiontests/admin_widgets/readonly_widgetadmin.py b/tests/regressiontests/admin_widgets/readonly_widgetadmin.py
new file mode 100644
index 0000000..83d24a6
-
|
+
|
|
| 1 | """ |
| 2 | |
| 3 | """ |
| 4 | from __future__ import absolute_import |
| 5 | |
| 6 | from django.contrib import admin |
| 7 | |
| 8 | from . import models |
| 9 | |
| 10 | |
| 11 | class WidgetAdmin(admin.AdminSite): |
| 12 | pass |
| 13 | |
| 14 | class AlbumAdmin(admin.ModelAdmin): |
| 15 | readonly_fields = ('cover_art',) |
| 16 | |
| 17 | site = WidgetAdmin(name='rowidget-admin') |
| 18 | |
| 19 | site.register(models.Member) |
| 20 | site.register(models.Band) |
| 21 | site.register(models.Album, AlbumAdmin) |
diff --git a/tests/regressiontests/admin_widgets/tests.py b/tests/regressiontests/admin_widgets/tests.py
index 87e0309..8dc3aae 100644
a
|
b
|
from django.utils.unittest import TestCase
|
18 | 18 | |
19 | 19 | from . import models |
20 | 20 | from .widgetadmin import site as widget_admin_site |
| 21 | from django.test.client import Client |
21 | 22 | |
22 | 23 | |
23 | 24 | admin_media_prefix = lambda: { |
… |
… |
class AdminFileWidgetTest(DjangoTestCase):
|
281 | 282 | ) |
282 | 283 | |
283 | 284 | |
| 285 | class ReadOnlyAdminFileWidget(DjangoTestCase): |
| 286 | fixtures = ['admin-widgets-users.xml'] |
| 287 | urls = "regressiontests.admin_widgets.urls" |
| 288 | |
| 289 | def test_fileupload(self): |
| 290 | """File widgets should render as a link when they're marked Read Only |
| 291 | """ |
| 292 | |
| 293 | band = models.Band.objects.create(name='Linkin Park') |
| 294 | album = band.album_set.create( |
| 295 | name='Hybrid Theory', cover_art=r'albums\hybrid_theory.jpg' |
| 296 | ) |
| 297 | client = Client() |
| 298 | client.login(username='super', password='secret') |
| 299 | resp = client.get('/ro-admin/admin_widgets/album/%s/' % album.id) |
| 300 | self.assertContains(resp, |
| 301 | '<a href="/media/albums/hybrid_theory.jpg">albums\hybrid_theory.jpg</a>', |
| 302 | html=True) |
| 303 | self.assertNotContains(resp, |
| 304 | '<input type="file" name="cover_art" id="id_cover_art" />', |
| 305 | html=True) |
| 306 | |
| 307 | |
284 | 308 | class ForeignKeyRawIdWidgetTest(DjangoTestCase): |
285 | 309 | def test_render(self): |
286 | 310 | band = models.Band.objects.create(name='Linkin Park') |
diff --git a/tests/regressiontests/admin_widgets/urls.py b/tests/regressiontests/admin_widgets/urls.py
index aecee90..73b1981 100644
a
|
b
|
from __future__ import absolute_import
|
2 | 2 | |
3 | 3 | from django.conf.urls import patterns, include |
4 | 4 | |
5 | | from . import widgetadmin |
| 5 | from . import widgetadmin, readonly_widgetadmin |
6 | 6 | |
7 | 7 | |
8 | 8 | urlpatterns = patterns('', |
9 | 9 | (r'^', include(widgetadmin.site.urls)), |
| 10 | (r'^ro-admin/', include(readonly_widgetadmin.site.urls)), |
10 | 11 | ) |