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 ...@@ -25,6 +25,7 @@ from email.header import Header
from urlparse import urljoin from urlparse import urljoin
from BeautifulSoup import BeautifulSoup, Comment as BComment from BeautifulSoup import BeautifulSoup, Comment as BComment
from operator import itemgetter from operator import itemgetter
from itertools import groupby
def sanitizeHtml(value, base_url=None): def sanitizeHtml(value, base_url=None):
rjs = r'[\s]*(&#x.{1,7})?'.join(list('javascript:')) rjs = r'[\s]*(&#x.{1,7})?'.join(list('javascript:'))
...@@ -212,7 +213,7 @@ class AddForm(FormView): ...@@ -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'))], for i in Violation.objects.values('operator_ref__name').filter(activationid='').exclude(state__in=['closed', 'ooscope', 'duplicate']).annotate(total=Count('confirmation'))],
reverse=True) reverse=True)
context['stats'] = [ 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])), (_('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]))] (_('Operators with some confirmed reports'), len([i for i,z in operators if i>0]))]
return context return context
...@@ -265,6 +266,25 @@ class LookupView(JSONMixin, SearchView): ...@@ -265,6 +266,25 @@ class LookupView(JSONMixin, SearchView):
queryset = Violation.objects.filter(activationid='') queryset = Violation.objects.filter(activationid='')
form_class = SearchViolation 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): def get_attach(request,id):
f = get_object_or_404(Attachment, pk=id) f = get_object_or_404(Attachment, pk=id)
wrapper = FileWrapper(f.storage) wrapper = FileWrapper(f.storage)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
{% load i18n %} {% load i18n %}
{% block active_tab_home %}id="current"{% endblock %} {% block active_tab_home %}id="current"{% endblock %}
{% block styles %} {% 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 %} {% endblock %}
{% block scripts %} {% block scripts %}
...@@ -133,7 +133,7 @@ $(document).ready(function(){ ...@@ -133,7 +133,7 @@ $(document).ready(function(){
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
</div> </div>
</div> </div>
{%endblock%} {%endblock%}
...@@ -3,77 +3,45 @@ ...@@ -3,77 +3,45 @@
{% load i18n %} {% load i18n %}
{% block active_tab_search %}id="current"{% endblock %} {% block active_tab_search %}id="current"{% endblock %}
{% block styles %} {% 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 %} {% endblock %}
{% block head %} {% 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 %} {% endblock %}
{% block scripts %} {% block scripts %}
<script type="text/javascript" src="/static/js/jquery.min.js"></script> <script type="text/javascript">
<script type="text/javascript" src="/static/js/jquery.tablesorter.js"></script> var data={% if countryweights %}{{countryweights|safe}}{%else%}[]{% endif %};
<script type="text/javascript" src="/static/js/picnet.table.filter.min.js"></script> var country="{{country}}";
<script type="text/javascript" src='/static/js/d3.min.js'></script> $.tablesorter.addParser({
<script type="text/javascript" src='/static/js/topojson.min.js'></script> // set a unique id
<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
id: 'stateparser', id: 'stateparser',
is: function(s) { is: function(s) {
/ return false so this parser is not auto detected // return false so this parser is not auto detected
return false; return false;
}, },
format: function(s) { 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 %}; 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' type: 'numeric'
}); });
$("#sortedlist").tablesorter({ </script>
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>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<div id="global"> <div id="global">
{% if messages %} {% if messages %}
<ul class="messages"> <ul class="messages">
{% for message in messages %} {% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li> <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endif %} {% endif %}
{% trans "Search through cases" %} {% trans "Search through cases" %}
<div id="map"> </div> <div id="map"> </div>
<form method="get" action="."> <form method="get" action=".">
{{ form.as_p }} {{ form.as_p }}
<input type="submit" value="Search"> <input type="submit" value="Search">
...@@ -82,7 +50,15 @@ ...@@ -82,7 +50,15 @@
{% if query %} {% if query %}
<h3>Results</h3> <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> <thead>
<tr> <tr>
<th filter-type='ddl'>{% trans "Status" %}</th> <th filter-type='ddl'>{% trans "Status" %}</th>
...@@ -97,7 +73,7 @@ ...@@ -97,7 +73,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <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"> <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 }}">{%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> <td><a class="cell-link" href="{{ result.object.get_absolute_url }}">{{ result.object.country|country }}</a></td>
...@@ -125,17 +101,17 @@ ...@@ -125,17 +101,17 @@
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
{% if page.has_previous or page.has_next %} {% if page.has_previous or page.has_next %}
<div> <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_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 %} {% if page.has_next %}<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">{% endif %}Next &raquo;{% if page.has_next %}</a>{% endif %}
</div> </div>
{% endif %} {% endif %}
{% else %} {% else %}
{# Show some example queries to run, maybe query syntax, something else? #} </div>
{% endif %} {% endif %}
</div> </div>
{% endblock %} {% endblock %}
...@@ -81,7 +81,7 @@ urlpatterns = patterns('', ...@@ -81,7 +81,7 @@ urlpatterns = patterns('',
url(r'^api/', url(r'^api/',
include(operator_api_resource.urls)), include(operator_api_resource.urls)),
url(r'^search/', url(r'^search/',
include('haystack.urls')), bt.ViolationSearchView.as_view(template_name='search/search.html')),
) )
if settings.DEV_SERVER == True: 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