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'))],
reverse=True)
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(f.storage)
......
......@@ -3,7 +3,7 @@
{% load i18n %}
{% block active_tab_home %}id="current"{% endblock %}
{% block styles %}
<link rel="stylesheet" type="text/css" media="all" href="/static/css/jquery-ui.css" />
<link rel="stylesheet" type="text/css" media="all" href="/static/css/jquery-ui.css" />
{% endblock %}
{% block scripts %}
......@@ -133,7 +133,7 @@ $(document).ready(function(){
</tr>
{% endfor %}
</tbody>
</table>
</table>
</div>
</div>
{%endblock%}
......@@ -3,77 +3,45 @@
{% load i18n %}
{% block active_tab_search %}id="current"{% endblock %}
{% block styles %}
<link rel="stylesheet" href="/static/css/map.css" type="text/css" />
<link rel="stylesheet" href="/static/css/map.css" type="text/css" />
{% endblock %}
{% block head %}
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{% endblock %}
{% block scripts %}
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/jquery.tablesorter.js"></script>
<script type="text/javascript" src="/static/js/picnet.table.filter.min.js"></script>
<script type="text/javascript" src='/static/js/d3.min.js'></script>
<script type="text/javascript" src='/static/js/topojson.min.js'></script>
<script type="text/javascript" src='/static/js/datamaps.js'></script>
<script type="text/javascript" src="/static/js/map.js"></script>
<script type="text/javascript">
var data={% if countryweights %}{{countryweights|safe}}{%else%}[]{% endif %};
var country="{{country}}";
$(document).ready(function() {
$.tablesorter.addParser({
/ set a unique id
<script type="text/javascript">
var data={% if countryweights %}{{countryweights|safe}}{%else%}[]{% endif %};
var country="{{country}}";
$.tablesorter.addParser({
// set a unique id
id: 'stateparser',
is: function(s) {
/ return false so this parser is not auto detected
// return false so this parser is not auto detected
return false;
},
format: function(s) {
/ format your data for normalization
// format your data for normalization
return s{% for s, translation in status %}.replace(/{{translation}}/,{{forloop.counter}}){% endfor %};
},
/ set type, either numeric or text
// set type, either numeric or text
type: 'numeric'
});
$("#sortedlist").tablesorter({
headers: { 8: { sorter: false },
0: { sorter: 'stateparser' }},
sortList: [[1,0],[0,0],[7,1]],
});
var options = { enableCookies: false };
$('#sortedlist').tableFilter(options);
$('.confirm_form').submit(function() {
var self=this;
var email=$(this).find('input:first').attr('value');
if( email.length>0) {
$.ajax({url: '/confirm/'+$(this).attr('id').slice(1)+'/'+email, success: function(data) { $(self).html(data); }});
} else {
$(this).find('[type=text]').focus();
}
return false;
});
$(".confirm > .button").click(function(){
$(this).parent().parent().parent().find('.info-validate').toggle();
});
$(".cancel-button").click(function(){
$(this).parent().hide();
});
});
</script>
});
</script>
{% endblock %}
{% block content %}
<div id="global">
{% if messages %}
<ul class="messages">
{% if messages %}
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% trans "Search through cases" %}
<div id="map"> </div>
</ul>
{% endif %}
{% trans "Search through cases" %}
<div id="map"> </div>
<form method="get" action=".">
{{ form.as_p }}
<input type="submit" value="Search">
......@@ -82,7 +50,15 @@
{% if query %}
<h3>Results</h3>
<table class="listing tablesorter zebra-striped" id='sortedlist'>
<h2 id="stats-title">{% trans "Statistics" %}</h2>
<ul id="stats">
{% for t, n in stats %}
<li class="stat"><dl><dt class="inline">{{t}}</dt><dd class="inline"><strong>{{n}}</strong></dd></dl></li>
{% endfor %}
</ul>
</div>
<table class="listing tablesorter zebra-striped" id='sortedlist'>
<thead>
<tr>
<th filter-type='ddl'>{% trans "Status" %}</th>
......@@ -97,7 +73,7 @@
</tr>
</thead>
<tbody>
{% for result in page.object_list %}
{% for result in object_list %}
<tr class="{%if result.object.state%}{{result.object.state}}{%else%}new{%endif%}-status">
<td><a class="cell-link" href="{{ result.object.get_absolute_url }}">{%if result.object.state%}{{result.object.state|status}}{%else%}{% trans "New" %}{%endif%}</a></td>
<td><a class="cell-link" href="{{ result.object.get_absolute_url }}">{{ result.object.country|country }}</a></td>
......@@ -125,17 +101,17 @@
</tr>
{% endfor %}
</tbody>
</table>
</table>
{% if page.has_previous or page.has_next %}
<div>
{% if page.has_previous or page.has_next %}
<div>
{% if page.has_previous %}<a href="?q={{ query }}&amp;page={{ page.previous_page_number }}">{% endif %}&laquo; Previous{% if page.has_previous %}</a>{% endif %}
|
{% if page.has_next %}<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">{% endif %}Next &raquo;{% if page.has_next %}</a>{% endif %}
</div>
{% endif %}
{% else %}
{# Show some example queries to run, maybe query syntax, something else? #}
{% endif %}
</div>
{% endif %}
{% else %}
</div>
{% endif %}
</div>
{% endblock %}
......@@ -81,7 +81,7 @@ urlpatterns = patterns('',
url(r'^api/',
include(operator_api_resource.urls)),
url(r'^search/',
include('haystack.urls')),
bt.ViolationSearchView.as_view(template_name='search/search.html')),
)
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