From 1825663b79f82f09a1b63bd40949c653067d9eec Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Mon, 29 Jan 2024 08:53:54 +0100 Subject: [PATCH] New Tender.partner_approch_id field. New property is_partner_approch. Update admin --- config/settings/base.py | 2 +- .../templates/tenders/_detail_contact.html | 8 ++------ lemarche/tenders/admin.py | 19 ++++++++++++++----- .../0070_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/0070_tender_partner_approch_id.py diff --git a/config/settings/base.py b/config/settings/base.py index ce1275411..348fbd83e 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 96ff41f08..b5636af79 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", @@ -292,6 +294,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin): ), }, ), + ("Partenaire APProch", {"fields": ("is_partner_approch", "partner_approch_id")}), ( "Structures", { @@ -424,6 +427,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}') @@ -437,11 +446,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}" diff --git a/lemarche/tenders/migrations/0070_tender_partner_approch_id.py b/lemarche/tenders/migrations/0070_tender_partner_approch_id.py new file mode 100644 index 000000000..ebeabd12f --- /dev/null +++ b/lemarche/tenders/migrations/0070_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", "0069_tendersiae_detail_not_interested_feedback"), + ] + + 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 4196c482e..59b4aba02 100644 --- a/lemarche/tenders/models.py +++ b/lemarche/tenders/models.py @@ -472,6 +472,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 @@ -617,7 +619,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é" @@ -747,6 +751,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,