From c861e43a02c33e1ddfb86dad6d32ac4a76669467 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Mon, 4 Dec 2023 17:33:30 +0100 Subject: [PATCH] Tender readonly fields cleanup --- lemarche/siaes/admin.py | 1 - lemarche/tenders/admin.py | 13 +------------ .../commands/update_tender_count_fields.py | 12 +----------- lemarche/tenders/models.py | 19 +++++++++++++++++++ 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/lemarche/siaes/admin.py b/lemarche/siaes/admin.py index 23140e478..7f1e3247c 100644 --- a/lemarche/siaes/admin.py +++ b/lemarche/siaes/admin.py @@ -182,7 +182,6 @@ class SiaeAdmin(FieldsetsInlineMixin, gis_admin.OSMGeoAdmin): "tender_detail_display_count_annotated_with_link", "tender_detail_contact_click_count_annotated_with_link", "logs_display", - # "import_raw_object", "import_raw_object_display", ] formfield_overrides = { diff --git a/lemarche/tenders/admin.py b/lemarche/tenders/admin.py index e922e9c9c..6e43cb37f 100644 --- a/lemarche/tenders/admin.py +++ b/lemarche/tenders/admin.py @@ -136,16 +136,9 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin): ordering = ["-created_at"] autocomplete_fields = ["sectors", "location", "perimeters", "author"] - readonly_fields = [field.name for field in Tender._meta.fields if field.name.endswith("_last_seen_date")] + [ + readonly_fields = [field for field in Tender.READONLY_FIELDS] + [ # slug # status - "survey_transactioned_send_date", - "survey_transactioned_answer", - "survey_transactioned_amount", - "survey_transactioned_feedback", - "survey_transactioned_answer_date", - "validated_at", - "sent_at", "question_count_with_link", "siae_count_annotated_with_link", "siae_email_send_count_annotated_with_link", @@ -156,11 +149,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin): "logs_display", "extra_data_display", "source", - # "import_raw_object", "import_raw_object_display", - "created_at", - "published_at", - "updated_at", ] formfield_overrides = { models.TextField: {"widget": CKEditorWidget}, diff --git a/lemarche/tenders/management/commands/update_tender_count_fields.py b/lemarche/tenders/management/commands/update_tender_count_fields.py index c3dbd491a..6604d1aa5 100644 --- a/lemarche/tenders/management/commands/update_tender_count_fields.py +++ b/lemarche/tenders/management/commands/update_tender_count_fields.py @@ -3,16 +3,6 @@ from lemarche.utils.commands import BaseCommand -TENDER_COUNT_FIELDS = [ - "siae_count", - "siae_email_send_count", - "siae_email_link_click_count", - "siae_detail_display_count", - "siae_email_link_click_or_detail_display_count", - "siae_detail_contact_click_count", -] - - class Command(BaseCommand): """ Goal: update the '_count' fields of each Tender @@ -40,7 +30,7 @@ def handle(self, *args, **options): self.stdout_messages_info(f"Found {tender_queryset.count()} tenders") # Step 1b: init fields to update - update_fields = options["fields"] if options["fields"] else TENDER_COUNT_FIELDS + update_fields = options["fields"] if options["fields"] else Tender.FIELDS_STATS_COUNT self.stdout_messages_info(f"Fields to update: {update_fields}") # Step 2: loop on each Tender diff --git a/lemarche/tenders/models.py b/lemarche/tenders/models.py index c8e16ef0f..a1a6832dc 100644 --- a/lemarche/tenders/models.py +++ b/lemarche/tenders/models.py @@ -191,6 +191,25 @@ def with_network_siae_stats(self, network_siaes): class Tender(models.Model): """Appel d'offres, demande de devis et sourcing""" + FIELDS_SURVEY_TRANSACTIONED = [ + "survey_transactioned_send_date", + "survey_transactioned_answer", + "survey_transactioned_amount", + "survey_transactioned_feedback", + "survey_transactioned_answer_date", + ] + FIELDS_STATS_COUNT = [ + "siae_count", + "siae_email_send_count", + "siae_email_link_click_count", + "siae_detail_display_count", + "siae_email_link_click_or_detail_display_count", + "siae_detail_contact_click_count", + ] + FIELDS_STATS_TIMESTAMPS = ["published_at", "validated_at", "sent_at", "siae_list_last_seen_date", "created_at", "updated_at"] + FIELDS_STATS = FIELDS_STATS_COUNT + FIELDS_STATS_TIMESTAMPS + [] + READONLY_FIELDS = FIELDS_SURVEY_TRANSACTIONED + FIELDS_STATS + # used in templates STATUS_DRAFT = tender_constants.STATUS_DRAFT STATUS_PUBLISHED = tender_constants.STATUS_PUBLISHED