Browse Source

Adiciona seletor UF no chart de uso dos serviços

pull/159/head
Sesostris Vieira 3 years ago
parent
commit
8e82286e96
  1. 29
      sigi/apps/home/templates/home/dashboard/ufs_snippet.html
  2. 26
      sigi/apps/home/views.py

29
sigi/apps/home/templates/home/dashboard/ufs_snippet.html

@ -0,0 +1,29 @@
{% load static i18n %}
<ul class="collapsible uf_selector">
<li>
<div class="collapsible-header">
{% if uf %}
{{ uf.nome }}
{% else %}
{% trans "Todo o país" %}
{% endif %}
</div>
<div class="collapsible-body">
<ul>
<li>
<a class="dashlink" href="{% url "home_chartusoservico" %}?uf=_all" data-target="chartusoservico">
{% trans "Todo o país" %}
</a>
</li>
{% for uf in ufs %}
<li>
<a class="dashlink" href="{% url "home_chartusoservico" %}?uf={{ uf.sigla|safe }}" data-target="chartusoservico-chart">
{{uf.nome|title }}
</a>
</li>
{% endfor %}
</ul>
</div>
</li>
</ul>

26
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)

Loading…
Cancel
Save