Commit 5e702c47 authored by Okhin's avatar Okhin

A hell of work done, need to finish the table and to fix the me too button

parent 5527d331
......@@ -54,10 +54,10 @@ class SearchViolation(SearchForm):
return self.no_query_found()
if self.cleaned_data['operator']:
sqs = sqs.filter(operator=self.cleaned_data['operator'])
sqs = sqs.filter(operator__icontains=self.cleaned_data['operator'])
if self.cleaned_data['contract']:
sqs = sqs.filter(contract=self.cleaned_data['contract'])
sqs = sqs.filter(contract__icontains=self.cleaned_data['contract'])
if self.cleaned_data['media']:
sqs = sqs.filter(media=self.cleaned_data['media'])
......
......@@ -5,9 +5,11 @@ class ViolationIndexes(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
operator = indexes.CharField(model_attr="operator_ref")
country = indexes.CharField(model_attr="country")
contract = indexes.CharField(model_attr="contract_excerpt")
type = indexes.BooleanField(model_attr="contractual")
contract = indexes.CharField(model_attr="contract")
type = indexes.CharField(model_attr="contractual")
media = indexes.CharField(model_attr="media")
operator_name = indexes.CharField()
state = indexes.NgramField(model_attr="state")
def get_model(self):
return Violation
......
......@@ -9,6 +9,8 @@ register = Library()
def jsonify(object):
if isinstance(object, QuerySet):
return serialize('json', object)
elif object == []:
return json.dumps(object)
elif isinstance(object[0], SearchResult):
return serialize('json', [x.object for x in object])
else:
......
......@@ -17,7 +17,7 @@ from django.utils.translation import ugettext_lazy as _
from django.db.models import Count
from haystack.generic_views import SearchView
from haystack.query import SearchQuerySet
from models import Violation, Attachment, Comment, Confirmation, COUNTRIES, STATUS, Operator
from models import Violation, Attachment, Comment, Confirmation, COUNTRIES, STATUS, Operator, FeaturedCase
from tempfile import mkstemp
from datetime import datetime
import hashlib, os, re, json
......@@ -210,6 +210,7 @@ class AddForm(FormView):
(_('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]))]
context['violations'] = [fc.case for fc in FeaturedCase.objects.all()]
return context
class ViolationsList(ListView):
......
......@@ -11,20 +11,55 @@
<script type="text/javascript">
$("#lookup_btn").click(function(event) {
event.preventDefault();
$.getJSON(
url="/lookup/",
data={
$.ajax({
dataType: "json",
url: "/lookup/",
data: {
country: $("#id_country").val(),
q: $("#id_ressource").val(),
operator: $("#id_operator").val(),
contract: $("#id_contract").val(),
media: $("#id_media").val(),
},
success=function(data){
console.log(data);
success: function(data) {
var filtered = data.filter(function(data) {
return data.fields.state in ["ooscope", "duplicate"]
});
if (filtered.length == 0) {
$("#lookup_btn").hide();
$("#collapseField").collapse('show');
return;
}
filtered = filtered.slice(0, 10);
$.each(filtered, function(key, obj) {
if (obj.fields.state in ["ooscope", "duplicate"]) {
return;
};
$("#modal-list").append(
"<dt>" + obj.fields.resource + "</dt>" +
"<dd><p>" + obj.fields.editorial + "</p>" +
"<div class=\"confirm\"><a class=\"btn btn-default\">{% trans "Me Too" %}</a>" +
"<div class=\"info-validate float-confirm\">" +
"<form method=\"get\" action=\"\" id=\"i" + obj.pk + "\" class=\"confirm_form\">" +
"<div>" +
"<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=\"{{obj.pk}}\" />" +
"<input type=\"submit\" value=\"{% trans "Ok" %}\" />" +
"</div>" +
"</form>" +
"</div>" +
"</dd>"
);
});
$('#similar_modal').modal('show');
console.log("Modal displayed");
},
error: function(xhr, status, err) {
console.log(err, xhr);
}
);
});
});
$("#btn_dismiss").click(function(event) {
......@@ -65,7 +100,7 @@
{% endfor %}
</ul>
<h2 id="featured-title">{% trans "Featured Cases" %}</h2>
<table id="featured_cases">
<table class="table table-stripped" id="featured_cases">
<thead>
<tr>
<th style="width: 70%;">{% trans "Infringing offering" %}</th>
......@@ -154,6 +189,9 @@
</div>
<div class="modal-body">
<p>{% trans "Those are cases that might be similar to yours, please feel free to add your input on those cases instead of adding yours if they overlap." %}</p>
<dl id="modal-list">
</dl>
</table>
</div>
<div class="modal-footer">
<button type="button" id="btn_dismiss" class="btn btn-default" data-dismiss="modal">{% trans "Dismiss" %}</button>
......
......@@ -54,7 +54,7 @@ $.tablesorter.addParser({
<th filter-type='ddl' class="col-sm-1">{% trans "country" %}</th>
<th filter-type='ddl' class="col-sm-1">{% trans "operator" %}</th>
<th filter-type='ddl' class="col-sm-2">{% trans "contract" %}</th>
<th filter-type='ddl' class="col-sm-3">{% trans "resource" %}</th>
<th filter-type='ddl' class="col-sm-2">{% trans "resource" %}</th>
<th filter-type='ddl' class="col-sm-1">{% trans "type" %}</th>
<th filter-type='ddl' class="col-sm-1">{% trans "fixed / wireless" %}</th>
<th filter='false' class="col-sm-1">{% trans "confirmations" %}</th>
......
{% load json_filters %}
{{ object_list|jsonify }}
{{ object_list|jsonify|safe }}
......@@ -103,9 +103,6 @@ $.tablesorter.addParser({
</tbody>
</table>
{% endif %}
{% else %}
</div>
{% endif %}
</div>
{% 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