From 9661477a0cecf0a64b55f0b29a8e6ef871fb7380 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Wed, 21 Feb 2024 21:08:16 +0100 Subject: [PATCH] add parameter fields_to_remove --- lemarche/www/tenders/utils.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lemarche/www/tenders/utils.py b/lemarche/www/tenders/utils.py index 9bb67f065..0c01b2823 100644 --- a/lemarche/www/tenders/utils.py +++ b/lemarche/www/tenders/utils.py @@ -100,17 +100,16 @@ def get_or_create_user(request_user, tender_dict: dict, source=user_constants.SO return user -def duplicate(tender: Tender) -> Tender: - FIELDS_TO_REMOVE = ( - ["_state", "_django_version"] - + ["id", "slug", "siae_transactioned", "extra_data", "import_raw_object"] - + Tender.READONLY_FIELDS - ) - FIELDS_TO_KEEP = [field for field in tender.__dict__.keys() if field not in FIELDS_TO_REMOVE] +FIELDS_TO_REMOVE = ["siae_transactioned", "extra_data", "import_raw_object"] + Tender.READONLY_FIELDS + + +def duplicate(tender: Tender, fields_to_remove=FIELDS_TO_REMOVE) -> Tender: + fields_to_remove_full = ["_state", "_django_version", "id", "slug"] + fields_to_remove + fields_to_keep = [field for field in tender.__dict__.keys() if field not in fields_to_remove_full] # sectors # managed post-create new_tender_dict = dict() - for key in FIELDS_TO_KEEP: + for key in fields_to_keep: new_tender_dict[key] = tender.__dict__[key] # overwrite some fields