diff --git a/nested_admin/compat.py b/nested_admin/compat.py index 270b898..41642a1 100644 --- a/nested_admin/compat.py +++ b/nested_admin/compat.py @@ -4,6 +4,7 @@ See https://github.com/django/django/commit/c19b56f633e172b3c02094cbe12d28865ee57772 and https://code.djangoproject.com/ticket/28377 """ + from collections import defaultdict, OrderedDict import warnings @@ -27,13 +28,19 @@ class MediaOrderConflictWarning(RuntimeWarning): CyclicDependencyError, stable_topological_sort, ) + + has_topological_sort = True except ImportError: + try: + from django.forms.widgets import TopologicalSorter + except ImportError: + has_topological_sort = False + else: + has_topological_sort = True class CyclicDependencyError(ValueError): pass - stable_topological_sort = None - class OrderedSet(_OrderedSet): def __sub__(self, other): @@ -46,7 +53,7 @@ def __repr__(self): return "OrderedSet(%r)" % list(self) -if MergeSafeMedia is None or stable_topological_sort is None: +if MergeSafeMedia is None or not has_topological_sort: def linearize_as_needed(l, dependency_graph): # Algorithm: DFS Topological sort diff --git a/nested_admin/tests/admin_widgets/tests.py b/nested_admin/tests/admin_widgets/tests.py index 8f4527f..1a65e14 100644 --- a/nested_admin/tests/admin_widgets/tests.py +++ b/nested_admin/tests/admin_widgets/tests.py @@ -406,7 +406,11 @@ def test_nested_autocomplete_extra(self): self.add_inline([0, 1, [0]]) select_field = self.get_field("fk3", indexes=[0, 1, [0, 0]]) select_parent = select_field.find_element(By.XPATH, "parent::*") - select_parent.click() + self.selenium.execute_script( + "return arguments[0].querySelector('.select2-selection') || arguments[0]", + select_parent + ).click() + select2_is_active = self.selenium.execute_script( 'return $(".select2-search__field").length > 0' )