Skip to content

Commit

Permalink
Tender readonly fields cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Dec 6, 2023
1 parent ea06a27 commit c861e43
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
1 change: 0 additions & 1 deletion lemarche/siaes/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
13 changes: 1 addition & 12 deletions lemarche/tenders/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions lemarche/tenders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c861e43

Please sign in to comment.