From d7d92dc62ae571e0a34a2ec417fa8414ebe44db5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20K=C3=A1rolyi?= Date: Mon, 28 Nov 2022 21:26:04 +0100 Subject: [PATCH 1/7] Fix when selecting with an MSFList --- multiselectfield/utils.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/multiselectfield/utils.py b/multiselectfield/utils.py index c08ff48..b8ac3a4 100644 --- a/multiselectfield/utils.py +++ b/multiselectfield/utils.py @@ -14,6 +14,30 @@ # You should have received a copy of the GNU Lesser General Public License # along with this programe. If not, see . +from __future__ import annotations + +import sys +from collections import UserList +from typing import Optional, Union + +from django.db.models.sql.query import Query + +if sys.version_info[0] == 2: + string = basestring # noqa: F821 + string_type = unicode # noqa: F821 +else: + string = str + string_type = string + +class _FakeSqlVal(UserList): + + contains_aggregate = False + contains_column_references = False + contains_over_clause = False + + def __str__(self): + return ','.join(map(str, self)) + class MSFList(list): @@ -25,6 +49,20 @@ def __str__(msgl): msg_list = [msgl.choices.get(int(i)) if i.isdigit() else msgl.choices.get(i) for i in msgl] return ', '.join([str(s) for s in msg_list]) + def resolve_expression( + self, query: Query = None, allow_joins: bool = True, + reuse: Optional[bool] = None, summarize: bool = False, + for_save: bool = False) -> Union[list, _FakeSqlVal]: + if for_save: + result = _FakeSqlVal(self) + else: + result = list(self) + return result + + if sys.version_info < (3,): + def __unicode__(self, msgl): + return self.__str__(msgl) + def get_max_length(choices, max_length, default=200): if max_length is None: From da8c346b8b54719f4c6eca6942303f0b2c4a6fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20K=C3=A1rolyi?= Date: Mon, 5 Dec 2022 17:36:05 +0100 Subject: [PATCH 2/7] Bumping version --- CHANGES.rst | 4 ++++ multiselectfield/utils.py | 1 + setup.py | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 21915b6..f53d949 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,7 @@ +0.1.13 (2024-05-23) +------------------- +* Fix error with Django>=4.1.3: + 0.1.12 (2020-02-20) ------------------- diff --git a/multiselectfield/utils.py b/multiselectfield/utils.py index b8ac3a4..c8fdc8f 100644 --- a/multiselectfield/utils.py +++ b/multiselectfield/utils.py @@ -29,6 +29,7 @@ string = str string_type = string + class _FakeSqlVal(UserList): contains_aggregate = False diff --git a/setup.py b/setup.py index 4dced04..df03fca 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ def read(*rnames): setup( name="django-multiselectfield", - version="0.1.12", + version="0.1.13", author="Pablo Martin", author_email="goinnn@gmail.com", description="Django multiple select field", From e7b836fa442f22f576df90d647e4be45e741ac8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20K=C3=A1rolyi?= <987055+karolyi@users.noreply.github.com> Date: Thu, 23 May 2024 17:23:30 +0000 Subject: [PATCH 3/7] Update CHANGES.rst Co-authored-by: blag --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index f53d949..24e5353 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,4 +1,4 @@ -0.1.13 (2024-05-23) +development (unreleased) ------------------- * Fix error with Django>=4.1.3: From c9e5aa785f9e8ea152879a013aa34f9bb911389e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20K=C3=A1rolyi?= Date: Thu, 23 May 2024 19:26:20 +0200 Subject: [PATCH 4/7] Removing stuff that's requested --- multiselectfield/utils.py | 11 ----------- setup.py | 5 +++-- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/multiselectfield/utils.py b/multiselectfield/utils.py index c8fdc8f..d8ded3a 100644 --- a/multiselectfield/utils.py +++ b/multiselectfield/utils.py @@ -22,13 +22,6 @@ from django.db.models.sql.query import Query -if sys.version_info[0] == 2: - string = basestring # noqa: F821 - string_type = unicode # noqa: F821 -else: - string = str - string_type = string - class _FakeSqlVal(UserList): @@ -60,10 +53,6 @@ def resolve_expression( result = list(self) return result - if sys.version_info < (3,): - def __unicode__(self, msgl): - return self.__str__(msgl) - def get_max_length(choices, max_length, default=200): if max_length is None: diff --git a/setup.py b/setup.py index df03fca..f9b0b34 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,8 @@ import codecs import os -from setuptools import setup, find_packages + +from setuptools import find_packages, setup def read(*rnames): @@ -31,7 +32,7 @@ def read(*rnames): setup( name="django-multiselectfield", - version="0.1.13", + version="0.1.12", author="Pablo Martin", author_email="goinnn@gmail.com", description="Django multiple select field", From 95cb2157ed17cb71f48a68e7bdf5d2216eed24d5 Mon Sep 17 00:00:00 2001 From: blag Date: Thu, 23 May 2024 14:42:02 -0700 Subject: [PATCH 5/7] Remove unnecessary sys import --- multiselectfield/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/multiselectfield/utils.py b/multiselectfield/utils.py index d8ded3a..68d270b 100644 --- a/multiselectfield/utils.py +++ b/multiselectfield/utils.py @@ -16,7 +16,6 @@ from __future__ import annotations -import sys from collections import UserList from typing import Optional, Union From e9e9bde095fb55ce5a79d67653b5f6b4270ad436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20K=C3=A1rolyi?= Date: Fri, 24 May 2024 15:34:58 +0200 Subject: [PATCH 6/7] Fixing broken patch for selecting with MSFLists --- example/app/test_msf_select.py | 19 +++++++++++++++++++ multiselectfield/db/fields.py | 11 ----------- multiselectfield/utils.py | 6 ++++-- 3 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 example/app/test_msf_select.py diff --git a/example/app/test_msf_select.py b/example/app/test_msf_select.py new file mode 100644 index 0000000..b98c0dd --- /dev/null +++ b/example/app/test_msf_select.py @@ -0,0 +1,19 @@ +from django.test.testcases import TestCase + +from .models import Book + + +class MsfSelectTestCase(TestCase): + fixtures = ['app_data.json'] + + def test_valid_select(self): + """ + Should be able to use a multiselectfield result to select + See + https://github.com/goinnn/django-multiselectfield/pull/135 + """ + book = Book.objects.first() + result = Book.objects.filter(categories=book.categories).only('pk') + self.assertEqual(len(result), 1) + self.assertEqual(result[0].pk, book.pk) + self.assertIn(member='1,3,5', container=str(result.query)) diff --git a/multiselectfield/db/fields.py b/multiselectfield/db/fields.py index 8fbcd4d..35aaa51 100644 --- a/multiselectfield/db/fields.py +++ b/multiselectfield/db/fields.py @@ -36,17 +36,6 @@ def wrapper(cls): return wrapper -class MSFList(list): - - def __init__(self, choices, *args, **kwargs): - self.choices = choices - super(MSFList, self).__init__(*args, **kwargs) - - def __str__(msgl): - l = [msgl.choices.get(int(i)) if i.isdigit() else msgl.choices.get(i) for i in msgl] - return ', '.join([str(s) for s in l]) - - class MultiSelectField(models.CharField): """ Choice values can not contain commas. """ diff --git a/multiselectfield/utils.py b/multiselectfield/utils.py index 68d270b..35a25d3 100644 --- a/multiselectfield/utils.py +++ b/multiselectfield/utils.py @@ -39,8 +39,10 @@ def __init__(self, choices, *args, **kwargs): super(MSFList, self).__init__(*args, **kwargs) def __str__(msgl): - msg_list = [msgl.choices.get(int(i)) if i.isdigit() else msgl.choices.get(i) for i in msgl] - return ', '.join([str(s) for s in msg_list]) + msg_list = [ + msgl.choices.get(int(i)) if i.isdigit() else msgl.choices.get(i) + for i in msgl] + return ', '.join(str(s) for s in msg_list) def resolve_expression( self, query: Query = None, allow_joins: bool = True, From dee5c6f6db7f8cc4ad0061cb44aa7191045924c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20K=C3=A1rolyi?= Date: Fri, 24 May 2024 15:43:22 +0200 Subject: [PATCH 7/7] Removing EOL'd Django 4.1 tests --- .github/workflows/tests.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 6fb3bfb..089252e 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -13,8 +13,6 @@ jobs: # and https://docs.djangoproject.com/en/4.2/faq/install/#what-python-version-can-i-use-with-django matrix: include: - - { dj: "4.1.*", py: "3.8" } - - { dj: "4.1.*", py: "3.11" } - { dj: "4.2.*", py: "3.8" } - { dj: "4.2.*", py: "3.12" } - { dj: "5.0.*", py: "3.10" }