Skip to content

Commit

Permalink
add parameter fields_to_remove
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Feb 21, 2024
1 parent 02351cc commit 9661477
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lemarche/www/tenders/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9661477

Please sign in to comment.