Fix search (fields and taxa not done yet)

This commit is contained in:
PCoder 2021-12-07 22:32:58 +05:30
parent dacd294911
commit 03313e2ee1
2 changed files with 10 additions and 10 deletions

View file

@ -675,9 +675,9 @@ Involved scientist''')
'fullname': self.fullname(), 'fullname': self.fullname(),
'organisation': self.organisation or '', 'organisation': self.organisation or '',
'position': self.position or '', 'position': self.position or '',
'country': self.country or '', 'country': self.country.short_name or '',
'personal_url': self.personal_url or '', 'personal_url': self.personal_url or '',
'personal_urls': self.personal_url.split(';'), 'personal_urls': [] if self.personal_url is None else self.personal_url.split(';'),
'biography': self.biography or '', 'biography': self.biography or '',
} }

View file

@ -21,7 +21,7 @@ from os import makedirs
from tempfile import gettempdir from tempfile import gettempdir
from .formats import * from .formats import *
from .convert import reindex_data, refresh_data from .convert import reindex_data, refresh_data
from .models import Person, RangesPeople, TaxaPeople, FieldsPeople, MethodsPeople, MountainRange, Field, Taxon, Resource from .models import Person, PeopleRange, TaxaPeople, FieldsPeople, MethodsPeople, MountainRange, Field, Taxon, Resource
# Get temporary file storage # Get temporary file storage
UPLOAD_PATH = gettempdir() UPLOAD_PATH = gettempdir()
@ -174,9 +174,9 @@ def get_paginated(query_set, page, per_page):
'taxon': [], 'taxon': [],
} }
for p in paginator.object_list: for p in paginator.object_list:
filters['country'].append(p.country) filters['country'].append(p.country.short_name)
for r in p.rangespeople_set.all(): for r in p.peoplerange_set.all():
filters['range'].append(r.range.name) filters['range'].append(r.range.range_name)
for r in p.fieldspeople_set.all(): for r in p.fieldspeople_set.all():
filters['field'].append(r.field.name) filters['field'].append(r.field.name)
for r in p.taxapeople_set.all(): for r in p.taxapeople_set.all():
@ -217,9 +217,9 @@ class SearchView(View):
q_field = self.request.GET.get('field', '') q_field = self.request.GET.get('field', '')
q_taxon = self.request.GET.get('taxon', '') q_taxon = self.request.GET.get('taxon', '')
if len(q_country) > 2: if len(q_country) > 2:
query_set = query_set.filter(country__icontains=q_country.strip().lower()) query_set = query_set.filter(country__short_name__icontains=q_country.strip().lower())
if len(q_range) > 2: if len(q_range) > 2:
ranges_people = RangesPeople.objects.filter(range__name__icontains=q_range.strip().lower()) ranges_people = PeopleRange.objects.filter(range__name__icontains=q_range.strip().lower())
r_people_ids = [rp.person_id for rp in ranges_people] r_people_ids = [rp.person_id for rp in ranges_people]
query_set = query_set.filter(id__in=r_people_ids) query_set = query_set.filter(id__in=r_people_ids)
if len(q_field) > 2: if len(q_field) > 2:
@ -272,9 +272,9 @@ class RangesListView(View):
def get(self, request): def get(self, request):
q = self.request.GET.get('q', '').strip() q = self.request.GET.get('q', '').strip()
if not q or len(q) < 3: if not q or len(q) < 3:
query_set = Range.objects.all().order_by('name')[:MAX_FILTER_RESULTS] query_set = MountainRange.objects.all().order_by('name')[:MAX_FILTER_RESULTS]
else: else:
query_set = Range.objects.filter(name__icontains=q.strip().lower()) query_set = MountainRange.objects.filter(name__icontains=q.strip().lower())
return JsonResponse(list(query_set.values()), safe=False) return JsonResponse(list(query_set.values()), safe=False)