Skip to content

Commit

Permalink
fix: autocomplete in django 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fdintino committed Jul 11, 2024
1 parent 6470734 commit 32c2455
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 10 additions & 3 deletions nested_admin/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion nested_admin/tests/admin_widgets/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
Expand Down

0 comments on commit 32c2455

Please sign in to comment.