diff --git a/app/settings/base.py b/app/settings/base.py index a5ea1b4..953f9da 100644 --- a/app/settings/base.py +++ b/app/settings/base.py @@ -19,6 +19,8 @@ "mathfilters", "djmoney", "anymail", + 'wagtail_rangefilter', + 'rangefilter', "rest_framework", "groundwork.core", "groundwork.geo", diff --git a/app/wagtail_hooks.py b/app/wagtail_hooks.py index 1c5cbde..58a49f4 100644 --- a/app/wagtail_hooks.py +++ b/app/wagtail_hooks.py @@ -17,6 +17,7 @@ from app.models.stripe import LBCCustomer, LBCProduct, LBCSubscription, ShippingZone from app.models.wagtail import MembershipPlanPage, MembershipPlanPrice, ReadingOption from app.utils import ensure_list +from wagtail_rangefilter.filters import DateTimeRangeFilter @hooks.register("insert_global_admin_css") @@ -117,6 +118,7 @@ class CustomerAdmin(ModelAdmin): exclude_from_explorer = ( False # or True to exclude pages of this type from Wagtail's explorer view ) + list_display = ( "recipient_name", "primary_product_name", @@ -145,6 +147,11 @@ class CustomerAdmin(ModelAdmin): ) export_filename = "lbc_members" + def get_list_filter(self, request): + if request.GET.get('status') == 'expired': + return (("ended_at", DateTimeRangeFilter),) + return () + def get_queryset(self, request): qs = super().get_queryset(request) return ( @@ -155,7 +162,6 @@ def get_queryset(self, request): .select_related("plan__product", "customer__subscriber") ) - # Now you just need to register your customised ModelAdmin class with Wagtail modeladmin_register(CustomerAdmin) diff --git a/poetry.lock b/poetry.lock index ce27d58..3b9c25b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "anyascii" @@ -793,6 +793,17 @@ files = [ {file = "django_active_link-0.1.8-py2.py3-none-any.whl", hash = "sha256:a6a94f92e9150d05be4491e10e5dfb3274c08dd88866081f5f90ea2d738db647"}, ] +[[package]] +name = "django-admin-rangefilter" +version = "0.13.0" +description = "django-admin-rangefilter app, add the filter by a custom date range on the admin UI." +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" +files = [ + {file = "django_admin_rangefilter-0.13.0-py2.py3-none-any.whl", hash = "sha256:ea23896f515fb0974097d6f035a1234d2e30bd33f4e62df2997b2826b1aefd01"}, + {file = "django_admin_rangefilter-0.13.0.tar.gz", hash = "sha256:d017bb8f44f6fbe262361fa9b0c7bcc05a01919f241f0eff084e1e2da9443084"}, +] + [[package]] name = "django-allauth" version = "0.50.0" @@ -2554,6 +2565,7 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, + {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, @@ -3351,6 +3363,25 @@ files = [ [package.dependencies] wagtail = ">=3.0,<6" +[[package]] +name = "wagtail-rangefilter" +version = "0.2.1" +description = "Integrates django-admin-rangefilter into Wagtail's ModelAdmin" +optional = false +python-versions = ">=3.8" +files = [ + {file = "wagtail-rangefilter-0.2.1.tar.gz", hash = "sha256:74fde188e13e44766f1e106c91be540ca1cdf032251f233d6b3e4ea7ecd57ace"}, + {file = "wagtail_rangefilter-0.2.1-py3-none-any.whl", hash = "sha256:54bff60260f23340a3f8bc1728c5eb19462f2a83173e0349f3b061095da39bbd"}, +] + +[package.dependencies] +Django = ">=3.2" +django-admin-rangefilter = ">=0.12" +wagtail = ">=4.1" + +[package.extras] +testing = ["coverage (>=6.4.4,<6.5.0)", "tox (>=3.26.0,<3.27.0)"] + [[package]] name = "wagtail-seo" version = "2.4.1" @@ -3592,4 +3623,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "e955fe45950e504a03be42dce4e9be7003b14bbad419871d24e784d4c4a9173c" +content-hash = "5108073b73c473b9355545ffc28b4cc0151800a72ab59b0ce1d9d3177bfe7538" diff --git a/pyproject.toml b/pyproject.toml index b7f1c24..b34bb92 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -72,6 +72,7 @@ orjson = "^3.9.2" slippers = "^0.6.2" django-vite = { git = "https://github.com/Niicck/django-vite", rev = "fix-isDynamicEntry" } whitenoise = { extras = ["brotli"], version = "*" } +wagtail-rangefilter = "^0.2.1" [tool.poetry.dev-dependencies] bandit = "^1.7.0"