From c19b56f633e172b3c02094cbe12d28865ee57772 Mon Sep 17 00:00:00 2001 From: Johannes Hoppe Date: Thu, 20 Jul 2017 17:06:30 +0200 Subject: Fixed #28377 -- Made combining form Media retain relative asset order. Thanks Florian Apolloner, Mariusz Felisiak, and Tim Graham for reviews. --- docs/releases/2.0.txt | 5 +++++ docs/topics/forms/media.txt | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) (limited to 'docs') diff --git a/docs/releases/2.0.txt b/docs/releases/2.0.txt index 81162e549f..d90b80124d 100644 --- a/docs/releases/2.0.txt +++ b/docs/releases/2.0.txt @@ -554,6 +554,11 @@ Miscellaneous * Renamed ``BaseExpression._output_field`` to ``output_field``. You may need to update custom expressions. +* In older versions, forms and formsets combine their ``Media`` with widget + ``Media`` by concatenating the two. The combining now tries to :ref:`preserve + the relative order of elements in each list `. + ``MediaOrderConflictWarning`` is issued if the order can't be preserved. + .. _deprecated-features-2.0: Features deprecated in 2.0 diff --git a/docs/topics/forms/media.txt b/docs/topics/forms/media.txt index 0bdf237a21..b98cc9e740 100644 --- a/docs/topics/forms/media.txt +++ b/docs/topics/forms/media.txt @@ -305,6 +305,42 @@ specified by both:: +.. _form-media-asset-order: + +Order of assets +--------------- + +The order in which assets are inserted into the DOM if often important. For +example, you may have a script that depends on jQuery. Therefore, combining +``Media`` objects attempts to preserve the relative order in which assets are +defined in each ``Media`` class. + +For example:: + + >>> from django import forms + >>> class CalendarWidget(forms.TextInput): + ... class Media: + ... js = ('jQuery.js', 'calendar.js', 'noConflict.js') + >>> class TimeWidget(forms.TextInput): + ... class Media: + ... js = ('jQuery.js', 'time.js', 'noConflict.js') + >>> w1 = CalendarWidget() + >>> w2 = TimeWidget() + >>> print(w1.media + w2.media) + + + + + +Combining ``Media`` objects with assets in a conflicting order results in a +``MediaOrderConflictWarning``. + +.. versionchanged:: 2.0 + + In older versions, the assets of ``Media`` objects are concatenated rather + than merged in a way that tries to preserve the relative ordering of the + elements in each list. + ``Media`` on Forms ================== -- cgit v1.3