From 751f7a6d9b29871795aec1c909ac47ba0b5305a3 Mon Sep 17 00:00:00 2001 From: Collin Anderson Date: Sat, 26 Aug 2017 10:32:32 -0400 Subject: [PATCH] Added Media.__repr__(). It makes it easier to debug MediaOrderConflictWarnings (refs #28377). --- django/forms/widgets.py | 3 +++ tests/forms_tests/tests/test_media.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 4bbe6ce052..f306abdec6 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -52,6 +52,9 @@ class Media: self._css = css self._js = js + def __repr__(self): + return 'Media(css=%r, js=%r)' % (self._css, self._js) + def __str__(self): return self.render() diff --git a/tests/forms_tests/tests/test_media.py b/tests/forms_tests/tests/test_media.py index dd10c60d2a..2b73a041be 100644 --- a/tests/forms_tests/tests/test_media.py +++ b/tests/forms_tests/tests/test_media.py @@ -25,6 +25,11 @@ class FormsMediaTestCase(SimpleTestCase): """ ) + self.assertEqual( + repr(m), + "Media(css={'all': ('path/to/css1', '/path/to/css2')}, " + "js=('/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3'))" + ) class Foo: css = {