Skip to content

Commit

Permalink
Merge pull request #40 from saxix/develop
Browse files Browse the repository at this point in the history
Release 2.4.3
  • Loading branch information
GigiusB authored Mar 15, 2024
2 parents 43838be + 676765e commit 31a5dfe
Show file tree
Hide file tree
Showing 51 changed files with 561 additions and 131 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.3.1
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: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ jobs:
strategy:
fail-fast: false
matrix:
django-version: [ "3.2", "4.2"]
python-version: [ "3.9", "3.11" ]
django-version: [ "3.2", "4.2", "5.0"]
python-version: [ "3.9", "3.10", "3.11", "3.12" ]
exclude:
- django-version: 5.0
python-version: 3.9
env:
DATABASE_URL: postgres://postgres:[email protected]:5432/adminfilters
PY_VER: ${{ matrix.python-version}}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
.*
~*
build
__pycache__
*.egg-info
!.gitignore
!.github
!.bumpversion.cfg
!.flake8
!.isort.cfg
!.readthedocs.yaml
.travis.yml
dist/
coverage.xml
pytest.xml
docs/images/*.mov
__pycache__
37 changes: 37 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Read the Docs configuration file for Sphinx projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.12"
# You can also specify other tool versions:
# nodejs: "20"
# rust: "1.70"
# golang: "1.20"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/conf.py
# You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
# builder: "dirhtml"
# Fail on all warnings to avoid broken references
# fail_on_warning: true

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
# - pdf
# - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- requirements: src/requirements/develop.pip
- method: pip
path: .
24 changes: 23 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
Release 2.4.3
=============
* Fixes bug in UnionListFilter


Release 2.4.2
=============
* Added compatibility with Django 5
* Autocomplete filter losing the value after the selection
* With LinkedAutocomplete and Autocomplete in same filter list the latter would not work


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


Release 2.4
===========
* Django 5.x support


Release 2.3.1
===============
=============
* Bug fixes


Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ docs: .mkbuilddir
@mkdir -p ${BUILDDIR}/docs
sphinx-build -aE docs ${BUILDDIR}/docs

bump: ## Bumps version
@while :; do \
read -r -p "bumpversion [major/minor/release]: " PART; \
case "$$PART" in \
major|minor|release) break ;; \
esac \
done ; \
bumpversion --no-commit --allow-dirty $$PART
@grep "^VERSION " src/adminfilters/__init__.py


heroku:
@git checkout heroku
Expand Down
4 changes: 1 addition & 3 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ Changelog

This sections lists the biggest changes done on each release.

.. contents::
:local:

.. include:: ../CHANGES
.. include:: ../CHANGES.md
16 changes: 8 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

# General information about the project.
project = 'Django AdminFilters'
copyright = '2012-2022, Stefano Apostolico'
copyright = '2012-2024, Stefano Apostolico'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -125,13 +125,13 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
if os.environ.get('READTHEDOCS', None) == 'True':
html_theme = 'default'
else:
import sphinx_rtd_theme

html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
# if os.environ.get('READTHEDOCS', None) == 'True':
# html_theme = 'default'
# else:
# import sphinx_rtd_theme
#
# html_theme = 'sphinx_rtd_theme'
# html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
#
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down
18 changes: 9 additions & 9 deletions docs/filters/autocomplete.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ python::
class MyCountry(models.ModelAdmin):
search_fields = ('name', )

class MyModelAdmin(models.ModelAdmin):
class MyModelAdmin(AdminFiltersMixin, models.ModelAdmin):
list_filter = (
('country', AutoCompleteFilter),
...
Expand Down Expand Up @@ -52,24 +52,24 @@ Usage

python::

class Country(models.ModelAdmin):
class Country(models.Model):
...

class Region(models.ModelAdmin):
class Region(models.Model):
country = models.ForeignKey(Country, ...)

class MyModel(models.ModelAdmin):
class MyModel(models.Model):
region = models.ForeignKey(Region, ...)

class MyCountry(models.ModelAdmin):
class MyCountry(AdminAutoCompleteSearchMixin, models.ModelAdmin):
search_fields = ('name', )

class MyRegion(models.ModelAdmin):
class MyRegion(AdminAutoCompleteSearchMixin, models.ModelAdmin):
search_fields = ('name', )

class MyModelAdmin(models.ModelAdmin):
class MyModelAdmin(AdminFiltersMixin, models.ModelAdmin):
list_filter = (
('region__country', LinkedAutoCompleteFilter.factory(None),
('region', LinkedAutoCompleteFilter.factory("region__country"),
('region__country', LinkedAutoCompleteFilter.factory(parent=None)),
('region', LinkedAutoCompleteFilter.factory(parent="region__country")),
...
)
5 changes: 5 additions & 0 deletions docs/filters/combo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
.. _filters_combo:


.. image:: ../images/choices_field_combo.gif
:width: 900


====================
AllValuesComboFilter
====================

Just overrides standard template of Django ``AllValuesFieldListFilter`` to use Combobox widget


=======================
ChoicesFieldComboFilter
=======================
Expand Down
2 changes: 1 addition & 1 deletion docs/filters/dj.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Usage
python::


class MyModelAdmin(models.ModelAdmin):
class MyModelAdmin(AdminFiltersMixin, models.ModelAdmin):
list_filter = (
DjangoLookupFilter,
...
Expand Down
2 changes: 1 addition & 1 deletion docs/filters/json.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ python::
class MyModel(models.ModelAdmin):
flags = models.JSONField()

class MyModelAdmin(models.ModelAdmin):
class MyModelAdmin(AdminFiltersMixin, models.ModelAdmin):
list_filter = (
('flags', JsonFieldFilter),
...
Expand Down
32 changes: 32 additions & 0 deletions docs/filters/multiselect.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,40 @@
IntersectionFieldListFilter
===========================

A FieldListFilter which allows multiple selection of filters for many-to-many type fields. A list of objects will be returned whose m2m contains all the selected filters.

.. image:: ../images/intersection.gif
:width: 900


Usage
-----

python::


class DemoModelAdmin_UnionFieldListFilter(DebugMixin, ModelAdmin):
list_filter = (("bands", IntersectionFieldListFilter),)




====================
UnionFieldListFilter
====================


.. image:: ../images/union.gif
:width: 900

A FieldListFilter which allows multiple selection of filters for many-to-many type fields, or any type with choices. A list of objects will be returned whose m2m or value set contains one of the selected filters.


Usage
-----

python::


class DemoModelAdmin_UnionFieldListFilter(DebugMixin, ModelAdmin):
list_filter = (("bands", UnionFieldListFilter),)
4 changes: 2 additions & 2 deletions docs/filters/querystring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Usage
-----
::

class MyModelAdmin(models.ModelAdmin):
class MyModelAdmin(AdminFiltersMixin, models.ModelAdmin):
list_filter = (
QueryStringFilter,
...
Expand Down Expand Up @@ -48,7 +48,7 @@ Configuration

The filter can be configured either using subclassing or `.factory()` method::

class MyModelAdmin(models.ModelAdmin):
class MyModelAdmin(AdminFiltersMixin, models.ModelAdmin):
list_filter = (
QueryStringFilter.factory(title=_("Generic field filter")),
...
Expand Down
5 changes: 5 additions & 0 deletions docs/filters/radio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
.. _filters_radio:



.. image:: ../images/boolean_radio.gif
:width: 900


====================
AllValuesRadioFilter
====================
Expand Down
4 changes: 2 additions & 2 deletions docs/filters/value.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Usage
-----
::

class MyModelAdmin(models.ModelAdmin):
class MyModelAdmin(AdminFiltersMixin, models.ModelAdmin):
list_filter = (
('name', ValueFilter),
('country__name', ValueFilter), # to foreign key
Expand Down Expand Up @@ -51,7 +51,7 @@ Configuration

The filter can be configured either using subclassing or `.factory()` method::

class MyModelAdmin(models.ModelAdmin):
class MyModelAdmin(AdminFiltersMixin, models.ModelAdmin):
list_filter = (
('name', ValueFilter.factory(can_negate=False, options=True,
title=_("Person full name"))),
Expand Down
Binary file added docs/images/ChoicesFieldComboFilter.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/IntersectionFieldListFilter.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/UnionFieldListFilter.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/boolean_radio.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/choices_field_combo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/intersection.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/union.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ def read(*parts):
'Framework :: Django :: 2.2',
'Framework :: Django :: 3.2',
'Framework :: Django :: 4.0',
'Framework :: Django :: 5.0',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Intended Audience :: Developers',
],
long_description=codecs.open('README.md', 'r').read(),
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.3.1"
VERSION = __version__ = "2.4.3"
__author__ = "sax"
27 changes: 14 additions & 13 deletions src/adminfilters/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ def __init__(self, field, request, params, model, model_admin, field_path):
self.dependants = []
self.lookup_kwarg = "%s__exact" % field_path
self.lookup_kwarg_isnull = "%s__isnull" % field_path
self.lookup_val = params.get(self.lookup_kwarg)
self._params = params
self.request = request
self.lookup_val = self.get_parameters(self.lookup_kwarg)
super().__init__(field, request, params, model, model_admin, field_path)
self.admin_site = model_admin.admin_site
self.query_string = ""
Expand Down Expand Up @@ -113,18 +114,18 @@ def __init__(self, field, request, params, model, model_admin, field_path):
self.parent_lookup_kwarg = f"{self.parent}__exact"
super().__init__(field, request, params, model, model_admin, field_path)
for pos, entry in enumerate(model_admin.list_filter):
if (
isinstance(entry, (list, tuple))
and len(entry) == 2
and entry[0] != self.field_path
and entry[1].__name__ == type(self).__name__
and entry[1].parent == self.field_path
):
kwarg = f"{entry[0]}__exact"
if entry[1].parent:
if kwarg not in self.dependants:
self.dependants.extend(entry[1].dependants)
self.dependants.append(kwarg)
if isinstance(entry, (list, tuple)):
if (
len(entry) == 2
and entry[0] != self.field_path
and entry[1].__name__ == type(self).__name__
and entry[1].parent == self.field_path
):
kwarg = f"{entry[0]}__exact"
if entry[1].parent:
if kwarg not in self.dependants:
self.dependants.extend(entry[1].dependants)
self.dependants.append(kwarg)

def has_output(self):
if self.parent:
Expand Down
3 changes: 3 additions & 0 deletions src/adminfilters/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django import __version__ as django_version

DJANGO_MAJOR = int(django_version.split('.')[0])
Loading

0 comments on commit 31a5dfe

Please sign in to comment.