Skip to content

Commit

Permalink
add cocontracting answer button
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienReuiller committed Sep 19, 2023
1 parent e53e80b commit 85abdf2
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lemarche/templates/layouts/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
{% block extra_head %}{% endblock %}
</head>

<body id="top" class="{% block body_class %}{% endblock %}">
<body id="top" class="{% block body_class %}{% endblock %}" hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'>
<!-- allow a user to go to the main content of the page -->
<noscript>
<div class="alert alert-danger" role="status">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="alert alert-success mt-3 mt-lg-0" role="alert">
<p class="mb-0 fs-sm">
Nous avons bien pris en compte votre demande de mise en relation.
Notre équipe revient vers vous dans les plus brefs délais.
</p>
</div>
19 changes: 19 additions & 0 deletions lemarche/templates/tenders/_detail_cta_cocontracting.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div id="detail_cocontracting_container" class="mt-3">
<div class="card c-card rounded-lg shadow-lg">
<div class="card-body">
<h3>Répondre en co-traitance ?</h3>

<p>Notre équipe vous met en relation avec d’autres structures désireuses de répondre en co-traitance.</p>

{% if user.is_authenticated %}
<button type="button" class="btn btn-primary btn-block" title="Être mis en relation" hx-post="{% url 'tenders:detail-cocontracting-click' tender.slug %}" hx-target="#detail_cocontracting_container">
Être mis en relation
</button>
{% else %}
<button type="button" class="btn btn-primary btn-block" title="Être mis en relation">
Être mis en relation pour {{ siae_id }}
</button>
{% endif %}
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
La structure {{ siae_name|safe }} souhaite répondre en co-traitance

Titre : {{ tender_title|safe }}
Type : {{ tender_kind|safe }}
Contact email de l'ESI: {{ siae_contact_email|safe }}
SIRET : {{ siae_siret|safe }}

Lien dans l'admin : {{ tender_admin_url }}
23 changes: 23 additions & 0 deletions lemarche/www/tenders/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,3 +533,26 @@ def send_tenders_author_30_days(tender: Tender, kind="feedback"):
}
tender.logs.append(log_item)
tender.save()


def notify_admin_siae_wants_cocontracting(tender: Tender, siae: Siae):
email_subject = f"Marché de l'inclusion : la structure {siae.name} souhaite répondre en co-traitance"
tender_admin_url = get_admin_url_object(tender)
email_body = render_to_string(
"tenders/cocontracting_notification_email_admin_body.txt",
{
"tender_title": tender.title,
"tender_kind": tender.get_kind_display(),
"tender_admin_url": tender_admin_url,
"siae_name": siae.name,
"siae_contact_email": siae.contact_email,
"siae_siret": siae.siret,
},
)
send_mail_async(
email_subject=email_subject,
email_body=email_body,
recipient_list=[settings.NOTIFY_EMAIL],
)

# api_slack.send_message_to_channel(text=email_body, service_id=settings.SLACK_WEBHOOK_C4_SUPPORT_CHANNEL)
6 changes: 6 additions & 0 deletions lemarche/www/tenders/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from lemarche.www.tenders.views import (
TenderCreateMultiStepView,
TenderDetailCocontractingClickView,
TenderDetailContactClickStatView,
TenderDetailSurveyTransactionedView,
TenderDetailView,
Expand Down Expand Up @@ -32,6 +33,11 @@
path(
"<str:slug>/contact-click-stat", TenderDetailContactClickStatView.as_view(), name="detail-contact-click-stat"
),
path(
"<str:slug>/cocontracting-click",
TenderDetailCocontractingClickView.as_view(),
name="detail-cocontracting-click",
),
path(
"<str:slug>/sondage-transaction",
TenderDetailSurveyTransactionedView.as_view(),
Expand Down
24 changes: 23 additions & 1 deletion lemarche/www/tenders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.paginator import Paginator
from django.db.models import Prefetch
from django.http import HttpResponseForbidden, HttpResponseRedirect
from django.http import HttpResponse, HttpResponseForbidden, HttpResponseRedirect
from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse_lazy
from django.utils import timezone
Expand Down Expand Up @@ -32,6 +32,7 @@
TenderCreateStepSurveyForm,
)
from lemarche.www.tenders.tasks import ( # , send_tender_emails_to_siaes
notify_admin_siae_wants_cocontracting,
notify_admin_tender_created,
send_siae_interested_email_to_author,
)
Expand Down Expand Up @@ -403,6 +404,27 @@ def get_success_message(self, detail_contact_click_confirm):
return f"<strong>{self.object.cta_card_button_text}</strong><br />Pour {self.object.cta_card_button_text.lower()}, vous devez accepter d'être mis en relation avec l'acheteur." # noqa


class TenderDetailCocontractingClickView(LoginRequiredMixin, DetailView):
"""
Endpoint to handle cocontracting button click
"""

template_name = "tenders/_detail_cocontracting_click_confirm.html"
model = Tender

def get_object(self):
return get_object_or_404(Tender, slug=self.kwargs.get("slug"))

def post(self, request, *args, **kwargs):
self.object = self.get_object()
user = self.request.user

if settings.BITOUBI_ENV == "prod":
notify_admin_siae_wants_cocontracting(self.object, user.siaes.first())

return self.get(request)


class TenderSiaeListView(TenderAuthorOrAdminRequiredMixin, FormMixin, ListView):
template_name = "tenders/siae_interested_list.html"
form_class = SiaeFilterForm
Expand Down

0 comments on commit 85abdf2

Please sign in to comment.