From a0c3dd57dd923f7126669173c1eadb66aec17331 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 5 Mar 2022 00:44:07 +0530 Subject: [PATCH] Format + improve indexer --- app/convert.py | 9 ++++++--- app/models.py | 15 +++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/convert.py b/app/convert.py index bf61193..faba6e9 100644 --- a/app/convert.py +++ b/app/convert.py @@ -147,7 +147,8 @@ def refresh_data(filename, fmt=None, update_existing=False): elif fmt['dataformat'] is DataFormat.RESOURCE_DETAIL: res, source_id = get_by_id(row['ID'], Resource) - if not res: res = Resource(source_id=source_id) + if not res: + res = Resource(source_id=source_id) res.title = row['Title'] res.citation = row['Citation'] res.url = fix_url(row['URL'].strip('#')) # remove weird #formatting# @@ -166,9 +167,11 @@ def refresh_data(filename, fmt=None, update_existing=False): elif fmt['dataformat'] is DataFormat.PERSON_RESOURCE: rzs, source_id = get_by_id(row['Resource'], Resource, first=False) - if not rzs or not rzs.first(): continue + if not rzs or not rzs.first(): + continue ppl, source_id = get_by_id(row['Person'], Person, first=False) - if not ppl or not ppl.first(): continue + if not ppl or not ppl.first(): + continue for person in ppl: person.resources = [] for r in rzs: diff --git a/app/models.py b/app/models.py index 665e953..bc71105 100644 --- a/app/models.py +++ b/app/models.py @@ -666,10 +666,17 @@ Involved scientist''') return False def index(self): - self.field_indexer = " ".join([ - self.first_name, self.last_name, self.organisation, self.position, self.biography - ]) - return True + if self: + self.field_indexer = " ".join([ + self.first_name if self and self.first_name else "", + self.last_name if self and self.last_name else "", + self.organisation if self and self.organisation else "", + self.position if self and self.position else "", + self.biography if self and self.biography else "" + ] if self else []) + return True + else: + return False def fullname(self): return " ".join([self.title if self.title else '',