Commit 35c12500 authored by Okhin's avatar Okhin
Browse files

Fixing the per country and operator listings #22

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