diff --git a/sapl/norma/forms.py b/sapl/norma/forms.py index 8e60ed8cc..6fc6ca521 100644 --- a/sapl/norma/forms.py +++ b/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'), diff --git a/sapl/painel/views.py b/sapl/painel/views.py index 788103e6a..cbdc94335 100644 --- a/sapl/painel/views.py +++ b/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) diff --git a/sapl/parlamentares/forms.py b/sapl/parlamentares/forms.py index 73e4f90a4..a5f23697b 100644 --- a/sapl/parlamentares/forms.py +++ b/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)]) diff --git a/sapl/parlamentares/migrations/0038_auto_20170213_1425.py b/sapl/parlamentares/migrations/0038_auto_20170213_1425.py new file mode 100644 index 000000000..7134cef57 --- /dev/null +++ b/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'}, + ), + ] diff --git a/sapl/parlamentares/migrations/0039_remove_votante_ip.py b/sapl/parlamentares/migrations/0039_remove_votante_ip.py new file mode 100644 index 000000000..9ae65babd --- /dev/null +++ b/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', + ), + ] diff --git a/sapl/parlamentares/models.py b/sapl/parlamentares/models.py index 253bc94ca..4fbecaab7 100644 --- a/sapl/parlamentares/models.py +++ b/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') diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index 366a08715..7d0d47306 100644 --- a/sapl/parlamentares/views.py +++ b/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): diff --git a/sapl/sessao/migrations/0034_votonominal.py b/sapl/sessao/migrations/0034_votonominal.py new file mode 100644 index 000000000..37ab664c7 --- /dev/null +++ b/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', + }, + ), + ] diff --git a/sapl/sessao/migrations/0035_auto_20170213_1455.py b/sapl/sessao/migrations/0035_auto_20170213_1455.py new file mode 100644 index 000000000..391c293b0 --- /dev/null +++ b/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', + ), + ] diff --git a/sapl/sessao/models.py b/sapl/sessao/models.py index af22e1d1d..07cfc3791 100644 --- a/sapl/sessao/models.py +++ b/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) diff --git a/sapl/templates/painel/voto_nominal.html b/sapl/templates/painel/voto_nominal.html index 5aff93b87..a4c5876e2 100644 --- a/sapl/templates/painel/voto_nominal.html +++ b/sapl/templates/painel/voto_nominal.html @@ -1,5 +1,66 @@ -head_title = {{head_title}}
-sessao_id = {{sessao_id}}
-materia = {{materia}}
-permissao = {{permissao}}
-presente = {{presente}}
+{% load i18n %} +{% load staticfiles sass_tags %} + + + + + + {% block head_title %}{% trans 'SAPL - Sistema de Apoio ao Processo Legislativo' %}{% endblock %} + + + + + + + + +

{{sessao}}

+ + + + + +
Data Início: {{hora}}Hora Início: {{data}}
+

+ +
+
+

Voto: {{voto_parlamentar}}

+
+
+ +

Matéria em Votação

+ + + + +

{{materia}}

{{ementa}}

+ +

+
+ {% csrf_token %} + + + +
+ +
+ +
+
+ + diff --git a/sapl/templates/parlamentares/layouts.yaml b/sapl/templates/parlamentares/layouts.yaml index 385c0caf6..7105ce9d3 100644 --- a/sapl/templates/parlamentares/layouts.yaml +++ b/sapl/templates/parlamentares/layouts.yaml @@ -105,5 +105,4 @@ Frente: Votante: {% trans 'Votante' %}: - parlamentar user - - data ip - + - data