From 3eb3feea49fef496752201b69b15154fa0498ace Mon Sep 17 00:00:00 2001 From: Sli Date: Mon, 21 Oct 2024 16:14:00 +0200 Subject: [PATCH] Fix deprecated usage of schema json method and avoid multiple inheritance on select widgets --- accounting/widgets/select.py | 30 +++++++++++------------------- club/widgets/select.py | 18 +++++++----------- core/views/widgets/select.py | 14 +++++++------- counter/widgets/select.py | 22 ++++++++++------------ sas/widgets/select.py | 21 ++++++++++----------- 5 files changed, 45 insertions(+), 60 deletions(-) diff --git a/accounting/widgets/select.py b/accounting/widgets/select.py index b9d85e83..a27a6c6a 100644 --- a/accounting/widgets/select.py +++ b/accounting/widgets/select.py @@ -1,45 +1,37 @@ -from django.forms import Select, SelectMultiple - from accounting.models import ClubAccount, Company from accounting.schemas import ClubAccountSchema, CompanySchema -from core.views.widgets.select import AutoCompleteSelectMixin +from core.views.widgets.select import AutoCompleteSelect, AutoCompleteSelectMultiple + +_js = ["webpack/accounting/components/ajax-select-index.ts"] -class AutoCompleteSelectClubAccount(AutoCompleteSelectMixin, Select): +class AutoCompleteSelectClubAccount(AutoCompleteSelect): component_name = "club-account-ajax-select" model = ClubAccount schema = ClubAccountSchema - js = [ - "webpack/accounting/components/ajax-select-index.ts", - ] + js = _js -class AutoCompleteSelectMultipleClubAccount(AutoCompleteSelectMixin, SelectMultiple): +class AutoCompleteSelectMultipleClubAccount(AutoCompleteSelectMultiple): component_name = "club-account-ajax-select" model = ClubAccount schema = ClubAccountSchema - js = [ - "webpack/accounting/components/ajax-select-index.ts", - ] + js = _js -class AutoCompleteSelectCompany(AutoCompleteSelectMixin, Select): +class AutoCompleteSelectCompany(AutoCompleteSelect): component_name = "company-ajax-select" model = Company schema = CompanySchema - js = [ - "webpack/accounting/components/ajax-select-index.ts", - ] + js = _js -class AutoCompleteSelectMultipleCompany(AutoCompleteSelectMixin, SelectMultiple): +class AutoCompleteSelectMultipleCompany(AutoCompleteSelectMultiple): component_name = "company-ajax-select" model = Company schema = CompanySchema - js = [ - "webpack/accounting/components/ajax-select-index.ts", - ] + js = _js diff --git a/club/widgets/select.py b/club/widgets/select.py index 3c96af05..87184ed2 100644 --- a/club/widgets/select.py +++ b/club/widgets/select.py @@ -1,25 +1,21 @@ -from django.forms import Select, SelectMultiple - from club.models import Club from club.schemas import ClubSchema -from core.views.widgets.select import AutoCompleteSelectMixin +from core.views.widgets.select import AutoCompleteSelect, AutoCompleteSelectMultiple + +_js = ["webpack/club/components/ajax-select-index.ts"] -class AutoCompleteSelectClub(AutoCompleteSelectMixin, Select): +class AutoCompleteSelectClub(AutoCompleteSelect): component_name = "club-ajax-select" model = Club schema = ClubSchema - js = [ - "webpack/club/components/ajax-select-index.ts", - ] + js = _js -class AutoCompleteSelectMultipleClub(AutoCompleteSelectMixin, SelectMultiple): +class AutoCompleteSelectMultipleClub(AutoCompleteSelectMultiple): component_name = "club-ajax-select" model = Club schema = ClubSchema - js = [ - "webpack/club/components/ajax-select-index.ts", - ] + js = _js diff --git a/core/views/widgets/select.py b/core/views/widgets/select.py index a02df82d..bd910059 100644 --- a/core/views/widgets/select.py +++ b/core/views/widgets/select.py @@ -47,7 +47,7 @@ class AutoCompleteSelectMixin: } if self.is_ajax: context["selected"] = [ - self.schema.from_orm(obj).json() + self.schema.from_orm(obj).model_dump_json() for obj in self.model.objects.filter( **{ f"{self.pk}__in": [ @@ -69,37 +69,37 @@ class AutoCompleteSelect(AutoCompleteSelectMixin, Select): ... class AutoCompleteSelectMultiple(AutoCompleteSelectMixin, SelectMultiple): ... -class AutoCompleteSelectUser(AutoCompleteSelectMixin, Select): +class AutoCompleteSelectUser(AutoCompleteSelect): component_name = "user-ajax-select" model = User schema = UserProfileSchema -class AutoCompleteSelectMultipleUser(AutoCompleteSelectMixin, SelectMultiple): +class AutoCompleteSelectMultipleUser(AutoCompleteSelectMultiple): component_name = "user-ajax-select" model = User schema = UserProfileSchema -class AutoCompleteSelectGroup(AutoCompleteSelectMixin, Select): +class AutoCompleteSelectGroup(AutoCompleteSelect): component_name = "group-ajax-select" model = Group schema = GroupSchema -class AutoCompleteSelectMultipleGroup(AutoCompleteSelectMixin, SelectMultiple): +class AutoCompleteSelectMultipleGroup(AutoCompleteSelectMultiple): component_name = "group-ajax-select" model = Group schema = GroupSchema -class AutoCompleteSelectSithFile(AutoCompleteSelectMixin, Select): +class AutoCompleteSelectSithFile(AutoCompleteSelect): component_name = "sith-file-ajax-select" model = SithFile schema = SithFileSchema -class AutoCompleteSelectMultipleSithFile(AutoCompleteSelectMixin, SelectMultiple): +class AutoCompleteSelectMultipleSithFile(AutoCompleteSelectMultiple): component_name = "sith-file-ajax-select" model = SithFile schema = SithFileSchema diff --git a/counter/widgets/select.py b/counter/widgets/select.py index 4b1bdf4a..e076de63 100644 --- a/counter/widgets/select.py +++ b/counter/widgets/select.py @@ -1,35 +1,33 @@ -from django.forms import Select, SelectMultiple - -from core.views.widgets.select import AutoCompleteSelectMixin +from core.views.widgets.select import AutoCompleteSelect, AutoCompleteSelectMultiple from counter.models import Counter, Product from counter.schemas import ProductSchema, SimplifiedCounterSchema - -class CounterAutoCompleteSelectMixin(AutoCompleteSelectMixin): - js = [ - "webpack/counter/components/ajax-select-index.ts", - ] +_js = ["webpack/counter/components/ajax-select-index.ts"] -class AutoCompleteSelectCounter(CounterAutoCompleteSelectMixin, Select): +class AutoCompleteSelectCounter(AutoCompleteSelect): component_name = "counter-ajax-select" model = Counter schema = SimplifiedCounterSchema + js = _js -class AutoCompleteSelectMultipleCounter(CounterAutoCompleteSelectMixin, SelectMultiple): +class AutoCompleteSelectMultipleCounter(AutoCompleteSelectMultiple): component_name = "counter-ajax-select" model = Counter schema = SimplifiedCounterSchema + js = _js -class AutoCompleteSelectProduct(CounterAutoCompleteSelectMixin, Select): +class AutoCompleteSelectProduct(AutoCompleteSelect): component_name = "product-ajax-select" model = Product schema = ProductSchema + js = _js -class AutoCompleteSelectMultipleProduct(CounterAutoCompleteSelectMixin, SelectMultiple): +class AutoCompleteSelectMultipleProduct(AutoCompleteSelectMultiple): component_name = "product-ajax-select" model = Product schema = ProductSchema + js = _js diff --git a/sas/widgets/select.py b/sas/widgets/select.py index 2ebd4745..c737c747 100644 --- a/sas/widgets/select.py +++ b/sas/widgets/select.py @@ -1,25 +1,24 @@ -from django.forms import Select, SelectMultiple - -from core.views.widgets.select import AutoCompleteSelectMixin +from core.views.widgets.select import ( + AutoCompleteSelect, + AutoCompleteSelectMultiple, +) from sas.models import Album from sas.schemas import AlbumSchema +_js = ["webpack/sas/components/ajax-select-index.ts"] -class AutoCompleteSelectAlbum(AutoCompleteSelectMixin, Select): + +class AutoCompleteSelectAlbum(AutoCompleteSelect): component_name = "album-ajax-select" model = Album schema = AlbumSchema - js = [ - "webpack/sas/components/ajax-select-index.ts", - ] + js = _js -class AutoCompleteSelectMultipleAlbum(AutoCompleteSelectMixin, SelectMultiple): +class AutoCompleteSelectMultipleAlbum(AutoCompleteSelectMultiple): component_name = "album-ajax-select" model = Album schema = AlbumSchema - js = [ - "webpack/sas/components/ajax-select-index.ts", - ] + js = _js