Skip to content

Commit

Permalink
Merge pull request #2271 from jadmsaadaot/TRACK-task#2175-B
Browse files Browse the repository at this point in the history
Prevent duplicating nation
  • Loading branch information
jadmsaadaot authored May 22, 2024
2 parents 7d04c19 + ff5c4b9 commit e21ffcf
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion epictrack-api/src/api/services/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ def import_first_nations(cls, work_id: int, indigenous_nation_ids: [int]):
).all(),
)
)
existing_first_nations_ids = [nation["indigenous_nation_id"] for nation in existing_first_nations]

# Mark removed entries as inactive
disabled_count = existing_first_nations_qry.filter(
Expand All @@ -838,9 +839,12 @@ def import_first_nations(cls, work_id: int, indigenous_nation_ids: [int]):

work = Work.find_by_id(work_id)
nations_in_same_project = find_all_by_project_id(work.project_id)

new_nations_ids = [nation_id for nation_id in indigenous_nation_ids
if nation_id not in existing_first_nations_ids]
selected_nations = [
nation for nation in nations_in_same_project
if nation.indigenous_nation_id in indigenous_nation_ids
if nation.indigenous_nation_id in new_nations_ids
]
nations_to_insert = [
{
Expand Down

0 comments on commit e21ffcf

Please sign in to comment.