Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use filter vertical for sous categories #721

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions qfdmo/admin/acteur.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,30 @@ 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 = (
"action",
"sous_categories",
)

filter_vertical = ("sous_categories",)


class PropositionServiceInline(BasePropositionServiceInline, NotEditableInlineMixin):
model = PropositionService
Expand Down
2 changes: 1 addition & 1 deletion qfdmo/models/categorie_objet.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Meta:
)

def __str__(self) -> str:
return self.libelle
return f"{self.categorie.libelle} | {self.libelle}"

@cached_property
def url_carte(self):
Expand Down
13 changes: 9 additions & 4 deletions unit_tests/qfdmo/test_sous_categorie.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -22,6 +26,7 @@ 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")
)
Loading