Skip to content

Commit

Permalink
Django5 support (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
vb64 authored Feb 20, 2024
1 parent ab69f9b commit 180bc1e
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/django4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v3
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/django5.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# https://docs.github.com/en/free-pro-team@latest/actions/guides/building-and-testing-python
name: django5

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:

django5:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r tests/requirements.txt
pip install -r tests/django5.txt
- name: flake8
run: |
flake8 --count --show-source --statistics --max-line-length=120 django_admin_filters
flake8 --count --show-source --statistics --max-line-length=120 tests/test
- name: pylint
run: |
python -m pylint django_admin_filters
python -m pylint tests/test
- name: pytest
run: |
python manage.py collectstatic --noinput --settings example.settings
python manage.py makemigrations --settings example.settings example
python manage.py migrate --settings example.settings
pytest -c pytest5.ini --cov=django_admin_filters --cov-report xml --cov-report term:skip-covered --durations=5 tests
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# DjangoAdminFilters library
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vb64/django.admin.filters/pep257.yml?label=Pep257&style=plastic&branch=main)](https://github.com/vb64/django.admin.filters/actions?query=workflow%3Apep257)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vb64/django.admin.filters/django3.yml?label=Django%203.2.20%20Python%203.7-3.10&style=plastic&branch=main)](https://github.com/vb64/django.admin.filters/actions?query=workflow%3Adjango3)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vb64/django.admin.filters/django4.yml?label=Django%204.2.3%20Python%203.8-3.11&style=plastic&branch=main)](https://github.com/vb64/django.admin.filters/actions?query=workflow%3Adjango4)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vb64/django.admin.filters/django3.yml?label=Django%203.2.23%20Python%203.7-3.10&style=plastic&branch=main)](https://github.com/vb64/django.admin.filters/actions?query=workflow%3Adjango3)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vb64/django.admin.filters/django4.yml?label=Django%204.2.8%20Python%203.8-3.11&style=plastic&branch=main)](https://github.com/vb64/django.admin.filters/actions?query=workflow%3Adjango4)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/926ec3c1141f4230b4d0508497e5561f)](https://app.codacy.com/gh/vb64/django.admin.filters/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/926ec3c1141f4230b4d0508497e5561f)](https://app.codacy.com/gh/vb64/django.admin.filters/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/django-admin-list-filters?label=pypi%20installs)](https://pypistats.org/packages/django-admin-list-filters)
Expand Down
13 changes: 12 additions & 1 deletion django_admin_filters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,23 @@ def __init__(self, field, request, params, model, model_admin, field_path):
super().__init__(field, request, params, model, model_admin, field_path)
self.set_title()

def get_facet_counts(self, _pk_attname, _filtered_qs):
"""Django5 amin site Facets.
https://docs.djangoproject.com/en/5.0/ref/contrib/admin/filters/#facet-filters
"""
return {}

def value(self):
"""Return the string provided in the request's query string.
None if the value wasn't provided.
"""
return self.used_parameters.get(self.parameter_name)
val = self.used_parameters.get(self.parameter_name)
if isinstance(val, list):
val = val[0]

return val

def expected_parameters(self):
"""Parameter list for chice filter."""
Expand Down
3 changes: 3 additions & 0 deletions django_admin_filters/daterange.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def __init__(self, field, request, params, model, model_admin, field_path):
@staticmethod
def to_dtime(text):
"""Convert string to datetime."""
if isinstance(text, list):
text = text[0]

try:
return datetime.fromisoformat(text)
except ValueError:
Expand Down
6 changes: 5 additions & 1 deletion django_admin_filters/multi_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ def set_selected(self, val, title):
title.update({
'choices_separator': self.CHOICES_SEPARATOR,
})
self.selected = val.split(self.CHOICES_SEPARATOR) if val else []

if isinstance(val, str):
val = val.split(self.CHOICES_SEPARATOR)

self.selected = val or []

def choices(self, _changelist):
"""Define filter checkboxes."""
Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PTEST = ./venv/bin/pytest
COVERAGE = ./venv/bin/coverage
endif

DJANGO_VER = 4
DJANGO_VER = 5

SOURCE = django_admin_filters
TESTS = tests
Expand Down
3 changes: 3 additions & 0 deletions pytest5.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
filterwarnings =
ignore::django.utils.deprecation.RemovedInDjango51Warning
2 changes: 1 addition & 1 deletion tests/django3.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Django==3.2.20
Django==3.2.23
2 changes: 1 addition & 1 deletion tests/django4.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Django==4.2.3
Django==4.2.8
1 change: 1 addition & 0 deletions tests/django5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Django==5.0
1 change: 1 addition & 0 deletions tests/test/test_multi_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def test_queryset(self):

flt_choice = changelist.get_filters(request)[0][0]
assert flt_choice.queryset(request, self.queryset) is not None
assert not flt_choice.get_facet_counts(None, None)

def test_queryset_ext(self):
"""Filter queryset with MultiChoiceExt."""
Expand Down

0 comments on commit 180bc1e

Please sign in to comment.