Browse Source

Lista de Gerentes Interlegis

pull/163/head 3.0.27
Sesostris Vieira 2 years ago
parent
commit
7d180dded1
  1. 1
      sigi/apps/casas/admin_urls.py
  2. 93
      sigi/apps/casas/templates/admin/casas/gerentes_list.html
  3. 72
      sigi/apps/casas/views.py
  4. 2
      sigi/menu_conf.yaml

1
sigi/apps/casas/admin_urls.py

@ -3,4 +3,5 @@ from sigi.apps.casas import views
urlpatterns = [ urlpatterns = [
path("carteira/", views.painel_relacionamento, name="casas_carteira"), path("carteira/", views.painel_relacionamento, name="casas_carteira"),
path("gerentes/", views.GerentesListView.as_view(), name="casas_gerentes"),
] ]

93
sigi/apps/casas/templates/admin/casas/gerentes_list.html

@ -0,0 +1,93 @@
{% extends 'public/base_site.html' %}
{% load i18n static %}
{% block extrastyle %}
{{ block.super }}
<link rel="stylesheet" href="{% static 'ocorrencias/css/painel_ocorrencias.css' %}">
{% endblock extrastyle %}
{% block content %}
{{ block.super }}
{% for gerente in object_list %}
<div class="row">
<div class="col s12">
<div class="card hoverable">
<div class="card-content">
<div class="row">
<div class="col s3 m1 center-align">
{% if gerente.foto %}
<img class="circle user-image" src="{{ gerente.foto.url }}"/>
{% else %}
<i class="material-icons circle user-image">account_circle</i>
{% endif %}
</div>
<div class="col s9 m11">
<span class="card-title">
{{ gerente.nome_completo }}
<p class="card-details">
<a href="{% url 'openmap' %}?tipo_servico=ignore&tipo_convenio=ignore&gerente={{ gerente.id|stringformat:'s' }}" title="{% trans "Ver no mapa" %}">
{% blocktrans with total=gerente.tot_casas %}
Atende a {{ total }} casas legislativas.
</a>
{% endblocktrans %}
</p>
</span>
</div>
</div>
{% for regiao, tot_casas, ufs in gerente.regioes %}
<div class="row card-inbox">
<span class="inbox-title">
{{ regiao }}
</span>
<p class="card-details">
<a href="{% url 'openmap' %}?tipo_servico=ignore&tipo_convenio=ignore&gerente={{ gerente.id|stringformat:'s' }}{% for uf_rec in ufs %}&uf={{ uf_rec.0 }}{% endfor %}" title="{% trans "Ver no mapa" %}">
{% blocktrans with total=tot_casas %}
{{ total }} casas atendidas
{% endblocktrans %}
</a>
</p>
<table class="striped">
<thead>
<tr>
<th>{% trans "Unidade da Federação" %}</th>
<th class="right-align">{% trans "Total de Casas" %}</th>
{% for tipo in tipos_orgao %}
<th class="right-align">{{ tipo.nome }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for uf_rec in ufs %}
<tr>
{% for value in uf_rec|slice:"1:" %}
{% if forloop.first %}
<td>
<a href="{% url 'openmap' %}?tipo_servico=ignore&tipo_convenio=ignore&gerente={{ gerente.id|stringformat:'s' }}&uf={{ uf_rec.0 }}" title="{% trans "Ver no mapa" %}">
{{ value }}
</a>
</td>
{% else %}
<td class="right-align">
{% if forloop.counter > 2 and value > 0 %}
<a href="{% url 'openmap' %}?tipo_servico=ignore&tipo_convenio=ignore&gerente={{ gerente.id|stringformat:'s' }}&uf={{ uf_rec.0 }}&tipo_orgao={% for tipo in tipos_orgao %}{% if forloop.counter == forloop.parentloop.counter|add:-2 %}{{ tipo.sigla }}{% endif %}{% endfor %}" title="{% trans "Ver no mapa" %}">
{{ value }}
</a>
{% else %}
{{ value|default:"-" }}
{% endif %}
</td>
{% endif %}
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
{% endfor %}
{% endblock %}

72
sigi/apps/casas/views.py

@ -5,15 +5,24 @@ from django.contrib.admin.sites import site
from django.contrib.admin.views.decorators import staff_member_required from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import (
LoginRequiredMixin,
PermissionRequiredMixin,
)
from django.core.paginator import Paginator, InvalidPage, EmptyPage from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.http import HttpResponse, HttpResponseRedirect from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from django.views.generic import CreateView, DeleteView, ListView, UpdateView from django.views.generic import (
CreateView,
DeleteView,
ListView,
UpdateView,
DetailView,
)
from sigi.apps.casas.forms import FuncionarioForm from sigi.apps.casas.forms import FuncionarioForm
from sigi.apps.casas.models import Funcionario, Orgao from sigi.apps.casas.models import Funcionario, Orgao, TipoOrgao
from sigi.apps.home.mixins import ContatoInterlegisViewMixin from sigi.apps.home.mixins import ContatoInterlegisViewMixin
from sigi.apps.servidores.models import Servidor from sigi.apps.servidores.models import Servidor
from sigi.apps.contatos.models import ( from sigi.apps.contatos.models import (
@ -321,6 +330,63 @@ def painel_relacionamento(request):
return render(request, "casas/painel.html", context) return render(request, "casas/painel.html", context)
class GerentesListView(PermissionRequiredMixin, ListView):
template_name = "admin/casas/gerentes_list.html"
_tipos = None
def get_tipos(self):
if self._tipos is None:
self._tipos = (
Orgao.objects.exclude(gerentes_interlegis=None)
.order_by("tipo_id")
.distinct("tipo")
.values_list("tipo", flat=True)
)
return self._tipos
def has_permission(self):
return self.request.user.is_staff
def get_queryset(self):
regioes_dict = dict(UnidadeFederativa.REGIAO_CHOICES)
counters = {
f"c_{t}": Count("id", filter=Q(tipo__id=t))
for t in self.get_tipos()
}
gerentes = list(
Servidor.objects.exclude(casas_que_gerencia=None)
.order_by("nome_completo")
.annotate(tot_casas=Count("casas_que_gerencia"))
)
for gerente in gerentes:
regioes = [
(
regioes_dict[r],
t,
gerente.casas_que_gerencia.filter(municipio__uf__regiao=r)
.order_by("municipio__uf__nome")
.values_list("municipio__uf__sigla", "municipio__uf__nome")
.annotate(tot_casas=Count("*"))
.annotate(**counters),
)
for r, t in gerente.casas_que_gerencia.order_by(
"municipio__uf__regiao"
)
.values_list("municipio__uf__regiao")
.annotate(tot_casas=Count("*"))
]
setattr(gerente, "regioes", regioes)
return gerentes
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["tipos_orgao"] = TipoOrgao.objects.filter(
id__in=self.get_tipos()
).order_by("id")
return context
################################################################################ ################################################################################
# Views para site público - acesso dos contatos Interlegis # # Views para site público - acesso dos contatos Interlegis #
################################################################################ ################################################################################

2
sigi/menu_conf.yaml

@ -48,7 +48,7 @@ main_menu:
- title: Organizar relacionamentos - title: Organizar relacionamentos
view_name: view_name:
- title: Lista de gerentes - title: Lista de gerentes
view_name: view_name: casas_gerentes
- title: Convênios - title: Convênios
icon: assignment icon: assignment
children: children:

Loading…
Cancel
Save