diff --git a/lemarche/templates/tenders/_detail_cta_not_interested.html b/lemarche/templates/tenders/_detail_cta_not_interested.html index 82909cdc1..7f7d73935 100644 --- a/lemarche/templates/tenders/_detail_cta_not_interested.html +++ b/lemarche/templates/tenders/_detail_cta_not_interested.html @@ -1,38 +1,19 @@
- {% if not tender.siae_detail_not_interested_click_date_count %} -
-
-

Pas intéressé ?

-

- Cette demande ne vous intéresse pas ? Dites-le nous ! -

- {% if user_can_click %} -
- {% csrf_token %} -
- - -
-
- {% if user.is_authenticated %} - - {% elif siae_id %} - - {% endif %} -
-
- {% else %} - - {{ tender.cta_not_interested_card_button_text|safe }} - - {% endif %} -
+
+
+

Pas intéressé ?

+

+ Cette demande ne vous intéresse pas ? Dites-le nous ! +

+ {% if user_can_click %} + + {% else %} + + {{ tender.cta_not_interested_card_button_text|safe }} + + {% endif %}
- {% else %} - {% include "tenders/_detail_not_interested_click_confirm.html" %} - {% endif %} +
diff --git a/lemarche/templates/tenders/_detail_not_interested_click_confirm_modal.html b/lemarche/templates/tenders/_detail_not_interested_click_confirm_modal.html new file mode 100644 index 000000000..1dd086b73 --- /dev/null +++ b/lemarche/templates/tenders/_detail_not_interested_click_confirm_modal.html @@ -0,0 +1,45 @@ + + + diff --git a/lemarche/templates/tenders/detail.html b/lemarche/templates/tenders/detail.html index 42379f49c..be1fba027 100644 --- a/lemarche/templates/tenders/detail.html +++ b/lemarche/templates/tenders/detail.html @@ -68,6 +68,7 @@ {% block modals %} {% include "auth/_login_or_signup_siae_tender_modal.html" %} {% include "tenders/_detail_contact_click_confirm_modal.html" %} +{% include "tenders/_detail_not_interested_click_confirm_modal.html" %} {% endblock %} {% block extra_js %} diff --git a/lemarche/www/tenders/views.py b/lemarche/www/tenders/views.py index 62e614376..6bf0e0373 100644 --- a/lemarche/www/tenders/views.py +++ b/lemarche/www/tenders/views.py @@ -506,25 +506,34 @@ def get_object(self): def post(self, request, *args, **kwargs): self.object = self.get_object() user = self.request.user - - if self.request.user.is_authenticated: - siae = user.siaes.first() - else: - siae = Siae.objects.filter(pk=self.request.GET.get("siae_id", None)).first() - - if siae: - # save the datetime of this action - TenderSiae.objects.filter( - tender=self.object, siae=siae, detail_not_interested_click_date__isnull=True - ).update( - detail_not_interested_feedback=self.request.POST.get("detail_not_interested_feedback", ""), - detail_not_interested_click_date=timezone.now(), - updated_at=timezone.now(), - ) + siae_id = request.GET.get("siae_id", None) + if (user.is_authenticated and user.kind == User.KIND_SIAE) or siae_id: + if user.is_authenticated: + TenderSiae.objects.filter( + tender=self.object, siae__in=user.siaes.all(), detail_not_interested_click_date__isnull=True + ).update( + detail_not_interested_feedback=self.request.POST.get("detail_not_interested_feedback", ""), + detail_not_interested_click_date=timezone.now(), + updated_at=timezone.now(), + ) + else: + TenderSiae.objects.filter( + tender=self.object, siae_id=int(siae_id), detail_not_interested_click_date__isnull=True + ).update( + detail_not_interested_feedback=self.request.POST.get("detail_not_interested_feedback", ""), + detail_not_interested_click_date=timezone.now(), + updated_at=timezone.now(), + ) + # redirect + return HttpResponseRedirect(self.get_success_url(siae_id)) else: - self.template_name = "tenders/_detail_not_interested_click_error.html" + return HttpResponseForbidden() - return self.get(request) + def get_success_url(self, siae_id=None): + success_url = reverse_lazy("tenders:detail", args=[self.kwargs.get("slug")]) + if siae_id: + success_url += f"?siae_id={siae_id}" + return success_url class TenderSiaeListView(TenderAuthorOrAdminRequiredMixin, FormMixin, ListView):