From d2054a6eeb3cf41f4dd2919ee4f6f79e4a9358e0 Mon Sep 17 00:00:00 2001 From: SebastienReuiller Date: Fri, 1 Mar 2024 09:52:14 +0100 Subject: [PATCH] feat(Besoins): Ajout d'un filtre par type de besoin (#1104) --- lemarche/templates/tenders/list.html | 10 +++++++++- lemarche/www/tenders/forms.py | 21 +++++++++++++++++++++ lemarche/www/tenders/tests.py | 17 ++++++++++++++++- lemarche/www/tenders/views.py | 9 +++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/lemarche/templates/tenders/list.html b/lemarche/templates/tenders/list.html index 0df3388e5..5504f08ed 100644 --- a/lemarche/templates/tenders/list.html +++ b/lemarche/templates/tenders/list.html @@ -35,6 +35,14 @@

{{ page_title }}

Publier un besoin d'achat + {% else %} +
+
+
+ {{ filter_form.kind }} +
+
+
{% endif %}
@@ -110,7 +118,7 @@

{{ page_title }}

{% include "includes/_pagination.html" %} {% if not tenders %}

- Désolé, nous n'avons aucune opportunités à vous présenter pour le moment. + Désolé, nous n'avons aucune opportunité à vous présenter pour le moment.
Si ce n'est pas déjà fait, pensez à compléter votre fiche structure pour optimiser vos chances de trouver de nouvelles opportunités. diff --git a/lemarche/www/tenders/forms.py b/lemarche/www/tenders/forms.py index 076d65c5f..2e9227291 100644 --- a/lemarche/www/tenders/forms.py +++ b/lemarche/www/tenders/forms.py @@ -340,3 +340,24 @@ def __init__(self, tender_survey_transactioned_answer=None, *args, **kwargs): self.fields["survey_transactioned_answer"].disabled = True if tender_survey_transactioned_answer is False: self.fields["survey_transactioned_amount"].widget = forms.HiddenInput() + + +class TenderFilterForm(forms.Form): + FORM_KIND_CHOICES = ( + ("", "Toutes les opportunités"), + (tender_constants.KIND_QUOTE, tender_constants.KIND_QUOTE_DISPLAY), + (tender_constants.KIND_TENDER, tender_constants.KIND_TENDER_DISPLAY), + (tender_constants.KIND_PROJECT, "Projets d'achats"), + ) + + kind = forms.ChoiceField( + label="Type de besoin", + choices=FORM_KIND_CHOICES, + widget=forms.Select( + attrs={ + "class": "form-control", + "onchange": "this.form.submit()", + } + ), + required=False, + ) diff --git a/lemarche/www/tenders/tests.py b/lemarche/www/tenders/tests.py index dd49dd1b1..e0b6871db 100644 --- a/lemarche/www/tenders/tests.py +++ b/lemarche/www/tenders/tests.py @@ -491,7 +491,9 @@ def setUpTestData(cls): email_send_date=timezone.now(), detail_contact_click_date=timezone.now(), ) - cls.tender_4 = TenderFactory(author=cls.user_buyer_1, perimeters=[perimeter]) + cls.tender_4 = TenderFactory( + author=cls.user_buyer_1, perimeters=[perimeter], kind=tender_constants.KIND_TENDER + ) cls.tendersiae_4_1 = TenderSiae.objects.create( tender=cls.tender_4, siae=cls.siae_1, email_send_date=timezone.now() ) @@ -577,6 +579,19 @@ def test_siae_user_should_see_unread_badge(self): response, 'Nouveau' ) + def test_siae_user_should_only_see_filtered_kind(self): + self.client.force_login(self.siae_user_2) + url = reverse("tenders:list") + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.context["tenders"]), 2) + + url = reverse("tenders:list") + response = self.client.get(f"{url}?kind={tender_constants.KIND_TENDER}") + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.context["tenders"]), 1) + self.assertEqual(response.context["tenders"][0], self.tender_4) + class TenderDetailViewTest(TestCase): @classmethod diff --git a/lemarche/www/tenders/views.py b/lemarche/www/tenders/views.py index 058765d23..555c72ed6 100644 --- a/lemarche/www/tenders/views.py +++ b/lemarche/www/tenders/views.py @@ -32,6 +32,7 @@ TenderCreateStepDetailForm, TenderCreateStepGeneralForm, TenderCreateStepSurveyForm, + TenderFilterForm, TenderSiaeSurveyTransactionedForm, TenderSurveyTransactionedForm, ) @@ -296,6 +297,13 @@ def get_queryset(self): qs = Tender.objects.by_user(user).with_siae_stats() if self.status: qs = qs.filter(status=self.status) + + self.filter_form = TenderFilterForm(data=self.request.GET) + if self.filter_form.is_valid(): + kind = self.filter_form.cleaned_data.get("kind") + if kind: + qs = qs.filter(kind=kind) + qs = qs.prefetch_many_to_many().select_foreign_keys() qs = qs.order_by_deadline_date() return qs @@ -317,6 +325,7 @@ def get_context_data(self, **kwargs): context["page_title"] = TITLE_DETAIL_PAGE_SIAE if user_kind == User.KIND_SIAE else TITLE_DETAIL_PAGE_OTHERS context["title_kind_sourcing_siae"] = TITLE_KIND_SOURCING_SIAE context["tender_constants"] = tender_constants + context["filter_form"] = self.filter_form return context