From d8e83dece5e7d78b442ea6e5a2a8674868e887f4 Mon Sep 17 00:00:00 2001 From: Fabien Le Frapper Date: Mon, 22 Jul 2024 12:11:32 +0200 Subject: [PATCH 1/4] force reopen pr --- forcereopen | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 forcereopen diff --git a/forcereopen b/forcereopen new file mode 100644 index 000000000..e69de29bb From 53543f3841e005b0439884abff7ae247bcd35299 Mon Sep 17 00:00:00 2001 From: Fabien Le Frapper Date: Mon, 22 Jul 2024 12:24:37 +0200 Subject: [PATCH 2/4] set filter and order in queryset for sous categorie proposition service --- qfdmo/admin/acteur.py | 18 ++++++++++++++---- qfdmo/models/categorie_objet.py | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/qfdmo/admin/acteur.py b/qfdmo/admin/acteur.py index eb264d682..fa1662ece 100644 --- a/qfdmo/admin/acteur.py +++ b/qfdmo/admin/acteur.py @@ -93,13 +93,21 @@ def __init__(self, *args, **kwargs): ).order_by("libelle_unaccent") ) - filter_horizontal = [ - "sous_categories", - ] + +class InlinePropositionServiceForm(forms.ModelForm): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + if "sous_categories" in self.fields: + self.fields["sous_categories"].queryset = ( + SousCategorieObjet.objects.annotate( + libelle_unaccent=Unaccent(Lower("libelle")), + categorie_libelle_unaccent=Unaccent(Lower("categorie__libelle")), + ).order_by("categorie_libelle_unaccent", "libelle_unaccent") + ) class BasePropositionServiceInline(admin.TabularInline): - form = BasePropositionServiceForm + form = InlinePropositionServiceForm extra = 0 fields = ( @@ -108,6 +116,8 @@ class BasePropositionServiceInline(admin.TabularInline): "sous_categories", ) + filter_vertical = ("sous_categories",) + class PropositionServiceInline(BasePropositionServiceInline, NotEditableInlineMixin): model = PropositionService diff --git a/qfdmo/models/categorie_objet.py b/qfdmo/models/categorie_objet.py index bc79c4f97..7f9218206 100644 --- a/qfdmo/models/categorie_objet.py +++ b/qfdmo/models/categorie_objet.py @@ -46,7 +46,7 @@ class Meta: ) def __str__(self) -> str: - return self.libelle + return f"{self.categorie.libelle} | {self.libelle}" @cached_property def url_carte(self): From 1f147848bf5912cfa7d270e3b1dff4414cfe575e Mon Sep 17 00:00:00 2001 From: Fabien Le Frapper Date: Mon, 22 Jul 2024 12:24:50 +0200 Subject: [PATCH 3/4] wip --- forcereopen | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 forcereopen diff --git a/forcereopen b/forcereopen deleted file mode 100644 index e69de29bb..000000000 From 8f2e3f4ef25fe7678bf2494a8ccdb83cb26630bd Mon Sep 17 00:00:00 2001 From: Fabien Le Frapper Date: Mon, 22 Jul 2024 12:55:38 +0200 Subject: [PATCH 4/4] Quick & dirty tests updates --- unit_tests/qfdmo/test_sous_categorie.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/unit_tests/qfdmo/test_sous_categorie.py b/unit_tests/qfdmo/test_sous_categorie.py index 3a7492f8e..9bc5af912 100644 --- a/unit_tests/qfdmo/test_sous_categorie.py +++ b/unit_tests/qfdmo/test_sous_categorie.py @@ -6,10 +6,14 @@ class TestSousCategorieObjetStr: def test_str_blank(self): - assert SousCategorieObjetFactory.build(libelle="").__str__() == "" + assert SousCategorieObjetFactory.build(libelle="").__str__().endswith("| ") def test_str_specialchar(self): - assert SousCategorieObjetFactory.build(libelle="Åctïôn").__str__() == "Åctïôn" + assert ( + SousCategorieObjetFactory.build(libelle="Åctïôn") + .__str__() + .endswith("| Åctïôn") + ) class TestActionNaturalKey: @@ -22,8 +26,9 @@ def test_natural_key(self): def test_get_natural_key(self): SousCategorieObjetFactory(libelle="Natural key", code="natural_key") assert ( - SousCategorieObjet.objects.get_by_natural_key("natural_key").__str__() - == "Natural key" + SousCategorieObjet.objects.get_by_natural_key("natural_key") + .__str__() + .endswith("| Natural key") )