Commit ebc98d8a authored by Okhin's avatar Okhin
Browse files

Updating the search results page to look lke everything else, as welle as...

Updating the search results page to look lke everything else, as welle as using the SearchForm and SearchView for /lookup
parent c1e0f1d7
from django import forms
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from haystack.forms import SearchForm
from haystack.query import SearchQuerySet
from bt.models import Violation, COUNTRIES, RESOURCES, TYPES, MEDIA
from bt.multifile import MultiFileField
from operator import itemgetter
......@@ -35,8 +37,32 @@ class AddViolation(forms.Form):
contract_excerpt = forms.CharField(required=False, widget=AdvancedEditor(), label=_('Please copy the relevant section describing the restriction from the user contract. (optional)'))
captcha = CaptchaField(label=_("In order to protect against spam, please fill in the result of the following calculation. (note the + and the * are somewhat confusing)"))
class SearchViolation(forms.Form):
class SearchViolation(SearchForm):
country = forms.ChoiceField(required=True, choices=(('',''),)+tuple(sorted(COUNTRIES,key=itemgetter(1))), label=_("Country"), help_text=_('EU member state where the restriction is reported.'))
operator = forms.CharField(required=True, max_length=256, label=_("Operator"), help_text=_('The ISP or operator providing the Internet service.'))
contract = forms.CharField(required=True, max_length=256, label=_("Contract"), help_text=_('The specific contract at the ISP provider. (please be as specific as possible)'))
media = forms.ChoiceField(required=True, choices=(('',''),)+tuple(sorted(MEDIA,key=itemgetter(1))), label=_('Is the Internet connection over mobile or fixed line?'))
def search(self):
# By default, teh search field is q. So let's check if it's empty
if not self.cleaned_data['q']:
sqs = SearchQuerySet().all()
sqs = super(SearchViolation, self).search()
if not self.is_valid():
return self.no_query_found()
if self.cleaned_data['operator']:
sqs = sqs.filter(operator=self.cleaned_data['operator'])
if self.cleaned_data['contract']:
sqs = sqs.filter(contract=self.cleaned_data['contract'])
if self.cleaned_data['media']:
sqs = sqs.filter(media=self.cleaned_data['media'])
if self.cleaned_data['country']:
sqs = sqs.filter(country=self.cleaned_data['country'])
return sqs
from haystack import indexes
from models import Operator, Violation
class OperatorIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
def get_model(self):
return Operator
class ViolationIndexes(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
operator = indexes.CharField(model_attr="operator_ref")
......@@ -283,14 +283,8 @@ def lookup(request):
if request.method == 'GET':
form = SearchViolation(request.GET)
if form.is_valid():
country = form.cleaned_data['country'],
operator_ref__name = form.cleaned_data['operator'],
contract = form.cleaned_data['contract'],
media = form.cleaned_data['media'],
activationid = ''
res=json.dumps(sorted([(,x.resource_name) for x in v],reverse=True))
res=json.dumps(sorted([(,x.object.resource_name) for x in v],reverse=True))
return HttpResponse(res)
return HttpResponse('')
......@@ -3,13 +3,77 @@
{% load i18n %}
{% block active_tab_home %}id="current"{% endblock %}
{% block styles %}
<link rel="stylesheet" type="text/css" media="all" href="{% media_url %}/css/jquery-ui.css" />
<link rel="stylesheet" href="{{ MEDIA_URL }}/css/map.css" type="text/css" />
{% endblock %}
{% block head %}
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{% endblock %}
{% block scripts %}
<script type="text/javascript" src="{{ MEDIA_URL }}/js/jquery.min.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}/js/jquery.tablesorter.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}/js/picnet.table.filter.min.js"></script>
<script type="text/javascript" src='{{ MEDIA_URL }}/js/d3.min.js'></script>
<script type="text/javascript" src='{{ MEDIA_URL }}/js/topojson.min.js'></script>
<script type="text/javascript" src='{{ MEDIA_URL }}/js/datamaps.js'></script>
<script type="text/javascript" src="{{ MEDIA_URL }}/js/map.js"></script>
<script type="text/javascript">
var data={% if countryweights %}{{countryweights|safe}}{%else%}[]{% endif %};
var country="{{country}}";
$(document).ready(function() {
// set a unique id
id: 'stateparser',
is: function(s) {
// return false so this parser is not auto detected
return false;
format: function(s) {
// format your data for normalization
return s{% for s, translation in status %}.replace(/{{translation}}/,{{forloop.counter}}){% endfor %};
// set type, either numeric or text
type: 'numeric'
headers: { 8: { sorter: false },
0: { sorter: 'stateparser' }},
sortList: [[1,0],[0,0],[7,1]],
var options = { enableCookies: false };
$('.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 {
return false;
$(".confirm > .button").click(function(){
{% endblock %}
{% block content %}
<div id="global">
{% if messages %}
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
{% endif %}
{% trans "Search through cases" %}
<div id="map"> </div>
<form method="get" action=".">
{{ form.as_table }}
......@@ -20,19 +84,55 @@
{% if query %}
<table class="listing tablesorter zebra-striped" id='sortedlist'>
<th filter-type='ddl'>{% trans "Status" %}</th>
<th filter-type='ddl'>{% trans "country" %}</th>
<th filter-type='ddl'>{% trans "operator" %}</th>
<th filter-type='ddl'>{% trans "contract" %}</th>
<th filter-type='ddl'>{% trans "resource" %}</th>
<th filter-type='ddl'>{% trans "type" %}</th>
<th filter-type='ddl'>{% trans "fixed / wireless" %}</th>
<th filter='false'>{% trans "confirmations" %}</th>
<th filter='false'></th>
{% for result in page.object_list %}
<a href="{{ result.object.get_absolute_url }}">{{ result.text }}</a>
{% empty %}
<li>No results found.</li>
<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 }}">{{|country }}</a></td>
<td><a class="cell-link" href="{{ result.object.get_absolute_url }}">{{ result.object.operator }}</a></td>
<td><a class="cell-link" href="{{ result.object.get_absolute_url }}">{{ result.object.contract }}</a></td>
<td><a class="cell-link" href="{{ result.object.get_absolute_url }}">{{ result.object.resource_name }}</a></td>
<td><a class="cell-link" href="{{ result.object.get_absolute_url }}">{{ result.object.type|type }}</a></td>
<td><a class="cell-link" href="{{ result.object.get_absolute_url }}">{{|media }}</a></td>
<td>{{ result.object.confirmations }}</td>
<div class="confirm"><a class="button">{% trans "Me too!" %}</a>
<div class="info-validate float-confirm">
<form method="get" action="" id="i{{ }}" class="confirm_form" >
<label>{% trans "In order to <strong>confirm</strong> this report, please enter your email address" %}</label>
<input type="text" name="email" />
<input type="hidden" value="{{ }}" />
<input type="submit" value="{% trans "OK" %}" />
<input class="cancel-button" type="button" value="{% trans "Close" %}" />
{% endfor %}
{% if page.has_previous or page.has_next %}
......@@ -44,6 +144,5 @@
{% else %}
{# Show some example queries to run, maybe query syntax, something else? #}
{% endif %}
{% endblock %}
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