Browse Source

cria model pra votação, layout, recupera dados do parlamentar

pull/906/head
Eduardo Edson Batista Cordeiro Alves 8 years ago
parent
commit
1aaba1dc42
  1. 2
      sapl/norma/forms.py
  2. 46
      sapl/painel/views.py
  3. 5
      sapl/parlamentares/forms.py
  4. 19
      sapl/parlamentares/migrations/0038_auto_20170213_1425.py
  5. 19
      sapl/parlamentares/migrations/0039_remove_votante_ip.py
  6. 3
      sapl/parlamentares/models.py
  7. 5
      sapl/parlamentares/views.py
  8. 39
      sapl/sessao/migrations/0034_votonominal.py
  9. 23
      sapl/sessao/migrations/0035_auto_20170213_1455.py
  10. 21
      sapl/sessao/models.py
  11. 71
      sapl/templates/painel/voto_nominal.html
  12. 3
      sapl/templates/parlamentares/layouts.yaml

2
sapl/norma/forms.py

@ -17,9 +17,11 @@ from sapl.utils import RANGE_ANOS, RangeWidgetOverride
from .models import (AssuntoNorma, NormaJuridica, NormaRelacionada,
TipoNormaJuridica)
def ANO_CHOICES():
return [('', '---------')] + RANGE_ANOS
def get_esferas():
return [('E', 'Estadual'),
('F', 'Federal'),

46
sapl/painel/views.py

@ -1,4 +1,5 @@
from datetime import date
from sapl.utils import get_client_ip
from django.contrib.auth.decorators import user_passes_test
from django.core.exceptions import ObjectDoesNotExist
@ -12,7 +13,8 @@ from sapl.painel.models import Painel
from sapl.parlamentares.models import Filiacao, Votante
from sapl.sessao.models import (ExpedienteMateria, OrdemDia, PresencaOrdemDia,
RegistroVotacao, SessaoPlenaria,
SessaoPlenariaPresenca, VotoParlamentar)
SessaoPlenariaPresenca, VotoNominal,
VotoParlamentar)
from .models import Cronometro
@ -28,6 +30,12 @@ def check_permission(user):
def votante_view(request, pk):
context = {'head_title': str(_('Votação Individual')), 'sessao_id': pk}
# Pega sessão
sessao = SessaoPlenaria.objects.get(pk=pk)
context.update({'sessao': sessao,
'data': sessao.data_inicio,
'hora': sessao.hora_inicio})
# Inicializa presentes
presentes = []
@ -35,17 +43,20 @@ def votante_view(request, pk):
# Se aberta, verifica se é nominal. ID nominal == 2
ordem_dia = get_materia_aberta(pk)
expediente = get_materia_expediente_aberta(pk)
materia = None
if ordem_dia:
materia = ordem_dia.materia
if ordem_dia.tipo_votacao == 2:
context.update({'materia': ordem_dia})
context.update({'materia': materia, 'ementa': materia.ementa})
presentes = PresencaOrdemDia.objects.filter(sessao_plenaria_id=pk)
else:
context.update(
{'materia': 'A matéria aberta não é votação nominal.'})
elif expediente:
materia = expediente.materia
if expediente.tipo_votacao == 2:
context.update({'materia': expediente})
context.update({'materia': materia, 'ementa': materia.ementa})
presentes = SessaoPlenariaPresenca.objects.filter(
sessao_plenaria_id=pk)
else:
@ -76,7 +87,34 @@ def votante_view(request, pk):
context.update({'presente': True})
break
# FIXME: Verificar se usuário já votou
try:
voto = VotoNominal.objects.get(
sessao=sessao,
parlamentar=parlamentar,
materia=materia)
except ObjectDoesNotExist:
context.update({'voto_parlamentar': 'Voto não computado.'})
else:
context.update({'voto_parlamentar': voto.voto})
if request.method == 'POST':
try:
voto = VotoNominal.objects.get(
sessao=sessao,
parlamentar=parlamentar,
materia=materia)
except ObjectDoesNotExist:
voto = VotoNominal.objects.create(
sessao=sessao,
parlamentar=parlamentar,
materia=materia,
voto=request.POST['voto'],
ip=get_client_ip(request),
user=request.user)
else:
voto.voto = request.POST['voto']
voto.ip = get_client_ip(request)
voto.save()
return render(request, 'painel/voto_nominal.html', context)

5
sapl/parlamentares/forms.py

@ -267,9 +267,8 @@ class VotanteForm(ModelForm):
class Meta:
model = Votante
fields = ['username', 'senha', 'senha_confirma', 'ip',
'email', 'email_confirma']
widgets = {'ip': forms.HiddenInput()}
fields = ['username', 'senha', 'senha_confirma', 'email',
'email_confirma']
def __init__(self, *args, **kwargs):
row1 = to_row([('username', 4), ('senha', 4), ('senha_confirma', 4)])

19
sapl/parlamentares/migrations/0038_auto_20170213_1425.py

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2017-02-13 14:25
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('parlamentares', '0037_votante'),
]
operations = [
migrations.AlterModelOptions(
name='votante',
options={'verbose_name': 'Usuários'},
),
]

19
sapl/parlamentares/migrations/0039_remove_votante_ip.py

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2017-02-13 14:26
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('parlamentares', '0038_auto_20170213_1425'),
]
operations = [
migrations.RemoveField(
model_name='votante',
name='ip',
),
]

3
sapl/parlamentares/models.py

@ -505,8 +505,7 @@ class Votante(models.Model):
data = models.DateTimeField(
verbose_name=_('Data'), auto_now_add=True,
max_length=30, null=True, blank=True)
ip = models.CharField(
verbose_name=_('IP'), max_length=30, null=True, blank=True)
class Meta:
verbose_name = _('Usuário')

5
sapl/parlamentares/views.py

@ -48,11 +48,6 @@ class VotanteView(MasterDetailCrud):
form_class = VotanteForm
layout_key = None
def get_initial(self):
initial_data = {}
initial_data['ip'] = get_client_ip(self.request)
return initial_data
class DetailView(MasterDetailCrud.DetailView):
def detail_create_url(self):

39
sapl/sessao/migrations/0034_votonominal.py

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2017-02-13 14:37
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('materia', '0075_auto_20170203_1019'),
('parlamentares', '0039_remove_votante_ip'),
('sessao', '0033_merge'),
]
operations = [
migrations.CreateModel(
name='VotoNominal',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('voto', models.CharField(max_length=10, verbose_name='Voto')),
('ip', models.CharField(max_length=30, verbose_name='IP')),
('data_hora', models.DateTimeField(auto_now_add=True, verbose_name='Data/Hora')),
('expediente', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='sessao.ExpedienteMateria')),
('materia', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='materia.MateriaLegislativa')),
('ordem', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='sessao.OrdemDia')),
('parlamentar', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='parlamentares.Parlamentar')),
('sessao', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='sessao.SessaoPlenaria')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'Registro do Voto do Parlamentar',
'verbose_name_plural': 'Registros dos Votos dos Parlamentares',
},
),
]

23
sapl/sessao/migrations/0035_auto_20170213_1455.py

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2017-02-13 14:55
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('sessao', '0034_votonominal'),
]
operations = [
migrations.RemoveField(
model_name='votonominal',
name='expediente',
),
migrations.RemoveField(
model_name='votonominal',
name='ordem',
),
]

21
sapl/sessao/models.py

@ -1,3 +1,4 @@
from django.contrib.auth.models import User
from django.db import models
from django.utils.translation import ugettext_lazy as _
from model_utils import Choices
@ -375,6 +376,26 @@ class VotoParlamentar(models.Model): # RegistroVotacaoParlamentar
'votacao': self.votacao, 'parlamentar': self.parlamentar}
class VotoNominal(models.Model):
parlamentar = models.ForeignKey(Parlamentar)
voto = models.CharField(verbose_name=_('Voto'), max_length=10)
sessao = models.ForeignKey(SessaoPlenaria)
materia = models.ForeignKey(MateriaLegislativa)
user = models.ForeignKey(User)
ip = models.CharField(verbose_name=_('IP'), max_length=30)
data_hora = models.DateTimeField(
verbose_name=_('Data/Hora'), auto_now_add=True)
class Meta:
verbose_name = _('Registro do Voto do Parlamentar')
verbose_name_plural = _('Registros dos Votos dos Parlamentares')
def __str__(self):
return self.Parlamentar, self.voto
class SessaoPlenariaPresenca(models.Model):
sessao_plenaria = models.ForeignKey(SessaoPlenaria)
parlamentar = models.ForeignKey(Parlamentar)

71
sapl/templates/painel/voto_nominal.html

@ -1,5 +1,66 @@
head_title = {{head_title}} <br />
sessao_id = {{sessao_id}} <br />
materia = {{materia}} <br />
permissao = {{permissao}} <br />
presente = {{presente}} <br />
{% load i18n %}
{% load staticfiles sass_tags %}
<!DOCTYPE HTML>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="{% sass_src 'bootstrap-sass/assets/stylesheets/_bootstrap.scss' %}" type="text/css">
<title>{% block head_title %}{% trans 'SAPL - Sistema de Apoio ao Processo Legislativo' %}{% endblock %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="{% static 'jquery/dist/jquery.js' %}"></script>
<script type="text/javascript" src="{% static 'js/jquery.runner.js' %}"></script>
<style type="text/css">
@media screen {
body {
background: #1c1b1b;
}
ul, li {
list-style-type: none;
}
}
</style>
</head>
<body>
<h1><b><font color="#4FA64D"><p align="center">{{sessao}}</p></font></b></h1>
<table style="width:100%">
<tr>
<th style="text-align:center"><font color="white" size="4">Data Início: {{hora}}</font></th>
<th style="text-align:center"><font color="white" size="4">Hora Início: {{data}}</font></th>
</tr>
</table>
<h1><font color="white"><p align="center"><span id="relogio"></span></p></font></h1>
</br>
</br>
<h2><font color="red"><p align="center" style="font-family:Verdana">Voto: {{voto_parlamentar}}</p></font></h2>
</br>
</br>
<h2><font color="#459170"><p align="center" style="font-family:Verdana">Matéria em Votação</p></font></h2>
<table style="width:75%; border:1px;" align="center">
<tr><th style="text-align:center"><h4><font color="white">{{materia}}</font></th></tr>
<tr><th style="text-align:center"><h4><font color="white">{{ementa}}</font></th></tr>
<tr><th style="text-align:center"><font color="#45919D"><span id="resultado_votacao"></span></font></th></tr>
</table>
<br /><br />
<form method='POST'>
{% csrf_token %}
<table style="width:75%; border:1px;" align="center">
<tr><th style="text-align:center">
<select id="voto" name="voto" style="width:30%;">
<option value="">Selecione</option>
<option value="Sim">Sim</option>
<option value="Não">Não</option>
<option value="Absteção">Abstenção</option>
</select>
</th></tr>
<tr><th style="text-align:center">
<input type="submit" value="Votar" name="Votar" style="width:10%;"/>
</th></tr>
</table>
</form>
</body>
</html>

3
sapl/templates/parlamentares/layouts.yaml

@ -105,5 +105,4 @@ Frente:
Votante:
{% trans 'Votante' %}:
- parlamentar user
- data ip
- data

Loading…
Cancel
Save