From dd2a19b5459091cba00fc838260a113b94f79e75 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Tue, 30 Jan 2024 14:48:03 +0100 Subject: [PATCH] =?UTF-8?q?D=C3=A9p=C3=B4t=20de=20besoin=20x=20APProch=20:?= =?UTF-8?q?=20nouveaux=20champs=20pour=20stocker=20leur=20ID=20(#1058)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * New Tender.partner_approch_id field. New property is_partner_approch. Update admin * Rebase: fix migration name --- config/settings/base.py | 2 +- .../templates/tenders/_detail_contact.html | 8 ++------ lemarche/tenders/admin.py | 19 ++++++++++++++----- .../0071_tender_partner_approch_id.py | 17 +++++++++++++++++ lemarche/tenders/models.py | 10 +++++++++- lemarche/utils/settings_context_processors.py | 1 - 6 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 lemarche/tenders/migrations/0071_tender_partner_approch_id.py diff --git a/config/settings/base.py b/config/settings/base.py index 43643aff4..77e72c47c 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -809,7 +809,7 @@ "https://docs.google.com/forms/d/e/1FAIpQLScx1k-UJ-962_rSgPJGabc327gGjFUho6ypgcZHCubuwTl7Lg/viewform" ) TALLY_NPS_FORM_ID = env.str("TALLY_NPS_FORM_ID", "") -APPROCH_USER_ID = env.int("APPROCH_USER_ID", 0) +PARTNER_APPROCH_USER_ID = env.int("PARTNER_APPROCH_USER_ID", 0) # Misc diff --git a/lemarche/templates/tenders/_detail_contact.html b/lemarche/templates/tenders/_detail_contact.html index 14e4aaaff..2ffd4d4e6 100644 --- a/lemarche/templates/tenders/_detail_contact.html +++ b/lemarche/templates/tenders/_detail_contact.html @@ -44,7 +44,7 @@

{% if tender.can_display_contact_external_link %}
- {% if tender.author.id == APPROCH_USER_ID %} + {% if tender.is_partner_approch %}

Ce projet d'achat a été publié sur la plateforme APProch.
@@ -53,11 +53,7 @@

{% endif %} - {% if tender.author.id == APPROCH_USER_ID %} - Ça m'intéresse - {% else %} - {{ tender.external_link_title|safe }} - {% endif %} + {{ tender.external_link_title|safe }}

diff --git a/lemarche/tenders/admin.py b/lemarche/tenders/admin.py index ec9b64e09..17c13311b 100644 --- a/lemarche/tenders/admin.py +++ b/lemarche/tenders/admin.py @@ -186,8 +186,10 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin): readonly_fields = [field for field in Tender.READONLY_FIELDS] + [ # slug # status - "author_kind_detail", "question_count_with_link", + "author_kind_detail", + "is_partner_approch", + "partner_approch_id", "siae_count_annotated_with_link", "siae_email_send_count_annotated_with_link", "siae_email_link_click_count_annotated_with_link", @@ -293,6 +295,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin): ), }, ), + ("Partenaire APProch", {"fields": ("is_partner_approch", "partner_approch_id")}), ( "Structures", { @@ -427,6 +430,12 @@ def is_validated_or_sent(self, tender: Tender): is_validated_or_sent.boolean = True is_validated_or_sent.short_description = "Validé / Envoyé" + def question_count_with_link(self, tender): + url = reverse("admin:tenders_tenderquestion_changelist") + f"?tender__in={tender.id}" + return format_html(f'{tender.questions.count()}') + + question_count_with_link.short_description = TenderQuestion._meta.verbose_name_plural + def author_with_link(self, tender): url = reverse("admin:users_user_change", args=[tender.author_id]) return format_html(f'{tender.author}') @@ -440,11 +449,11 @@ def author_kind_detail(self, tender): author_kind_detail.short_description = "Type du client" author_kind_detail.admin_order_field = "author__kind" - def question_count_with_link(self, tender): - url = reverse("admin:tenders_tenderquestion_changelist") + f"?tender__in={tender.id}" - return format_html(f'{tender.questions.count()}') + def is_partner_approch(self, tender: Tender): + return tender.is_partner_approch - question_count_with_link.short_description = TenderQuestion._meta.verbose_name_plural + is_partner_approch.boolean = True + is_partner_approch.short_description = "Partenaire APProch ?" def siae_count_annotated_with_link(self, tender): url = reverse("admin:siaes_siae_changelist") + f"?tenders__in={tender.id}&tendersiae__source__in=" diff --git a/lemarche/tenders/migrations/0071_tender_partner_approch_id.py b/lemarche/tenders/migrations/0071_tender_partner_approch_id.py new file mode 100644 index 000000000..a8d7ec862 --- /dev/null +++ b/lemarche/tenders/migrations/0071_tender_partner_approch_id.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.9 on 2024-01-29 07:39 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("tenders", "0070_tender_with_ai_matching_tendersiae_found_with_ai_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="tender", + name="partner_approch_id", + field=models.IntegerField(blank=True, null=True, verbose_name="Partenaire APProch : ID"), + ), + ] diff --git a/lemarche/tenders/models.py b/lemarche/tenders/models.py index d67388543..d7ce7c379 100644 --- a/lemarche/tenders/models.py +++ b/lemarche/tenders/models.py @@ -492,6 +492,8 @@ class Tender(models.Model): help_text=ADMIN_FIELD_HELP_TEXT, default=5, ) + # partner data + partner_approch_id = models.IntegerField("Partenaire APProch : ID", blank=True, null=True) # stats siae_count = models.IntegerField( "Nombre de structures concernées", help_text=RECALCULATED_FIELD_HELP_TEXT, default=0 @@ -671,7 +673,9 @@ def questions_list(self): @cached_property def external_link_title(self) -> str: - if self.kind == tender_constants.KIND_TENDER: + if self.is_partner_approch: + return "Ça m'intéresse" + elif self.kind == tender_constants.KIND_TENDER: return "Voir l'appel d'offres" return "Lien partagé" @@ -805,6 +809,10 @@ def is_sent(self) -> bool: def is_validated_or_sent(self) -> bool: return self.is_validated or self.is_sent + @property + def is_partner_approch(self) -> bool: + return self.author_id == settings.PARTNER_APPROCH_USER_ID + def set_validated(self): self.validated_at = timezone.now() self.status = tender_constants.STATUS_VALIDATED diff --git a/lemarche/utils/settings_context_processors.py b/lemarche/utils/settings_context_processors.py index e2852258d..b08872163 100644 --- a/lemarche/utils/settings_context_processors.py +++ b/lemarche/utils/settings_context_processors.py @@ -21,7 +21,6 @@ def expose_settings(request): "CONTACT_EMAIL": settings.CONTACT_EMAIL, "TEAM_CONTACT_EMAIL": settings.TEAM_CONTACT_EMAIL, "GIP_CONTACT_EMAIL": settings.GIP_CONTACT_EMAIL, - "APPROCH_USER_ID": settings.APPROCH_USER_ID, # forms & docs "FACILITATOR_SLIDE": settings.FACILITATOR_SLIDE, "FACILITATOR_LIST": settings.FACILITATOR_LIST,