Ticket #7415: 7415-filefield-url-admin-windows.diff

File 7415-filefield-url-admin-windows.diff, 1.9 KB (added by Julien Phalip, 16 years ago)

Patch and tests

  • django/django/contrib/admin/widgets.py

     
    33"""
    44
    55import copy
     6import urllib
    67
    78from django import newforms as forms
    89from django.newforms.widgets import RadioFieldRenderer
     
    8889        from django.conf import settings
    8990        output = []
    9091        if value:
    91             output.append('%s <a target="_blank" href="%s%s">%s</a> <br />%s ' % \
    92                 (_('Currently:'), settings.MEDIA_URL, value, value, _('Change:')))
     92            output.append('%s <a target="_blank" href="%s">%s</a> <br />%s ' % \
     93                (_('Currently:'), urllib.pathname2url('%s%s' % (settings.MEDIA_URL, value)), value, _('Change:')))
    9394        output.append(super(AdminFileWidget, self).render(name, value, attrs))
    9495        return mark_safe(u''.join(output))
    9596
  • django/tests/regressiontests/admin_widgets/models.py

     
    5050>>> print conditional_escape(w.render('test', 'test'))
    5151Currently: <a target="_blank" href="%(MEDIA_URL)stest">test</a> <br />Change: <input type="file" name="test" />
    5252
     53In Windows, make sure that backward slashes are turned into forward slashes in the url.
     54>>> w = AdminFileWidget()
     55>>> print conditional_escape(w.render('testname', 'path\\\\file'))
     56Currently: <a target="_blank" href="%(MEDIA_URL)spath/file">path\\file</a> <br />Change: <input type="file" name="testname" />
     57
    5358>>> band = Band.objects.create(pk=1, name='Linkin Park')
    5459>>> album = band.album_set.create(name='Hybrid Theory')
    5560
Back to Top