Commit 066d1d85 authored by Okhin's avatar Okhin

Soem work done on the ListViews #22

parent 33b7d8ce
...@@ -221,12 +221,19 @@ class ViolationsList(ListView): ...@@ -221,12 +221,19 @@ class ViolationsList(ListView):
def get_queryset(self): def get_queryset(self):
queryset = Violation.objects.filter(activationid='') 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: 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 return queryset
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
...@@ -234,13 +241,13 @@ class ViolationsList(ListView): ...@@ -234,13 +241,13 @@ class ViolationsList(ListView):
if 'country' in self.kwargs: if 'country' in self.kwargs:
context['country'] = self.kwargs['country'] context['country'] = self.kwargs['country']
else:
countries = sorted([(i['total'], i['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'))], for i in Violation.objects.values('country').filter(activationid='').exclude(state__in=['duplicate', 'closed']).annotate(total=Count('country'))],
reverse=True) reverse=True)
countryweights=json.dumps([{'iso2': y, 'w': x} for x, y in countries]) countryweights=json.dumps([{'iso2': y, 'w': x} for x, y in countries])
context['countries'] = countries context['countries'] = countries
context['countryweights'] = countryweights context['countryweights'] = countryweights
return context return context
class ViolationView(DetailView): class ViolationView(DetailView):
......
...@@ -122,5 +122,4 @@ ...@@ -122,5 +122,4 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
</div>
{%endblock%} {%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