Commit 5527d331 authored by Okhin's avatar Okhin

Fixing the lookup SearchView

parent fd1fbad5
......@@ -38,13 +38,13 @@ class AddViolation(forms.Form):
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(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?'))
country = forms.ChoiceField(required=False, choices=(('',''),)+tuple(sorted(COUNTRIES,key=itemgetter(1))), label=_("Country"), help_text=_('EU member state where the restriction is reported.'))
operator = forms.CharField(required=False, max_length=256, label=_("Operator"), help_text=_('The ISP or operator providing the Internet service.'))
contract = forms.CharField(required=False, max_length=256, label=_("Contract"), help_text=_('The specific contract at the ISP provider. (please be as specific as possible)'))
media = forms.ChoiceField(required=False, 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
# By default, the search field is q. So let's check if it's empty
if not self.cleaned_data['q']:
sqs = SearchQuerySet().all()
else:
......
from django.core.serializers import serialize
from django.db.models.query import QuerySet
from django.template import Library
from haystack.models import SearchResult
import json
register = Library()
def jsonify(object):
if isinstance(object, QuerySet):
return serialize('json', object)
elif isinstance(object[0], SearchResult):
return serialize('json', [x.object for x in object])
else:
return json.dumps(object)
register.filter('jsonify', jsonify)
......@@ -6,6 +6,7 @@ from django.shortcuts import render_to_response, get_object_or_404, redirect
from django.template import RequestContext, loader, Context
from django.core.files import File
from django.core.servers.basehttp import FileWrapper
from django.core import serializers
from django.conf import settings
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.core.exceptions import ObjectDoesNotExist
......@@ -15,6 +16,7 @@ from django.contrib.auth.models import User
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 tempfile import mkstemp
from datetime import datetime
......@@ -142,14 +144,6 @@ def sendverifymail(service,to,body):
return actid
class JSONMixin(object):
def get(self, request, *args, **kwargs):
qs = self.get_queryset()
if qs.count():
return HttpResponse(json.dumps(sorted([(x.id, x.resource_name) for x in qs])))
else:
return HttpResponse('')
class AddForm(FormView):
model = Violation
template_name = 'index.html'
......@@ -262,11 +256,12 @@ class ViolationView(DetailView):
raise Http404
return object
class LookupView(JSONMixin, SearchView):
queryset = Violation.objects.filter(activationid='')
class LookupView(SearchView):
form_class = SearchViolation
class ViolationSearchView(SearchView):
form_class = SearchViolation
def get_context_data(self, *args, **kwargs):
context = super(ViolationSearchView, self).get_context_data(*args, **kwargs)
countries = sorted([(k, len(list(g)),) for k, g in groupby(sorted([i['country'] for i in self.queryset.values('country')]))])
......
......@@ -93,43 +93,43 @@
<ul style="padding:0; max-width:800px; margin:0 auto;">
<li class="logo-org">
<a href="https://www.laquadrature.net/">
<img alt="LQDN logo" src="static/img/logos/la-quadrature-du-net.png" /><br>
<img alt="LQDN logo" src="/static/img/logos/la-quadrature-du-net.png" /><br>
La Quadrature du Net
</a>
</li>
<li class="logo-org">
<a href="https://www.bof.nl/">
<img alt="BoF logo" src="static/img/logos/Bits-of-Freedom.png" /><br>
<img alt="BoF logo" src="/static/img/logos/Bits-of-Freedom.png" /><br>
Bits of Freedom
</a>
</li>
<li class="logo-org">
<a href="https://edri.org/">
<img alt="EDRI logo" src="static/img/logos/edri.png" /><br>
<img alt="EDRI logo" src="/static/img/logos/edri.png" /><br>
European Digital Rights
</a>
</li>
<li class="logo-org">
<a href="https://netzfreiheit.org/">
<img alt="Netzfreiheit logo" src="static/img/logos/netzfreiheit.png" /><br>
<img alt="Netzfreiheit logo" src="/static/img/logos/netzfreiheit.png" /><br>
Initiative für Netzfreiheit
</a>
</li>
<li class="logo-org">
<a href="http://nurpa.be/">
<img alt="NURPA logo" src="static/img/logos/nurpa.png" /><br>
<img alt="NURPA logo" src="/static/img/logos/nurpa.png" /><br>
Nurpa
</a>
</li>
<li class="logo-org">
<a href="https://www.openrightsgroup.org/">
<img alt="ORG logo" src="static/img/logos/org.png" /><br>
<img alt="ORG logo" src="/static/img/logos/org.png" /><br>
Open Rights Group
</a>
</li>
<li class="logo-org">
<a href="https://xnet-x.net">
<img alt="Xnet logo" src="static/img/logos/Xnet.png" /><br>
<img alt="Xnet logo" src="/static/img/logos/Xnet.png" /><br>
Xnet
</a>
</li>
......
......@@ -13,13 +13,13 @@
event.preventDefault();
$.getJSON(
url="/lookup/",
data="country=FR",
// {
// country:
// q:
// operator:
// type:
// }
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);
$('#similar_modal').modal('show');
......
{% load json_filters %}
{{ object_list|jsonify }}
......@@ -103,12 +103,6 @@ $.tablesorter.addParser({
</tbody>
</table>
{% 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 %}
</div>
......
......@@ -59,8 +59,8 @@ urlpatterns = patterns('',
url(r'^moderate/$',
view=bt.moderate,
name="moderate"),
url(r'^lookup/$',
view=bt.LookupView.as_view(),
url(r'^lookup/',
view=bt.LookupView.as_view(template_name='search/lookup.json'),
name="lookup"),
url(r'^accounts/logout$',
'django.contrib.auth.views.logout', {'next_page': '/'}),
......
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