From 066d1d85820ab2cfa254fa78ec72942d599907af Mon Sep 17 00:00:00 2001 From: Okhin Date: Mon, 15 Feb 2016 17:47:30 +0100 Subject: [PATCH] Soem work done on the ListViews #22 --- bt/views.py | 31 +++++++++++++++++++------------ nnmon/templates/list.html | 1 - 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/bt/views.py b/bt/views.py index 8df7f12..c56628a 100644 --- a/bt/views.py +++ b/bt/views.py @@ -221,12 +221,19 @@ class ViolationsList(ListView): def get_queryset(self): queryset = Violation.objects.filter(activationid='') - if 'all' not in self.request.GET: - queryset = queryset.exclude(state__in=['duplicate', 'closed']) - if 'country' in self.kwargs: - queryset = queryset.filter(country=self.kwargs['country']) if 'operator' in self.kwargs: - queryset = queryset.filter(operator_ref__name=self.kwargs['operator']) + # If i Have operator I have a country + queryset = Violation.objects.filter(activationid='', + country=self.kwargs['country'], + operator_ref__name=self.kwargs['operator']) + elif '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.objects.filter(activationid='').exclude(state__in=['duplicate', 'closed']) return queryset def get_context_data(self, **kwargs): @@ -234,13 +241,13 @@ class ViolationsList(ListView): if 'country' in self.kwargs: context['country'] = self.kwargs['country'] - - countries = sorted([(i['total'], i['country']) - for i in Violation.objects.values('country').filter(activationid='').exclude(state__in=['duplicate', 'closed']).annotate(total=Count('country'))], - reverse=True) - countryweights=json.dumps([{'iso2': y, 'w': x} for x, y in countries]) - context['countries'] = countries - context['countryweights'] = countryweights + else: + countries = sorted([(i['total'], i['country']) + for i in Violation.objects.values('country').filter(activationid='').exclude(state__in=['duplicate', 'closed']).annotate(total=Count('country'))], + reverse=True) + countryweights=json.dumps([{'iso2': y, 'w': x} for x, y in countries]) + context['countries'] = countries + context['countryweights'] = countryweights return context class ViolationView(DetailView): diff --git a/nnmon/templates/list.html b/nnmon/templates/list.html index a71f5ee..dc854ba 100644 --- a/nnmon/templates/list.html +++ b/nnmon/templates/list.html @@ -122,5 +122,4 @@ {% endfor %} - {%endblock%} -- GitLab