From 8e82286e96c11720d1b450a665e25fcf3e3ec1e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Tue, 17 May 2022 10:36:56 -0300 Subject: [PATCH] =?UTF-8?q?Adiciona=20seletor=20UF=20no=20chart=20de=20uso?= =?UTF-8?q?=20dos=20servi=C3=A7os?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/home/dashboard/ufs_snippet.html | 29 +++++++++++++++++++ sigi/apps/home/views.py | 26 +++++++++++++---- 2 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 sigi/apps/home/templates/home/dashboard/ufs_snippet.html diff --git a/sigi/apps/home/templates/home/dashboard/ufs_snippet.html b/sigi/apps/home/templates/home/dashboard/ufs_snippet.html new file mode 100644 index 0000000..96c44f9 --- /dev/null +++ b/sigi/apps/home/templates/home/dashboard/ufs_snippet.html @@ -0,0 +1,29 @@ +{% load static i18n %} + + \ No newline at end of file diff --git a/sigi/apps/home/views.py b/sigi/apps/home/views.py index 33a8b01..edcd724 100644 --- a/sigi/apps/home/views.py +++ b/sigi/apps/home/views.py @@ -410,17 +410,28 @@ def chart_seit(request): @login_required def chart_uso_servico(request): colors, highlights = color_palete() + ufs = UnidadeFederativa.objects.all() + sigla_uf = request.GET.get("uf", "_all") + + if sigla_uf != "_all": + uf = get_object_or_404(UnidadeFederativa, sigla=sigla_uf) + else: + uf = None + counts = { f"{key}_count": Count("servico", Q(servico__resultado_verificacao=key)) for key, *__ in Servico.RESULTADO_CHOICES } - queryset = ( - TipoServico.objects.exclude(string_pesquisa="") - .filter(servico__data_desativacao=None) - .annotate(**counts) + queryset = TipoServico.objects.exclude(string_pesquisa="").filter( + servico__data_desativacao=None ) + if uf is not None: + queryset = queryset.filter(servico__casa_legislativa__municipio__uf=uf) + + queryset = queryset.annotate(**counts) + chart = { "data": { "datasets": [ @@ -435,7 +446,12 @@ def chart_uso_servico(request): for key, label in Servico.RESULTADO_CHOICES ], "labels": list(queryset.values_list("sigla", flat=True)), - } + }, + "actionblock": render_to_string( + "home/dashboard/ufs_snippet.html", + context={"ufs": ufs, "uf": uf}, + request=request, + ), } return JsonResponse(chart)