Skip to content

Commit

Permalink
Fix bug #38 unionlistfilter
Browse files Browse the repository at this point in the history
  • Loading branch information
GigiusB committed Mar 15, 2024
2 parents cd9d6ce + 17c261d commit d4f53d5
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.4.2
current_version = 2.4.3
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<release>\d+)
serialize = {major}.{minor}.{release}
commit = False
Expand Down
7 changes: 6 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Release 2.4.3
=============
* Fixes bug in UnionListFilter


Release 2.4.2
=============
* Added compatibility with Django 5
Expand All @@ -7,7 +12,7 @@ Release 2.4.2

Release 2.4.1
=============
* Fixes bug in AutiCompleteFilter
* Fixes bug in AutoCompleteFilter


Release 2.4
Expand Down
2 changes: 1 addition & 1 deletion src/adminfilters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
NAME = "django-adminfilters"
VERSION = __version__ = "2.4.2"
VERSION = __version__ = "2.4.3"
__author__ = "sax"
15 changes: 13 additions & 2 deletions src/adminfilters/multiselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ class MultipleSelectFieldListFilter(SmartFieldListFilter):
def __init__(self, field, request, params, model, model_admin, field_path):
self.lookup_kwarg = "%s_filter" % field_path
self.filter_statement = "%s" % field_path
self.lookup_val = params.pop(self.lookup_kwarg, None)


# self.lookup_val = params.pop(self.lookup_kwarg, None)

self._params = params
self.lookup_val = self.get_parameters(self.lookup_kwarg, pop=True)

self.lookup_choices = field.get_choices(include_blank=False)
super().__init__(field, request, params, model, model_admin, field_path)
self.used_parameters[self.lookup_kwarg] = prepare_lookup_value(
Expand Down Expand Up @@ -92,12 +98,17 @@ class UnionFieldListFilter(MultipleSelectFieldListFilter):
contains one of the selected filters.
"""

# def __init__(self, *args, **kwargs):
# self._params = params
# self.lookup_val = self.get_parameters(self.lookup_kwarg, pop=True)
# super().__init__(*args, **kwargs)

def get_field(self):
try:
field = super().get_field()
except AttributeError: # pragma: no cover
if hasattr(self.field, "choices") and self.field.choices:
field = self.field # It's a *Field with choises
field = self.field # It's a *Field with choices
else:
raise AttributeError(
"Multiselect field must be a FK or any type with choices"
Expand Down
3 changes: 2 additions & 1 deletion tests/demoapp/demo/management/commands/init_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def sample_data():

acdc = BandFactory(name="AC/DC", active=True)
geordie = BandFactory(name="Geordie", active=False)
abba = BandFactory(name="Abba", active=True)

ArtistFactory(
name="Angus",
Expand Down Expand Up @@ -89,7 +90,7 @@ def sample_data():
year_of_birth=1946,
favourite_city=milano,
active=False,
bands=[acdc],
bands=[abba],
country=uk,
flags={"full_name": "Bon Scott"},
)
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_f_querystring.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_elements(selenium):
"query,negated,check",
[
("name=Angus", False, lambda cl: len(cl.rows) == 1),
("bands__name=AC/DC", False, lambda cl: len(cl.rows) == 5),
("bands__name=AC/DC", False, lambda cl: len(cl.rows) == 4),
(
"bands__name=AC/DC",
True,
Expand Down
64 changes: 16 additions & 48 deletions tests/functional/test_f_unionlistfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,51 +21,19 @@
@pytest.mark.selenium
def test_unionlist_filter(admin_factory):
site = admin_factory('UnionFieldListFilters')
site.driver.find_elements(By.CSS_SELECTOR, '<details>[data-filter-title~="Bands"]')

print(1)
print(1)

# __, select2, *__ = get_elements(site.driver)
# select2.click()
# __, __, input_text, __ = get_elements(site.driver)
# input_text.send_keys("United K")
# admin_site.wait_and_click(By.XPATH, '//li[contains(text(), "United Kingdom")]')
# *__, cl = get_elements(admin_site.driver)
# assert set(cl.get_values(None, 5)) == {"United Kingdom"}
# el = admin_site.driver.find_elements(By.ID, "select2-ac_country-container")
# assert 'United Kingdom' in el[0].text

#
# @pytest.mark.selenium
# def test_linked_autocomplete(admin_site):
# __, select2, *__ = get_elements(admin_site.driver)
# select2.click()
# __, __, input_text, __ = get_elements(admin_site.driver)
# input_text.send_keys("United K")
# admin_site.wait_and_click(By.XPATH, '//li[contains(text(), "United Kingdom")]')
# *__, cl = get_elements(admin_site.driver)
# assert set(cl.get_values(None, 5)) == {"United Kingdom"}
# el = admin_site.driver.find_elements(By.ID, "select2-ac_country-container")
# assert 'United Kingdom' in el[0].text
#
# country, region, city = get_linked_ac(admin_site.driver)
# assert country and not (region or city), "Others should be disabled"
# country[1].click()
# country, region, city = get_linked_ac(admin_site.driver)
# country[2].send_keys("Aus")
# admin_site.wait_and_click(By.XPATH, '//li[contains(text(), "Australia")]')
# country, region, city = get_linked_ac(admin_site.driver)
# assert country and region and not city, "Only city should be disabled"
#
# region[1].click()
# country, region, city = get_linked_ac(admin_site.driver)
# region[2].send_keys("Cap")
# admin_site.wait_and_click(By.XPATH, '//li[contains(text(), "Australian Capital Territory")]')
# country, region, city = get_linked_ac(admin_site.driver)
# assert country and region and city, "All should be there"
#
# city[1].click()
# country, region, city = get_linked_ac(admin_site.driver)
# city[2].send_keys("Cam")
# admin_site.wait_and_click(By.XPATH, '//li[contains(text(), "Camberra")]')
site.wait_and_click(
By.XPATH,
'//*[@id="changelist-filter"]//a[contains(text(), "AC/DC")]'
)
site.wait_for(By.XPATH, '//*[@id="result_list"]/tbody/tr')
assert len(
site.driver.find_elements(By.XPATH, '//*[@id="result_list"]/tbody/tr')
) == 4, 'Should have 5 artists selected'
site.wait_for(By.XPATH, '//*[@id="result_list"]/tbody/tr')
site.wait_and_click(
By.XPATH,
'//*[@id="changelist-filter"]//a[contains(text(), "Abba")]'
)
assert len(
site.driver.find_elements(By.XPATH, '//*[@id="result_list"]/tbody/tr')
) == 5, 'Should have 6 artists selected'
6 changes: 3 additions & 3 deletions tests/test_related.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_RelatedFieldCheckBoxFilte_multi(fixtures, rf):
result = f.queryset(None, Artist.objects.all())

value = sorted(list(result.values_list("name", flat=True)))
assert value == ["Angus", "Bon", "Brian", "Malcom", "Phil"]
assert value == ["Angus", "Brian", "Malcom", "Phil"]


def test_RelatedFieldCheckBoxFilte_isnull(fixtures, rf):
Expand Down Expand Up @@ -77,5 +77,5 @@ def test_RelatedFieldCheckBoxFilte_choices(fixtures, rf):
"bands",
)
choices = list(f.choices(Mock()))
assert len(choices) == 4
assert [c["display"] for c in choices] == ["All", "None", "AC/DC", "Geordie"]
assert len(choices) == 5
assert [c["display"] for c in choices] == ["All", "None", "AC/DC", "Geordie", "Abba"]
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tox]
envlist =
d{32,42}-py{39,310,311,312}
d50-py{310,311,312}
d32-py{39,310,311}
d{42,50}-py{310,311,312}
skip_missing_interpreters = true

[pytest]
Expand Down

0 comments on commit d4f53d5

Please sign in to comment.