Skip to content

Commit

Permalink
feat(Besoins): Ajout d'un filtre par type de besoin (#1104)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienReuiller authored Mar 1, 2024
1 parent 31208bb commit d2054a6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lemarche/templates/tenders/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ <h1>{{ page_title }}</h1>
<i class="ri-add-fill ri-lg mr-2"></i>Publier un besoin d'achat
</a>
</div>
{% else %}
<div class="col-12 col-md-auto">
<form method="GET" action="">
<div class="form-group">
{{ filter_form.kind }}
</div>
</form>
</div>
{% endif %}
</div>
<div class="row">
Expand Down Expand Up @@ -110,7 +118,7 @@ <h1>{{ page_title }}</h1>
{% include "includes/_pagination.html" %}
{% if not tenders %}
<p class="text-muted">
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.
<br />
Si ce n'est pas déjà fait, pensez à <a href="{% url 'dashboard:home' %}">compléter votre fiche structure</a>
pour optimiser vos chances de trouver de nouvelles opportunités.
Expand Down
21 changes: 21 additions & 0 deletions lemarche/www/tenders/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
17 changes: 16 additions & 1 deletion lemarche/www/tenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
Expand Down Expand Up @@ -577,6 +579,19 @@ def test_siae_user_should_see_unread_badge(self):
response, '<span class="float-right badge badge-sm badge-pill badge-new">Nouveau</span>'
)

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
Expand Down
9 changes: 9 additions & 0 deletions lemarche/www/tenders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
TenderCreateStepDetailForm,
TenderCreateStepGeneralForm,
TenderCreateStepSurveyForm,
TenderFilterForm,
TenderSiaeSurveyTransactionedForm,
TenderSurveyTransactionedForm,
)
Expand Down Expand Up @@ -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
Expand All @@ -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


Expand Down

0 comments on commit d2054a6

Please sign in to comment.