Commit 0ac46074 authored by Okhin's avatar Okhin
Browse files

Upgrading the search function

parent 435000e5
......@@ -7,6 +7,10 @@ class ViolationIndexes(indexes.SearchIndex, indexes.Indexable):
country = indexes.CharField(model_attr="country")
contract = indexes.CharField(model_attr="contract_excerpt")
type = indexes.BooleanField(model_attr="contractual")
operator_name = indexes.CharField()
def get_model(self):
return Violation
def prepare_operator_name(self, obj):
......@@ -267,21 +267,18 @@ class LookupView(JSONMixin, SearchView):
form_class = SearchViolation
class ViolationSearchView(SearchView):
def get_queryset(self):
"""Let's strip the queryset form the non needed items."""
queryset = super(ViolationSearchView, self).get_queryset()
return queryset.filter(annotationid='').exclude(state__in=['closed', 'ooscope', 'duplicate'])
def get_context_data(self, *args, **kwargs):
context = super(ViolationSearchView, self).get_context_data(*args, **kwargs)
countries = [(k, len(g),) for k,g in groupby(sorted([i['country'] for i in self.queryset.values('country')]))]
countries = sorted([(k, len(list(g)),) for k, g in groupby(sorted([i['country'] for i in self.queryset.values('country')]))])
countryweights=json.dumps([{'iso2': y, 'w': x} for x, y in countries])
operators = sorted([(k, len(list(g)),) for k, g in groupby(sorted([i['operator_name'] for i in self.queryset.values('operator_name')]))])
context['operators'] = operators
context['countries'] = countries
context['countryweights'] = countryweights
context['stats'] = [
(_('Number of reports in this search'), self.queryset.count()),
(_('Countries with some confirmed reports'), self.queryset.values('country').count()),
(_('Operators with some confirmed reports'), self.queryset.values('operator_ref__name').count()),
(_('Number of reports in this search'), len(self.queryset.all())),
(_('Countries with some confirmed reports'), len([c for c,v in countries if v > 0])),
(_('Operators with some confirmed reports'), len([c for c,v in operators if v > 0])),
return context
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment