Commit 9475f340 authored by Okhin's avatar Okhin

Improving the search page with map coloration and stats

parent a45c07ef
......@@ -25,6 +25,7 @@ from email.header import Header
from urlparse import urljoin
from BeautifulSoup import BeautifulSoup, Comment as BComment
from operator import itemgetter
from itertools import groupby
def sanitizeHtml(value, base_url=None):
rjs = r'[\s]*(&#x.{1,7})?'.join(list('javascript:'))
......@@ -212,7 +213,7 @@ class AddForm(FormView):
for i in Violation.objects.values('operator_ref__name').filter(activationid='').exclude(state__in=['closed', 'ooscope', 'duplicate']).annotate(total=Count('confirmation'))],
context['stats'] = [
(_('Total confirmed reorts'), len([i for i,z in reports if i>0])),
(_('Total confirmed reports'), len([i for i,z in reports if i>0])),
(_('Countries with some confirmed reports'), len([i for i,z in confirms if i>0])),
(_('Operators with some confirmed reports'), len([i for i,z in operators if i>0]))]
return context
......@@ -265,6 +266,25 @@ class LookupView(JSONMixin, SearchView):
queryset = Violation.objects.filter(activationid='')
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')]))]
countryweights=json.dumps([{'iso2': y, 'w': x} for x, y in countries])
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()),
return context
def get_attach(request,id):
f = get_object_or_404(Attachment, pk=id)
wrapper = FileWrapper(
This diff is collapsed.
This diff is collapsed.
......@@ -81,7 +81,7 @@ urlpatterns = patterns('',
if settings.DEV_SERVER == True:
Markdown is supported
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