Skip to content

Commit

Permalink
Merge pull request #82 from caktus/django-42-upgrade
Browse files Browse the repository at this point in the history
Django 4.x Support
  • Loading branch information
ronardcaktus authored Aug 3, 2023
2 parents 22c1c17 + 5d8011e commit 64bff4c
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
matrix:
# tox-gh-actions will only run the tox environments which match the currently
# running python-version. See [gh-actions] in tox.ini for the mapping
python-version: [3.7, 3.8, 3.9]
python-version: [3.8, 3.9, 3.10]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ _build
.coverage
.envrc
.direnv
.vscode/
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -15,16 +15,16 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.7.0
hooks:
- id: black

- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Django 2.0 has been out of support since April 1, 2019.)
Supported versions
------------------

Django: 2.2, 3.2
Python: 3.7, 3.8, 3.9, 3.10
Django: 3.2, 4.2
Python: 3.8, 3.9, 3.10

For Python 2.7 and/or Django 1.11 support, the 0.5 release series is identical (features-wise)
to 0.6 and is available on PyPI: https://pypi.org/project/django-bread/#history
Expand Down
20 changes: 16 additions & 4 deletions bread/bread.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from urllib.parse import urlencode

from django.conf import settings
from django.contrib.admin.utils import lookup_needs_distinct
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.models import Permission
from django.contrib.auth.views import redirect_to_login
Expand Down Expand Up @@ -339,6 +338,7 @@ def get_search_results(self, request, queryset, search_term):
Returns a tuple containing a queryset to implement the search,
and a boolean indicating if the results may contain duplicates.
"""

# Apply keyword searches.
def construct_search(field_name):
if field_name.startswith("^"):
Expand All @@ -362,9 +362,21 @@ def construct_search(field_name):
if not use_distinct:
opts = self.bread.model._meta
for search_spec in orm_lookups:
if lookup_needs_distinct(opts, search_spec):
use_distinct = True
break
# The function lookup_needs_distinct() was renamed
# to lookup_spawns_duplicates() in Django 4.0
# https://docs.djangoproject.com/en/4.2/releases/4.0/#:~:text=The%20undocumented%20django.contrib.admin.utils.lookup_needs_distinct()%20function%20is%20renamed%20to%20lookup_spawns_duplicates().
try:
from django.contrib.admin.utils import lookup_spawns_duplicates

if lookup_spawns_duplicates(opts, search_spec):
use_distinct = True
break
except ImportError:
from django.contrib.admin.utils import lookup_needs_distinct

if lookup_needs_distinct(opts, search_spec):
use_distinct = True
break

return queryset, use_distinct

Expand Down
1 change: 0 additions & 1 deletion bread/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


class Migration(migrations.Migration):

dependencies = []

operations = [
Expand Down
1 change: 0 additions & 1 deletion bread/migrations/0002_delete_breadtestmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


class Migration(migrations.Migration):

dependencies = [
("bread", "0001_initial"),
]
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
. # <- install ourselves
coverage
django>=3.2,<4.0
factory_boy==2.3.1
factory_boy==3.2.1
flake8
pre-commit
sphinx
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

# General information about the project.
project = "Django Bread"
copyright = "2015, Caktus Consulting, LLC"
copyright = "2015-2023, Caktus Consulting, LLC"
author = "Caktus Consulting, LLC"

# The version info for the project you're documenting, acts as replacement for
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Software Development :: Libraries :: Python Modules",
"Framework :: Django :: 2.2",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
],
zip_safe=False, # because we're including media that Django needs
)
24 changes: 13 additions & 11 deletions tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import factory
import factory.fuzzy

from .models import BreadLabelValueTestModel, BreadTestModel, BreadTestModel2


class BreadTestModel2Factory(factory.DjangoModelFactory):
FACTORY_FOR = BreadTestModel2
class BreadTestModel2Factory(factory.django.DjangoModelFactory):
class Meta:
model = BreadTestModel2

text = factory.fuzzy.FuzzyText(length=10)
text = factory.Faker("text", max_nb_chars=10)


class BreadTestModelFactory(factory.DjangoModelFactory):
FACTORY_FOR = BreadTestModel
class BreadTestModelFactory(factory.django.DjangoModelFactory):
class Meta:
model = BreadTestModel

name = factory.fuzzy.FuzzyText(length=10)
age = factory.fuzzy.FuzzyInteger(low=1, high=99)
name = factory.Faker("name")
age = factory.Faker("pyint", min_value=0, max_value=99)
other = factory.SubFactory(BreadTestModel2Factory)


class BreadLabelValueTestModelFactory(factory.DjangoModelFactory):
FACTORY_FOR = BreadLabelValueTestModel
class BreadLabelValueTestModelFactory(factory.django.DjangoModelFactory):
class Meta:
model = BreadLabelValueTestModel

name = factory.fuzzy.FuzzyText(length=10)
name = factory.Faker("name")
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[tox]
envlist = {py37,py38,py39}-django{22,32},py310-django32
envlist = {py38,py39,py310}-django{32,41,42}

[gh-actions]
python =
3.7: py37
3.8: py38
3.9: py39
3.10: py310

[testenv]
deps =
factory_boy==2.3.1
django22: Django>=2.2,<3.0
factory_boy==3.2.1
django32: Django>=3.2,<4.0
django41: Django>=4.1,<4.2
django42: Django>=4.2,<5.0
commands = python -Wmodule runtests.py

0 comments on commit 64bff4c

Please sign in to comment.