|
|
@ -1,6 +1,7 @@ |
|
|
import collections |
|
|
import collections |
|
|
import itertools |
|
|
|
|
|
import datetime |
|
|
import datetime |
|
|
|
|
|
import itertools |
|
|
|
|
|
import json |
|
|
import logging |
|
|
import logging |
|
|
import os |
|
|
import os |
|
|
|
|
|
|
|
|
@ -15,11 +16,13 @@ from django.core.urlresolvers import reverse, reverse_lazy |
|
|
from django.db import connection |
|
|
from django.db import connection |
|
|
from django.db.models import Count, Q, ProtectedError |
|
|
from django.db.models import Count, Q, ProtectedError |
|
|
from django.http import Http404, HttpResponseRedirect |
|
|
from django.http import Http404, HttpResponseRedirect |
|
|
|
|
|
from django.shortcuts import render |
|
|
from django.template import TemplateDoesNotExist |
|
|
from django.template import TemplateDoesNotExist |
|
|
from django.template.loader import get_template |
|
|
from django.template.loader import get_template |
|
|
from django.utils import timezone |
|
|
from django.utils import timezone |
|
|
from django.utils.encoding import force_bytes |
|
|
from django.utils.encoding import force_bytes |
|
|
from django.utils.http import urlsafe_base64_decode, urlsafe_base64_encode |
|
|
from django.utils.http import urlsafe_base64_decode, urlsafe_base64_encode |
|
|
|
|
|
from django.utils.safestring import mark_safe |
|
|
from django.utils.translation import string_concat |
|
|
from django.utils.translation import string_concat |
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
from django.views.generic import (CreateView, DeleteView, FormView, ListView, |
|
|
from django.views.generic import (CreateView, DeleteView, FormView, ListView, |
|
|
@ -61,6 +64,16 @@ from .forms import (AlterarSenhaForm, CasaLegislativaForm, |
|
|
from .models import AppConfig, CasaLegislativa |
|
|
from .models import AppConfig, CasaLegislativa |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def chanel_index(request): |
|
|
|
|
|
return render(request, 'base/channel_index.html', {}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def chanel_room(request, room_name): |
|
|
|
|
|
return render(request, 'base/channel_room.html', { |
|
|
|
|
|
'room_name_json': mark_safe(json.dumps(room_name)) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def filtra_url_materias_em_tramitacao(qr, qs, campo_url, local_ou_status): |
|
|
def filtra_url_materias_em_tramitacao(qr, qs, campo_url, local_ou_status): |
|
|
id_materias = [] |
|
|
id_materias = [] |
|
|
filtro_url = qr[campo_url] |
|
|
filtro_url = qr[campo_url] |
|
|
@ -289,7 +302,7 @@ class AutorCrud(CrudAux): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RelatoriosListView(TemplateView): |
|
|
class RelatoriosListView(TemplateView): |
|
|
template_name='base/relatorios_list.html' |
|
|
template_name = 'base/relatorios_list.html' |
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs): |
|
|
def get_context_data(self, **kwargs): |
|
|
context = super(TemplateView, self).get_context_data(**kwargs) |
|
|
context = super(TemplateView, self).get_context_data(**kwargs) |
|
|
@ -799,15 +812,15 @@ class RelatorioNormasPublicadasMesView(FilterView): |
|
|
context['ano'] = self.request.GET['ano'] |
|
|
context['ano'] = self.request.GET['ano'] |
|
|
|
|
|
|
|
|
normas_mes = collections.OrderedDict() |
|
|
normas_mes = collections.OrderedDict() |
|
|
meses = {1: 'Janeiro', 2: 'Fevereiro', 3:'Março', 4: 'Abril', 5: 'Maio', 6:'Junho', |
|
|
meses = {1: 'Janeiro', 2: 'Fevereiro', 3: 'Março', 4: 'Abril', 5: 'Maio', 6: 'Junho', |
|
|
7: 'Julho', 8: 'Agosto', 9:'Setembro', 10:'Outubro', 11:'Novembro', 12:'Dezembro'} |
|
|
7: 'Julho', 8: 'Agosto', 9: 'Setembro', 10: 'Outubro', 11: 'Novembro', 12: 'Dezembro'} |
|
|
for norma in context['object_list']: |
|
|
for norma in context['object_list']: |
|
|
if not meses[norma.data.month] in normas_mes: |
|
|
if not meses[norma.data.month] in normas_mes: |
|
|
normas_mes[meses[norma.data.month]] = [] |
|
|
normas_mes[meses[norma.data.month]] = [] |
|
|
normas_mes[meses[norma.data.month]].append(norma) |
|
|
normas_mes[meses[norma.data.month]].append(norma) |
|
|
|
|
|
|
|
|
context['normas_mes'] = normas_mes |
|
|
context['normas_mes'] = normas_mes |
|
|
|
|
|
|
|
|
quant_normas_mes = {} |
|
|
quant_normas_mes = {} |
|
|
for key in normas_mes.keys(): |
|
|
for key in normas_mes.keys(): |
|
|
quant_normas_mes[key] = len(normas_mes[key]) |
|
|
quant_normas_mes[key] = len(normas_mes[key]) |
|
|
@ -833,19 +846,20 @@ class RelatorioNormasVigenciaView(FilterView): |
|
|
vigencia = kwargs['data']['vigencia'] |
|
|
vigencia = kwargs['data']['vigencia'] |
|
|
if ano: |
|
|
if ano: |
|
|
qs = qs.filter(ano=ano) |
|
|
qs = qs.filter(ano=ano) |
|
|
|
|
|
|
|
|
if vigencia == 'True': |
|
|
if vigencia == 'True': |
|
|
qs_dt_not_null = qs.filter(data_vigencia__isnull=True) |
|
|
qs_dt_not_null = qs.filter(data_vigencia__isnull=True) |
|
|
qs = (qs_dt_not_null | qs.filter(data_vigencia__gte=datetime.datetime.now().date())).distinct() |
|
|
qs = (qs_dt_not_null | qs.filter( |
|
|
|
|
|
data_vigencia__gte=datetime.datetime.now().date())).distinct() |
|
|
else: |
|
|
else: |
|
|
qs = qs.filter(data_vigencia__lt=datetime.datetime.now().date()) |
|
|
qs = qs.filter( |
|
|
|
|
|
data_vigencia__lt=datetime.datetime.now().date()) |
|
|
|
|
|
|
|
|
kwargs.update({ |
|
|
kwargs.update({ |
|
|
'queryset': qs |
|
|
'queryset': qs |
|
|
}) |
|
|
}) |
|
|
return kwargs |
|
|
return kwargs |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs): |
|
|
def get_context_data(self, **kwargs): |
|
|
context = super(RelatorioNormasVigenciaView, |
|
|
context = super(RelatorioNormasVigenciaView, |
|
|
self).get_context_data(**kwargs) |
|
|
self).get_context_data(**kwargs) |
|
|
@ -855,17 +869,20 @@ class RelatorioNormasVigenciaView(FilterView): |
|
|
if not self.filterset.form.is_valid(): |
|
|
if not self.filterset.form.is_valid(): |
|
|
return context |
|
|
return context |
|
|
|
|
|
|
|
|
normas_totais = NormaJuridica.objects.filter(ano=self.request.GET['ano']) |
|
|
normas_totais = NormaJuridica.objects.filter( |
|
|
|
|
|
ano=self.request.GET['ano']) |
|
|
|
|
|
|
|
|
context['quant_total'] = len(normas_totais) |
|
|
context['quant_total'] = len(normas_totais) |
|
|
if self.request.GET['vigencia'] == 'True': |
|
|
if self.request.GET['vigencia'] == 'True': |
|
|
context['vigencia'] = 'Vigente' |
|
|
context['vigencia'] = 'Vigente' |
|
|
context['quant_vigente'] = len(context['object_list']) |
|
|
context['quant_vigente'] = len(context['object_list']) |
|
|
context['quant_nao_vigente'] = context['quant_total'] - context['quant_vigente'] |
|
|
context['quant_nao_vigente'] = context['quant_total'] - \ |
|
|
|
|
|
context['quant_vigente'] |
|
|
else: |
|
|
else: |
|
|
context['vigencia'] = 'Não vigente' |
|
|
context['vigencia'] = 'Não vigente' |
|
|
context['quant_nao_vigente'] = len(context['object_list']) |
|
|
context['quant_nao_vigente'] = len(context['object_list']) |
|
|
context['quant_vigente'] = context['quant_total'] - context['quant_nao_vigente'] |
|
|
context['quant_vigente'] = context['quant_total'] - \ |
|
|
|
|
|
context['quant_nao_vigente'] |
|
|
|
|
|
|
|
|
qr = self.request.GET.copy() |
|
|
qr = self.request.GET.copy() |
|
|
context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' |
|
|
context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' |
|
|
@ -891,7 +908,7 @@ class EstatisticasAcessoNormas(TemplateView): |
|
|
return self.render_to_response(context) |
|
|
return self.render_to_response(context) |
|
|
|
|
|
|
|
|
context['ano'] = self.request.GET['ano'] |
|
|
context['ano'] = self.request.GET['ano'] |
|
|
|
|
|
|
|
|
query = ''' |
|
|
query = ''' |
|
|
select norma_id, ano, extract(month from horario_acesso) as mes, count(*) |
|
|
select norma_id, ano, extract(month from horario_acesso) as mes, count(*) |
|
|
from norma_normaestatisticas |
|
|
from norma_normaestatisticas |
|
|
@ -904,20 +921,21 @@ class EstatisticasAcessoNormas(TemplateView): |
|
|
rows = cursor.fetchall() |
|
|
rows = cursor.fetchall() |
|
|
|
|
|
|
|
|
normas_mes = collections.OrderedDict() |
|
|
normas_mes = collections.OrderedDict() |
|
|
meses = {1: 'Janeiro', 2: 'Fevereiro', 3:'Março', 4: 'Abril', 5: 'Maio', 6:'Junho', |
|
|
meses = {1: 'Janeiro', 2: 'Fevereiro', 3: 'Março', 4: 'Abril', 5: 'Maio', 6: 'Junho', |
|
|
7: 'Julho', 8: 'Agosto', 9:'Setembro', 10:'Outubro', 11:'Novembro', 12:'Dezembro'} |
|
|
7: 'Julho', 8: 'Agosto', 9: 'Setembro', 10: 'Outubro', 11: 'Novembro', 12: 'Dezembro'} |
|
|
|
|
|
|
|
|
for row in rows: |
|
|
for row in rows: |
|
|
if not meses[int(row[2])] in normas_mes: |
|
|
if not meses[int(row[2])] in normas_mes: |
|
|
normas_mes[meses[int(row[2])]] = [] |
|
|
normas_mes[meses[int(row[2])]] = [] |
|
|
norma_est = [NormaJuridica.objects.get(id=row[0]), row[3]] |
|
|
norma_est = [NormaJuridica.objects.get(id=row[0]), row[3]] |
|
|
normas_mes[meses[int(row[2])]].append(norma_est) |
|
|
normas_mes[meses[int(row[2])]].append(norma_est) |
|
|
|
|
|
|
|
|
# Ordena por acesso e limita em 5 |
|
|
# Ordena por acesso e limita em 5 |
|
|
for n in normas_mes: |
|
|
for n in normas_mes: |
|
|
sorted_by_value = sorted(normas_mes[n], key=lambda kv: kv[1], reverse=True) |
|
|
sorted_by_value = sorted( |
|
|
|
|
|
normas_mes[n], key=lambda kv: kv[1], reverse=True) |
|
|
normas_mes[n] = sorted_by_value[0:5] |
|
|
normas_mes[n] = sorted_by_value[0:5] |
|
|
|
|
|
|
|
|
context['normas_mes'] = normas_mes |
|
|
context['normas_mes'] = normas_mes |
|
|
|
|
|
|
|
|
return self.render_to_response(context) |
|
|
return self.render_to_response(context) |
|
|
@ -952,8 +970,8 @@ class ListarInconsistenciasView(PermissionRequiredMixin, ListView): |
|
|
tabela.append( |
|
|
tabela.append( |
|
|
('mandato_sem_data_inicio', |
|
|
('mandato_sem_data_inicio', |
|
|
'Mandatos sem data inicial', |
|
|
'Mandatos sem data inicial', |
|
|
len(mandato_sem_data_inicio()) |
|
|
len(mandato_sem_data_inicio()) |
|
|
) |
|
|
) |
|
|
) |
|
|
) |
|
|
tabela.append( |
|
|
tabela.append( |
|
|
('parlamentares_mandatos_intersecao', |
|
|
('parlamentares_mandatos_intersecao', |
|
|
@ -977,7 +995,7 @@ class ListarInconsistenciasView(PermissionRequiredMixin, ListView): |
|
|
('legislatura_infindavel', |
|
|
('legislatura_infindavel', |
|
|
'Legislaturas sem data fim', |
|
|
'Legislaturas sem data fim', |
|
|
len(legislatura_infindavel()) |
|
|
len(legislatura_infindavel()) |
|
|
) |
|
|
) |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
return tabela |
|
|
return tabela |
|
|
@ -1000,14 +1018,14 @@ class ListarLegislaturaInfindavelView(PermissionRequiredMixin, ListView): |
|
|
def get_context_data(self, **kwargs): |
|
|
def get_context_data(self, **kwargs): |
|
|
context = super( |
|
|
context = super( |
|
|
ListarLegislaturaInfindavelView, self |
|
|
ListarLegislaturaInfindavelView, self |
|
|
).get_context_data(**kwargs) |
|
|
).get_context_data(**kwargs) |
|
|
paginator = context['paginator'] |
|
|
paginator = context['paginator'] |
|
|
page_obj = context['page_obj'] |
|
|
page_obj = context['page_obj'] |
|
|
context['page_range'] = make_pagination( |
|
|
context['page_range'] = make_pagination( |
|
|
page_obj.number, paginator.num_pages) |
|
|
page_obj.number, paginator.num_pages) |
|
|
context[ |
|
|
context[ |
|
|
'NO_ENTRIES_MSG' |
|
|
'NO_ENTRIES_MSG' |
|
|
] = 'Nenhuma encontrada.' |
|
|
] = 'Nenhuma encontrada.' |
|
|
return context |
|
|
return context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1050,14 +1068,14 @@ class ListarBancadaComissaoAutorExternoView(PermissionRequiredMixin, ListView): |
|
|
def get_context_data(self, **kwargs): |
|
|
def get_context_data(self, **kwargs): |
|
|
context = super( |
|
|
context = super( |
|
|
ListarBancadaComissaoAutorExternoView, self |
|
|
ListarBancadaComissaoAutorExternoView, self |
|
|
).get_context_data(**kwargs) |
|
|
).get_context_data(**kwargs) |
|
|
paginator = context['paginator'] |
|
|
paginator = context['paginator'] |
|
|
page_obj = context['page_obj'] |
|
|
page_obj = context['page_obj'] |
|
|
context['page_range'] = make_pagination( |
|
|
context['page_range'] = make_pagination( |
|
|
page_obj.number, paginator.num_pages) |
|
|
page_obj.number, paginator.num_pages) |
|
|
context[ |
|
|
context[ |
|
|
'NO_ENTRIES_MSG' |
|
|
'NO_ENTRIES_MSG' |
|
|
] = 'Nenhum encontrado.' |
|
|
] = 'Nenhum encontrado.' |
|
|
return context |
|
|
return context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1084,7 +1102,7 @@ class ListarAutoresDuplicadosView(PermissionRequiredMixin, ListView): |
|
|
page_obj.number, paginator.num_pages) |
|
|
page_obj.number, paginator.num_pages) |
|
|
context[ |
|
|
context[ |
|
|
'NO_ENTRIES_MSG' |
|
|
'NO_ENTRIES_MSG' |
|
|
] = 'Nenhum encontrado.' |
|
|
] = 'Nenhum encontrado.' |
|
|
return context |
|
|
return context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1097,10 +1115,12 @@ def parlamentares_mandatos_intersecao(): |
|
|
|
|
|
|
|
|
for c in combinacoes: |
|
|
for c in combinacoes: |
|
|
data_inicio_mandato1 = c[0].data_inicio_mandato |
|
|
data_inicio_mandato1 = c[0].data_inicio_mandato |
|
|
data_fim_mandato1 = c[0].data_fim_mandato if c[0].data_fim_mandato else timezone.now().date() |
|
|
data_fim_mandato1 = c[0].data_fim_mandato if c[0].data_fim_mandato else timezone.now( |
|
|
|
|
|
).date() |
|
|
|
|
|
|
|
|
data_inicio_mandato2 = c[1].data_inicio_mandato |
|
|
data_inicio_mandato2 = c[1].data_inicio_mandato |
|
|
data_fim_mandato2 = c[1].data_fim_mandato if c[1].data_fim_mandato else timezone.now().date() |
|
|
data_fim_mandato2 = c[1].data_fim_mandato if c[1].data_fim_mandato else timezone.now( |
|
|
|
|
|
).date() |
|
|
|
|
|
|
|
|
if data_inicio_mandato1 and data_inicio_mandato2: |
|
|
if data_inicio_mandato1 and data_inicio_mandato2: |
|
|
exists = intervalos_tem_intersecao( |
|
|
exists = intervalos_tem_intersecao( |
|
|
@ -1131,7 +1151,7 @@ class ListarParlMandatosIntersecaoView(PermissionRequiredMixin, ListView): |
|
|
page_obj.number, paginator.num_pages) |
|
|
page_obj.number, paginator.num_pages) |
|
|
context[ |
|
|
context[ |
|
|
'NO_ENTRIES_MSG' |
|
|
'NO_ENTRIES_MSG' |
|
|
] = 'Nenhum encontrado.' |
|
|
] = 'Nenhum encontrado.' |
|
|
return context |
|
|
return context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1152,14 +1172,14 @@ class ListarMandatoSemDataInicioView(PermissionRequiredMixin, ListView): |
|
|
def get_context_data(self, **kwargs): |
|
|
def get_context_data(self, **kwargs): |
|
|
context = super( |
|
|
context = super( |
|
|
ListarMandatoSemDataInicioView, self |
|
|
ListarMandatoSemDataInicioView, self |
|
|
).get_context_data(**kwargs) |
|
|
).get_context_data(**kwargs) |
|
|
paginator = context['paginator'] |
|
|
paginator = context['paginator'] |
|
|
page_obj = context['page_obj'] |
|
|
page_obj = context['page_obj'] |
|
|
context['page_range'] = make_pagination( |
|
|
context['page_range'] = make_pagination( |
|
|
page_obj.number, paginator.num_pages) |
|
|
page_obj.number, paginator.num_pages) |
|
|
context[ |
|
|
context[ |
|
|
'NO_ENTRIES_MSG' |
|
|
'NO_ENTRIES_MSG' |
|
|
] = 'Nenhum encontrada.' |
|
|
] = 'Nenhum encontrada.' |
|
|
return context |
|
|
return context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1187,27 +1207,27 @@ class ListarMatProtocoloInexistenteView(PermissionRequiredMixin, ListView): |
|
|
def get_context_data(self, **kwargs): |
|
|
def get_context_data(self, **kwargs): |
|
|
context = super( |
|
|
context = super( |
|
|
ListarMatProtocoloInexistenteView, self |
|
|
ListarMatProtocoloInexistenteView, self |
|
|
).get_context_data(**kwargs) |
|
|
).get_context_data(**kwargs) |
|
|
paginator = context['paginator'] |
|
|
paginator = context['paginator'] |
|
|
page_obj = context['page_obj'] |
|
|
page_obj = context['page_obj'] |
|
|
context['page_range'] = make_pagination( |
|
|
context['page_range'] = make_pagination( |
|
|
page_obj.number, paginator.num_pages) |
|
|
page_obj.number, paginator.num_pages) |
|
|
context[ |
|
|
context[ |
|
|
'NO_ENTRIES_MSG' |
|
|
'NO_ENTRIES_MSG' |
|
|
] = 'Nenhuma encontrada.' |
|
|
] = 'Nenhuma encontrada.' |
|
|
return context |
|
|
return context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def protocolos_com_materias(): |
|
|
def protocolos_com_materias(): |
|
|
protocolos = {} |
|
|
protocolos = {} |
|
|
|
|
|
|
|
|
for m in MateriaLegislativa.objects.filter(numero_protocolo__isnull=False).order_by('-ano', 'numero_protocolo'): |
|
|
for m in MateriaLegislativa.objects.filter(numero_protocolo__isnull=False).order_by('-ano', 'numero_protocolo'): |
|
|
if Protocolo.objects.filter(numero=m.numero_protocolo, ano=m.ano).exists(): |
|
|
if Protocolo.objects.filter(numero=m.numero_protocolo, ano=m.ano).exists(): |
|
|
key = "{}/{}".format(m.numero_protocolo, m.ano) |
|
|
key = "{}/{}".format(m.numero_protocolo, m.ano) |
|
|
val = protocolos.get(key, list()) |
|
|
val = protocolos.get(key, list()) |
|
|
val.append(m) |
|
|
val.append(m) |
|
|
protocolos[key] = val |
|
|
protocolos[key] = val |
|
|
|
|
|
|
|
|
return [(v[0], len(v)) for (k, v) in protocolos.items() if len(v) > 1] |
|
|
return [(v[0], len(v)) for (k, v) in protocolos.items() if len(v) > 1] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1230,7 +1250,7 @@ class ListarProtocolosComMateriasView(PermissionRequiredMixin, ListView): |
|
|
page_obj.number, paginator.num_pages) |
|
|
page_obj.number, paginator.num_pages) |
|
|
context[ |
|
|
context[ |
|
|
'NO_ENTRIES_MSG' |
|
|
'NO_ENTRIES_MSG' |
|
|
] = 'Nenhum encontrado.' |
|
|
] = 'Nenhum encontrado.' |
|
|
return context |
|
|
return context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1244,6 +1264,7 @@ def protocolos_duplicados(): |
|
|
|
|
|
|
|
|
return [(v[0], len(v)) for (k, v) in protocolos.items() if len(v) > 1] |
|
|
return [(v[0], len(v)) for (k, v) in protocolos.items() if len(v) > 1] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ListarProtocolosDuplicadosView(PermissionRequiredMixin, ListView): |
|
|
class ListarProtocolosDuplicadosView(PermissionRequiredMixin, ListView): |
|
|
model = get_user_model() |
|
|
model = get_user_model() |
|
|
template_name = 'base/protocolos_duplicados.html' |
|
|
template_name = 'base/protocolos_duplicados.html' |
|
|
@ -1263,7 +1284,7 @@ class ListarProtocolosDuplicadosView(PermissionRequiredMixin, ListView): |
|
|
page_obj.number, paginator.num_pages) |
|
|
page_obj.number, paginator.num_pages) |
|
|
context[ |
|
|
context[ |
|
|
'NO_ENTRIES_MSG' |
|
|
'NO_ENTRIES_MSG' |
|
|
] = 'Nenhum encontrado.' |
|
|
] = 'Nenhum encontrado.' |
|
|
return context |
|
|
return context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|