From c0979645df5c8e15259187fabe052254bd8d8133 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Thu, 28 Sep 2023 11:08:43 +0200 Subject: [PATCH 1/3] Tender detail: simple admin only info card --- .../tenders/_detail_admin_extra_info.html | 29 +++++++++++++++++++ lemarche/templates/tenders/detail.html | 9 ++++-- lemarche/tenders/models.py | 8 +++++ lemarche/tenders/tests.py | 10 +++++++ lemarche/www/tenders/views.py | 7 ++--- 5 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 lemarche/templates/tenders/_detail_admin_extra_info.html diff --git a/lemarche/templates/tenders/_detail_admin_extra_info.html b/lemarche/templates/tenders/_detail_admin_extra_info.html new file mode 100644 index 000000000..0f34d4404 --- /dev/null +++ b/lemarche/templates/tenders/_detail_admin_extra_info.html @@ -0,0 +1,29 @@ +
+

Informations Admin

+
+
+
    +
  • + + {{ tender.siae_email_send_date_count }} prestataire{{ tender.siae_email_send_date_count|pluralize }} ciblé{{ tender.siae_email_send_date_count|pluralize }} +
  • +
  • + + {{ tender.siae_detail_display_date_count_all }} prestataire{{ tender.siae_email_send_date_count|pluralize }} qui {{ tender.siae_email_send_date_count|pluralize:'a,ont' }} vu +
  • +
  • + + {{ tender.siae_detail_contact_click_date_count }} prestataire{{ tender.siae_detail_contact_click_date_count|pluralize }} intéressé{{ tender.siae_detail_contact_click_date_count|pluralize }} +
  • +
  • + + + Lien vers l'admin  + + + +
  • +
+
+
+
diff --git a/lemarche/templates/tenders/detail.html b/lemarche/templates/tenders/detail.html index 45a57f3c8..c17462c55 100644 --- a/lemarche/templates/tenders/detail.html +++ b/lemarche/templates/tenders/detail.html @@ -58,8 +58,11 @@ {# Sidebar with actions #}
+ {% if is_admin %} + {% include "tenders/_detail_admin_extra_info.html" with tender=tender %} + {% endif %} {% if user == tender.author %} - {% if is_draft %} + {% if tender.is_draft %}
@@ -75,7 +78,7 @@ Modifier {% endif %} - {% if is_pending_validation %} + {% if tender.is_pending_validation %}
@@ -87,7 +90,7 @@
{% endif %} - {% if is_validated %} + {% if tender.is_validated %}
diff --git a/lemarche/tenders/models.py b/lemarche/tenders/models.py index ca82050d7..dc261e9ac 100644 --- a/lemarche/tenders/models.py +++ b/lemarche/tenders/models.py @@ -588,6 +588,14 @@ def set_hubspot_id(self, hubspot_deal_id, with_save=True): if with_save: self.save() + @property + def is_draft(self) -> bool: + return self.status == self.STATUS_DRAFT + + @property + def is_pending_validation(self) -> bool: + return self.status == self.STATUS_PUBLISHED + @property def is_validated(self) -> bool: return self.validated_at and self.status == self.STATUS_VALIDATED diff --git a/lemarche/tenders/tests.py b/lemarche/tenders/tests.py index 8f84d22a3..201bc4f6e 100644 --- a/lemarche/tenders/tests.py +++ b/lemarche/tenders/tests.py @@ -103,6 +103,16 @@ def test_questions_list(self): self.assertEqual(len(tender_with_questions.questions_list()), 2) self.assertEqual(tender_with_questions.questions_list()[0].get("text"), tender_question_1.text) + def test_status(self): + tender_draft = TenderFactory(status=tender_constants.STATUS_DRAFT) + tender_pending_validation = TenderFactory(status=tender_constants.STATUS_PUBLISHED) + tender_validated_half = TenderFactory(status=tender_constants.STATUS_VALIDATED) + tender_validated_full = TenderFactory(status=tender_constants.STATUS_VALIDATED, validated_at=timezone.now()) + self.assertTrue(tender_draft.is_draft, True) + self.assertTrue(tender_pending_validation.is_pending_validation, True) + self.assertTrue(tender_validated_half.is_validated, False) + self.assertTrue(tender_validated_full.is_validated, True) + class TenderModelSaveTest(TestCase): def test_set_slug(self): diff --git a/lemarche/www/tenders/views.py b/lemarche/www/tenders/views.py index f0528273f..c33c2abf3 100644 --- a/lemarche/www/tenders/views.py +++ b/lemarche/www/tenders/views.py @@ -327,6 +327,7 @@ def get_context_data(self, **kwargs): user_kind = user.kind if user.is_authenticated else "anonymous" show_nps = self.request.GET.get("nps", None) # enrich context + context["is_admin"] = self.request.user.is_authenticated and self.request.user.is_admin context["parent_title"] = TITLE_DETAIL_PAGE_SIAE if user_kind == User.KIND_SIAE else TITLE_DETAIL_PAGE_OTHERS context["tender_kind_display"] = ( TITLE_KIND_SOURCING_SIAE @@ -339,11 +340,7 @@ def get_context_data(self, **kwargs): tender=self.object, siae_id=int(self.siae_id), detail_contact_click_date__isnull=False ).exists() if user.is_authenticated: - if self.object.author == user: - context["is_draft"] = self.object.status == tender_constants.STATUS_DRAFT - context["is_pending_validation"] = self.object.status == tender_constants.STATUS_PUBLISHED - context["is_validated"] = self.object.status == tender_constants.STATUS_VALIDATED - elif user.kind == User.KIND_SIAE: + if user.kind == User.KIND_SIAE: context["user_siae_has_detail_contact_click_date"] = TenderSiae.objects.filter( tender=self.object, siae__in=user.siaes.all(), detail_contact_click_date__isnull=False ).exists() From c777b3232876a6c1bf50c507a47d5909fdc1c606 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Thu, 28 Sep 2023 11:39:07 +0200 Subject: [PATCH 2/3] Add tests --- .../tenders/_detail_admin_extra_info.html | 20 +++++++++++ lemarche/www/siaes/tests.py | 34 ++++++++++++++++--- lemarche/www/tenders/tests.py | 15 ++++++++ 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/lemarche/templates/tenders/_detail_admin_extra_info.html b/lemarche/templates/tenders/_detail_admin_extra_info.html index 0f34d4404..0949b2ade 100644 --- a/lemarche/templates/tenders/_detail_admin_extra_info.html +++ b/lemarche/templates/tenders/_detail_admin_extra_info.html @@ -3,6 +3,16 @@

Informations Admin