From 0c285ca072554eaf951c805b9d9fc28e3f80648f Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 28 Jul 2021 17:02:58 +0530 Subject: [PATCH] Update add_linked: add relationship fields manually --- app/convert.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/convert.py b/app/convert.py index 1fbc5b8..23b18eb 100644 --- a/app/convert.py +++ b/app/convert.py @@ -24,7 +24,8 @@ def fix_url(link): # Create linked objects -def add_linked(person, field, obj, data): +def add_linked(person, obj, data): + field = [] # TODO: fuzzy matching instead of lower() items = fix_bracketed_lists(data).lower() items = items.replace(';', ',').split(',') @@ -38,6 +39,7 @@ def add_linked(person, field, obj, data): tgt.name = n tgt.save() field.append(tgt) + return field # Fetch an object by source_id (numeric identifier used in source DB) @@ -116,10 +118,14 @@ def refresh_data(filename, fmt=None): person.personal_url = fix_url(row['URL']) with transaction.atomic(): - add_linked(person, person.research_methods, Method, row['Methods']) - add_linked(person, person.research_scales, Scale, row['Scale']) - add_linked(person, person.research_taxa, Taxon, row['Taxa']) - add_linked(person, person.research_fields, Field, row['Field of expertise']) + research_methods = add_linked(person, Method, row['Methods']) + person.research_methods = research_methods + research_scales = add_linked(person, Scale, row['Scale']) + person.research_scales = research_scales + research_taxa = add_linked(person, Taxon, row['Taxa']) + person.research_taxa = research_taxa + research_fields = add_linked(person, Field, row['Field of expertise']) + person.research_fields = research_fields person.index() person.save() @@ -150,6 +156,7 @@ def refresh_data(filename, fmt=None): ppl, source_id = get_by_id(row['Person'], Person, first=False) if not ppl or not ppl.first(): continue for person in ppl: + person.resources = [] for r in rzs: person.resources.append(r) person.save() @@ -162,6 +169,7 @@ def refresh_data(filename, fmt=None): ppl, source_id = get_by_id(row['Person'], Person, first=False) if not ppl or not ppl.first(): continue for person in ppl: + person.ranges = [] for r in rzs: person.ranges.append(r) person.save()