Commit 35c12500 authored by okhin's avatar okhin 🚴

Fixing the per country and operator listings #22

parent 65fc14c8
......@@ -144,7 +144,11 @@ def sendverifymail(service,to,body):
class JSONMixin(object):
def get(self, request, *args, **kwargs):
return HttpResponse(serializers.serialize('json', self.get_queryset()))
qs = self.get_queryset()
if qs.count():
return HttpResponse(json.dumps(sorted([(x.object.id, x.object.resource_name) for x in qs])))
else:
return HttpResponse('')
class AddForm(FormView):
model = Violation
......@@ -215,7 +219,6 @@ class AddForm(FormView):
return context
class ViolationsList(ListView):
queryset = Violation.objects.filter(activationid='')
template_name = 'list.html'
context_object_name = 'violations'
......@@ -226,12 +229,9 @@ class ViolationsList(ListView):
queryset = Violation.objects.filter(activationid='',
country=self.kwargs['country'],
operator_ref__name=self.kwargs['operator'])
elif 'country' in self.kwargs:
if 'country' in self.kwargs:
queryset = Violation.objects.filter(activationid='',
country=self.kwargs['country'])
if not queryset.count():
queryset = queryset.filter(activationid='',
operator_ref__name=self.kwargs['country'])
if 'all' not in self.request.GET:
queryset = queryset.filter(activationid='').exclude(state__in=['duplicate', 'closed'])
return queryset
......@@ -262,6 +262,10 @@ class ViolationView(DetailView):
raise Http404
return object
class LookupView(JSONMixin, SearchView):
queryset = Violation.objects.filter(activationid='')
form_class = SearchViolation
def get_attach(request,id):
f = get_object_or_404(Attachment, pk=id)
wrapper = FileWrapper(f.storage)
......@@ -270,19 +274,6 @@ def get_attach(request,id):
response['Content-Length'] = f.storage.size
return response
class LookupView(JSONMixin, SearchView):
model = Violation
form_class = SearchViolation
#def lookup(request):
# if request.method == 'GET':
# form = SearchViolation(request.GET)
# if form.is_valid():
# v=form.search()
# res=json.dumps(sorted([(x.object.id,x.object.resource_name) for x in v],reverse=True))
# return HttpResponse(res)
# return HttpResponse('')
def ascsv(request):
response = HttpResponse(mimetype='text/csv')
response['Content-Disposition'] = 'attachment; filename=respectmynet.csv'
......
......@@ -19,9 +19,12 @@ urlpatterns = patterns('',
url(r'^list/$',
view=bt.ViolationsList.as_view(),
name="list_violations"),
url(r'^list/(?P<country>[^/]*)(/(?P<operator>[^/]*))?/$',
url(r'^list/(?P<country>\w+)/$',
view=bt.ViolationsList.as_view(),
name="filter"),
name="filter_country"),
url(r'^list/(?P<country>\w+)/(?P<operator>\w+)/$',
view=bt.ViolationsList.as_view(),
name="filter_operator"),
# violation cannonical url and redirections
url(r'^(?P<id>[0-9]*)$',
RedirectView.as_view(url='/view/%(id)s')),
......
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