diff options
| author | Nick Pope <nick@nickpope.me.uk> | 2021-03-08 13:27:19 +0000 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-01-19 06:33:39 +0100 |
| commit | 1e62a6420230c512b78433265ae8003f27c6eaeb (patch) | |
| tree | dddc821551c833a46958c03ba2d797f7475edf52 /django/forms | |
| parent | 1282b5e4207440af659ef0e0e0c486fdfba8e7b7 (diff) | |
Refs #32528 -- Simplified Media.merge().
This avoids building up a second datastructure for the duplicate files
warning case and simply flatten and strip duplicates if that case ever
arises.
Diffstat (limited to 'django/forms')
| -rw-r--r-- | django/forms/widgets.py | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/django/forms/widgets.py b/django/forms/widgets.py index a1c67bb863..a53569c5a3 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -12,7 +12,6 @@ from itertools import chain from django.forms.utils import to_current_timezone from django.templatetags.static import static from django.utils import formats -from django.utils.datastructures import OrderedSet from django.utils.dates import MONTHS from django.utils.formats import get_format from django.utils.html import format_html, html_safe @@ -152,16 +151,10 @@ class Media: global or in CSS you might want to override a style. """ ts = TopologicalSorter() - all_items = OrderedSet() - for list_ in filter(None, lists): - head = list_[0] - # The first items depend on nothing but have to be part of the - # dependency graph to be included in the result. - ts.add(head) - for item in list_: - all_items.add(item) - # No self dependencies - if head != item: + for head, *tail in filter(None, lists): + ts.add(head) # Ensure that the first items are included. + for item in tail: + if head != item: # Avoid circular dependency to self. ts.add(item, head) head = item try: @@ -173,7 +166,7 @@ class Media: ), MediaOrderConflictWarning, ) - return list(all_items) + return list(dict.fromkeys(chain.from_iterable(filter(None, lists)))) def __add__(self, other): combined = Media() |
