Ticket #17549: 17549.patch

File 17549.patch, 3.5 KB (added by Elvard, 2 years ago)

Fixed force_unicode in AdminURLFieldWidget

  • django/contrib/admin/static/admin/css/widgets.css

    diff --git a/django/contrib/admin/static/admin/css/widgets.css b/django/contrib/admin/static/admin/css/widgets.css
    index 0a7012c..3b19353 100644
    a b table p.datetime { 
    225225    padding-left: 0;
    226226}
    227227
     228/* URL */
     229
     230p.url {
     231    line-height: 20px;
     232    margin: 0;
     233    padding: 0;
     234    color: #666;
     235    font-size: 11px;
     236    font-weight: bold;
     237}
     238
     239.url a {
     240    font-weight: normal;
     241}
     242
    228243/* FILE UPLOADS */
    229244
    230245p.file-upload {
  • django/contrib/admin/widgets.py

    diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py
    index 1e0bc2d..bd5f3b0 100644
    a b class AdminURLFieldWidget(forms.TextInput): 
    306306            final_attrs.update(attrs)
    307307        super(AdminURLFieldWidget, self).__init__(attrs=final_attrs)
    308308
     309    def render(self, name, value, attrs=None):
     310        html = super(AdminURLFieldWidget, self).render(name, value, attrs)
     311        if value:
     312            value = force_text(self._format_value(value))
     313            final_attrs = {
     314                'href': value,
     315                'target': '_blank'
     316            }
     317            html = format_html(
     318                '<p class="url">{0} <a {1}>{2}</a><br />{3} {4}</p>',
     319                _('Currently:'), flatatt(final_attrs), value,
     320                _('Change:'), html
     321            )
     322        return html
     323
     324
    309325class AdminIntegerFieldWidget(forms.TextInput):
    310326    class_name = 'vIntegerField'
    311327
  • docs/ref/models/fields.txt

    diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt
    index 02d8453..3bca17d 100644
    a b Like all :class:`CharField` subclasses, :class:`URLField` takes the optional 
    922922:attr:`~CharField.max_length`argument. If you don't specify
    923923:attr:`~CharField.max_length`, a default of 200 is used.
    924924
     925.. versionadded:: 1.5
     926
     927The current value of the field will be displayed as a clickable link above the
     928input widget.
     929
    925930
    926931Relationship fields
    927932===================
  • tests/regressiontests/admin_widgets/tests.py

    diff --git a/tests/regressiontests/admin_widgets/tests.py b/tests/regressiontests/admin_widgets/tests.py
    index 4b11543..bbcb2da 100644
    a b class AdminSplitDateTimeWidgetTest(DjangoTestCase): 
    266266                )
    267267
    268268
     269class AdminURLWidgetTest(DjangoTestCase):
     270    def test_render(self):
     271        w = widgets.AdminURLFieldWidget()
     272        self.assertHTMLEqual(
     273            conditional_escape(w.render('test', '')),
     274            '<input class="vURLField" name="test" type="text" />'
     275        )
     276        self.assertHTMLEqual(
     277            conditional_escape(w.render('test', 'http://example.com')),
     278            '<p class="url">Currently:<a href="http://example.com" target="_blank">http://example.com</a><br />Change:<input class="vURLField" name="test" type="text" value="http://example.com" /></p>'
     279        )
     280
     281    def test_render_idn(self):
     282        w = widgets.AdminURLFieldWidget()
     283        self.assertHTMLEqual(
     284            conditional_escape(w.render('test', 'http://example-äüö.com')),
     285            '<p class="url">Currently:<a href="http://example-äüö.com" target="_blank">http://example-äüö.com</a><br />Change:<input class="vURLField" name="test" type="text" value="http://example-äüö.com" /></p>'
     286        )
     287
     288
    269289class AdminFileWidgetTest(DjangoTestCase):
    270290    def test_render(self):
    271291        band = models.Band.objects.create(name='Linkin Park')
Back to Top