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 13, 2024
1 parent 623c5ba commit 03a0d93
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
15 changes: 11 additions & 4 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 @@ -23,17 +24,23 @@ class MediaOrderConflictWarning(RuntimeWarning):
MergeSafeMedia = django.forms.Media

try:
from django.utils.topological_sort import (
from django.utils.topological_sort import ( # noqa: F401
CyclicDependencyError,
stable_topological_sort,
)

has_topological_sort = True
except ImportError:
try:
from django.forms.widgets import TopologicalSorter # noqa: F401
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 03a0d93

Please sign in to comment.