def get_name(self, obj): query_value = self.context.get('query_value') if query_value: highlight = CustomHighlighter(query_value, max_length=100) return highlight.highlight(obj.name) else: return obj.name
def process_sites_search(sites, site_results, query): highlighter = CustomHighlighter(query, max_length=100) for site in sites: if site.location_site_id not in site_results: site_results[site.location_site_id] = { COUNT_LABEL: 0, NAME_LABEL: highlighter.highlight(site.location_site_name) } else: continue return site_results
def process_search( collection_result, query_value, taxon_results, site_results): highlighter = CustomHighlighter(query_value, max_length=100) # calculate taxon for collection in collection_result: if collection.taxon_gbif not in taxon_results: taxon_results[collection.taxon_gbif] = { COUNT_LABEL: 1, NAME_LABEL: collection.original_species_name, HIGHLIGHTER_LABEL: highlighter.highlight( collection.original_species_name), COLLECTION_IDS: [ collection.pk ] } else: if collection.pk not in taxon_results[collection.taxon_gbif][ COLLECTION_IDS]: taxon_results[collection.taxon_gbif][COUNT_LABEL] += 1 taxon_results[collection.taxon_gbif][ COLLECTION_IDS].append(collection.pk) if collection.location_site_id not in site_results: site_results[collection.location_site_id] = { COUNT_LABEL: 1, NAME_LABEL: collection.location_site_name, COLLECTION_IDS: [ collection.pk ] } else: if collection.pk not in site_results[ collection.location_site_id][COLLECTION_IDS]: site_results[collection.location_site_id][ COUNT_LABEL] += 1 site_results[collection.location_site_id][ COLLECTION_IDS].append( collection.pk) return taxon_results, site_results
def get_highlighted_common_name(self, obj): query_value = self.context.get('query_value') highlight = CustomHighlighter(query_value, max_length=100) return highlight.highlight(obj.common_name)