Browse Source

Merge

pull/760/head
Eduardo Calil 9 years ago
parent
commit
603fcb0978
  1. 177
      sapl/painel/views.py
  2. 14
      sapl/sessao/views.py

177
sapl/painel/views.py

@ -82,21 +82,13 @@ def get_cronometro_status(request, name):
def get_materia_aberta(pk): def get_materia_aberta(pk):
try: return OrdemDia.objects.filter(
materia = OrdemDia.objects.filter( sessao_plenaria_id=pk, votacao_aberta=True).last()
sessao_plenaria_id=pk, votacao_aberta=True).last()
return materia
except ObjectDoesNotExist:
return None
def get_last_materia(pk): def get_last_materia(pk):
try: return OrdemDia.objects.filter(
materia = OrdemDia.objects.filter( sessao_plenaria_id=pk).last()
sessao_plenaria_id=pk).last()
return materia
except ObjectDoesNotExist:
return None
def get_presentes(pk, response, materia): def get_presentes(pk, response, materia):
@ -136,11 +128,14 @@ def get_presentes(pk, response, materia):
num_presentes_ordem_dia = len(presentes_ordem_dia) num_presentes_ordem_dia = len(presentes_ordem_dia)
if materia.tipo_votacao == 1: if materia.tipo_votacao == 1:
tipo_votacao = 'Simbólica' tipo_votacao = str(_('Simbólica'))
response = get_votos(response, materia)
elif materia.tipo_votacao == 2: elif materia.tipo_votacao == 2:
tipo_votacao = 'Nominal' tipo_votacao = 'Nominal'
response = get_votos_nominal(response, materia)
elif materia.tipo_votacao == 3: elif materia.tipo_votacao == 3:
tipo_votacao = 'Secreta' tipo_votacao = 'Secreta'
response = get_votos(response, materia)
response.update({ response.update({
'presentes_ordem_dia': presentes_ordem_dia, 'presentes_ordem_dia': presentes_ordem_dia,
@ -149,10 +144,6 @@ def get_presentes(pk, response, materia):
'num_presentes_sessao_plenaria': num_presentes_sessao_plen, 'num_presentes_sessao_plenaria': num_presentes_sessao_plen,
'status_painel': 'ABERTO', 'status_painel': 'ABERTO',
'msg_painel': str(_('Votação aberta!')), 'msg_painel': str(_('Votação aberta!')),
'numero_votos_sim': 0,
'numero_votos_nao': 0,
'numero_abstencoes': 0,
'total_votos': 0,
'tipo_resultado': tipo_votacao, 'tipo_resultado': tipo_votacao,
'observacao_materia': materia.observacao, 'observacao_materia': materia.observacao,
'materia_legislativa_texto': str(materia.materia)}) 'materia_legislativa_texto': str(materia.materia)})
@ -164,21 +155,13 @@ def get_presentes(pk, response, materia):
def get_materia_expediente_aberta(pk): def get_materia_expediente_aberta(pk):
try: return ExpedienteMateria.objects.filter(
materia = ExpedienteMateria.objects.filter( sessao_plenaria_id=pk, votacao_aberta=True).last()
sessao_plenaria_id=pk, votacao_aberta=True).last()
return materia
except ObjectDoesNotExist:
return None
def get_last_materia_expediente(pk): def get_last_materia_expediente(pk):
try: return ExpedienteMateria.objects.filter(
materia = ExpedienteMateria.objects.filter( sessao_plenaria_id=pk).last()
sessao_plenaria_id=pk).last()
return materia
except ObjectDoesNotExist:
return None
def get_presentes_expediente(pk, response, materia): def get_presentes_expediente(pk, response, materia):
@ -219,10 +202,14 @@ def get_presentes_expediente(pk, response, materia):
if materia.tipo_votacao == 1: if materia.tipo_votacao == 1:
tipo_votacao = 'Simbólica' tipo_votacao = 'Simbólica'
response = get_votos(response, materia)
elif materia.tipo_votacao == 2: elif materia.tipo_votacao == 2:
tipo_votacao = 'Nominal' tipo_votacao = 'Nominal'
response = get_votos_nominal(response, materia)
elif materia.tipo_votacao == 3: elif materia.tipo_votacao == 3:
tipo_votacao = 'Secreta' tipo_votacao = 'Secreta'
response = get_votos(response, materia)
response.update({ response.update({
'presentes_expediente': presentes_expediente, 'presentes_expediente': presentes_expediente,
'num_presentes_expediente': num_presentes_expediente, 'num_presentes_expediente': num_presentes_expediente,
@ -230,10 +217,6 @@ def get_presentes_expediente(pk, response, materia):
'num_presentes_sessao_plenaria': num_presentes_sessao_plen, 'num_presentes_sessao_plenaria': num_presentes_sessao_plen,
'status_painel': str(_('ABERTO')), 'status_painel': str(_('ABERTO')),
'msg_painel': str(_('Votação aberta!')), 'msg_painel': str(_('Votação aberta!')),
'numero_votos_sim': 0,
'numero_votos_nao': 0,
'numero_abstencoes': 0,
'total_votos': 0,
'tipo_resultado': tipo_votacao, 'tipo_resultado': tipo_votacao,
'observacao_materia': materia.observacao, 'observacao_materia': materia.observacao,
'materia_legislativa_texto': str(materia.materia)}) 'materia_legislativa_texto': str(materia.materia)})
@ -262,17 +245,28 @@ def get_votos(response, materia):
registro = RegistroVotacao.objects.filter( registro = RegistroVotacao.objects.filter(
ordem=materia, materia=materia.materia).last() ordem=materia, materia=materia.materia).last()
total = (registro.numero_votos_sim +
registro.numero_votos_nao + if registro:
registro.numero_abstencoes) total = (registro.numero_votos_sim +
response.update({ registro.numero_votos_nao +
'numero_votos_sim': registro.numero_votos_sim, registro.numero_abstencoes)
'numero_votos_nao': registro.numero_votos_nao, response.update({
'numero_abstencoes': registro.numero_abstencoes, 'numero_votos_sim': registro.numero_votos_sim,
'total_votos': total, 'numero_votos_nao': registro.numero_votos_nao,
'tipo_votacao': tipo_votacao, 'numero_abstencoes': registro.numero_abstencoes,
'tipo_resultado': registro.tipo_resultado_votacao.nome, 'total_votos': total,
}) 'tipo_votacao': tipo_votacao,
'tipo_resultado': registro.tipo_resultado_votacao.nome,
})
else:
response.update({
'numero_votos_sim': 0,
'numero_votos_nao': 0,
'numero_abstencoes': 0,
'total_votos': 0,
'tipo_votacao': tipo_votacao,
'tipo_resultado': 'Ainda não foi votada.',
})
return response return response
@ -286,48 +280,61 @@ def get_votos_nominal(response, materia):
elif materia.tipo_votacao == 3: elif materia.tipo_votacao == 3:
tipo_votacao = 'Secreta' tipo_votacao = 'Secreta'
registro = RegistroVotacao.objects.get( try:
ordem=materia, materia=materia.materia) registro = RegistroVotacao.objects.get(
ordem=materia, materia=materia.materia)
votos_parlamentares = VotoParlamentar.objects.filter( except ObjectDoesNotExist:
votacao_id=registro.id) response.update({
'numero_votos_sim': 0,
filiacao = Filiacao.objects.filter( 'numero_votos_nao': 0,
data_desfiliacao__isnull=True, parlamentar__ativo=True) 'numero_abstencoes': 0,
parlamentar_partido = {} 'total_votos': 0,
for f in filiacao: 'tipo_votacao': tipo_votacao,
parlamentar_partido[ 'tipo_resultado': 'Não foi votado ainda',
f.parlamentar.nome_parlamentar] = f.partido.sigla 'votos': None
})
for v in votos_parlamentares:
try:
parlamentar_partido[v.parlamentar.nome_parlamentar]
except KeyError:
votos.update({v.parlamentar.id: {
'parlamentar': v.parlamentar.nome_parlamentar,
'voto': str(v.voto),
'partido': str(_('Sem Registro'))
}})
else:
votos.update({v.parlamentar.id: {
'parlamentar': v.parlamentar.nome_parlamentar,
'voto': str(v.voto),
'partido': parlamentar_partido[v.parlamentar.nome_parlamentar]
}})
total = (registro.numero_votos_sim +
registro.numero_votos_nao +
registro.numero_abstencoes)
response.update({ else:
'numero_votos_sim': registro.numero_votos_sim, votos_parlamentares = VotoParlamentar.objects.filter(
'numero_votos_nao': registro.numero_votos_nao, votacao_id=registro.id)
'numero_abstencoes': registro.numero_abstencoes,
'total_votos': total, filiacao = Filiacao.objects.filter(
'tipo_votacao': tipo_votacao, data_desfiliacao__isnull=True, parlamentar__ativo=True)
'tipo_resultado': registro.tipo_resultado_votacao.nome, parlamentar_partido = {}
'votos': votos for f in filiacao:
}) parlamentar_partido[
f.parlamentar.nome_parlamentar] = f.partido.sigla
for v in votos_parlamentares:
try:
parlamentar_partido[v.parlamentar.nome_parlamentar]
except KeyError:
votos.update({v.parlamentar.id: {
'parlamentar': v.parlamentar.nome_parlamentar,
'voto': str(v.voto),
'partido': str(_('Sem Registro'))
}})
else:
votos.update({v.parlamentar.id: {
'parlamentar': v.parlamentar.nome_parlamentar,
'voto': str(v.voto),
'partido': parlamentar_partido[
v.parlamentar.nome_parlamentar]
}})
total = (registro.numero_votos_sim +
registro.numero_votos_nao +
registro.numero_abstencoes)
response.update({
'numero_votos_sim': registro.numero_votos_sim,
'numero_votos_nao': registro.numero_votos_nao,
'numero_abstencoes': registro.numero_abstencoes,
'total_votos': total,
'tipo_votacao': tipo_votacao,
'tipo_resultado': registro.tipo_resultado_votacao.nome,
'votos': votos
})
return response return response

14
sapl/sessao/views.py

@ -2,7 +2,8 @@ from datetime import datetime
from re import sub from re import sub
from django.contrib import messages from django.contrib import messages
from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.core.exceptions import (ObjectDoesNotExist, MultipleObjectsReturned,
ValidationError)
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.forms.utils import ErrorList from django.forms.utils import ErrorList
from django.http import JsonResponse from django.http import JsonResponse
@ -1855,9 +1856,14 @@ class VotacaoExpedienteEditView(SessaoPermissionMixin):
'ementa': expediente.observacao} 'ementa': expediente.observacao}
context.update({'materia': materia}) context.update({'materia': materia})
votacao = RegistroVotacao.objects.get( try:
materia_id=materia_id, votacao = RegistroVotacao.objects.get(
expediente_id=expediente_id) materia_id=materia_id,
expediente_id=expediente_id)
except MultipleObjectsReturned:
votacao = RegistroVotacao.objects.get(
materia_id=materia_id,
expediente_id=expediente_id).last()
votacao_existente = {'observacao': sub( votacao_existente = {'observacao': sub(
' ', ' ', strip_tags(votacao.observacao)), ' ', ' ', strip_tags(votacao.observacao)),
'tipo_resultado': 'tipo_resultado':

Loading…
Cancel
Save