diff --git a/painel/migrations/0001_initial.py b/painel/migrations/0001_initial.py new file mode 100644 index 000000000..3fa9fdd97 --- /dev/null +++ b/painel/migrations/0001_initial.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Cronometro', + fields=[ + ('id', models.AutoField(serialize=False, primary_key=True, auto_created=True, verbose_name='ID')), + ('start', models.PositiveIntegerField()), + ('reset', models.PositiveIntegerField()), + ('stop', models.PositiveIntegerField()), + ('tipo', models.CharField(choices=[('A', 'Aparte'), ('D', 'Discurso'), ('O', 'Ordem do dia')], max_length=1)), + ], + ), + migrations.CreateModel( + name='Painel', + fields=[ + ('id', models.AutoField(serialize=False, primary_key=True, auto_created=True, verbose_name='ID')), + ('abrir', models.PositiveIntegerField()), + ('fechar', models.PositiveIntegerField()), + ('mostrar', models.CharField(choices=[('C', 'Completo'), ('P', 'Parlamentares'), ('V', 'Votação'), ('M', 'Mensagem')], max_length=1)), + ], + ), + ] diff --git a/painel/migrations/0002_auto_20150908_1435.py b/painel/migrations/0002_auto_20150908_1435.py new file mode 100644 index 000000000..3c98a7701 --- /dev/null +++ b/painel/migrations/0002_auto_20150908_1435.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +from django.utils.timezone import utc +import datetime + + +class Migration(migrations.Migration): + + dependencies = [ + ('painel', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='cronometro', + name='data', + field=models.DateField(null=True, verbose_name='Data cronômetro', auto_now_add=True), + ), + migrations.AddField( + model_name='painel', + name='data_painel', + field=models.DateField(default=datetime.datetime(2015, 9, 8, 17, 35, 48, 279510, tzinfo=utc), verbose_name='Data painel', auto_now_add=True), + preserve_default=False, + ), + migrations.AlterField( + model_name='cronometro', + name='reset', + field=models.PositiveIntegerField(verbose_name='Reiniciar cronômetro'), + ), + migrations.AlterField( + model_name='cronometro', + name='start', + field=models.PositiveIntegerField(verbose_name='Iniciar cronômetro'), + ), + migrations.AlterField( + model_name='cronometro', + name='stop', + field=models.PositiveIntegerField(verbose_name='Parar cronômetro'), + ), + migrations.AlterField( + model_name='cronometro', + name='tipo', + field=models.CharField(choices=[('A', 'Aparte'), ('D', 'Discurso'), ('O', 'Ordem do dia')], verbose_name='Tipo Cronômetro', max_length=1), + ), + migrations.AlterField( + model_name='painel', + name='abrir', + field=models.PositiveIntegerField(default=0, verbose_name='Abrir painel'), + ), + migrations.AlterField( + model_name='painel', + name='fechar', + field=models.PositiveIntegerField(default=1, verbose_name='Fechar painel'), + ), + migrations.AlterField( + model_name='painel', + name='mostrar', + field=models.CharField(default='C', choices=[('C', 'Completo'), ('P', 'Parlamentares'), ('V', 'Votação'), ('M', 'Mensagem')], max_length=1), + ), + ] diff --git a/painel/migrations/0003_auto_20150908_1444.py b/painel/migrations/0003_auto_20150908_1444.py new file mode 100644 index 000000000..77e54a2b9 --- /dev/null +++ b/painel/migrations/0003_auto_20150908_1444.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +from django.utils.timezone import utc +import datetime + + +class Migration(migrations.Migration): + + dependencies = [ + ('painel', '0002_auto_20150908_1435'), + ] + + operations = [ + migrations.AlterField( + model_name='cronometro', + name='data', + field=models.DateField(verbose_name='Data cronômetro', default=datetime.datetime(2015, 9, 8, 17, 44, 1, 708326, tzinfo=utc)), + preserve_default=False, + ), + migrations.AlterField( + model_name='painel', + name='data_painel', + field=models.DateField(verbose_name='Data painel'), + ), + ] diff --git a/painel/models.py b/painel/models.py index 0b4331b36..aa9fb4856 100644 --- a/painel/models.py +++ b/painel/models.py @@ -1,3 +1,33 @@ -# from django.db import models +from django.db import models -# Create your models here. + +class Cronometro(models.Model): + CRONOMETRO_TYPES = ( + ('A', 'Aparte'), + ('D', 'Discurso'), + ('O', 'Ordem do dia') + ) + + start = models.PositiveIntegerField(verbose_name='Iniciar cronômetro') + reset = models.PositiveIntegerField(verbose_name='Reiniciar cronômetro') + stop = models.PositiveIntegerField(verbose_name='Parar cronômetro') + data = models.DateField(verbose_name='Data cronômetro') + tipo = models.CharField( + max_length=1, choices=CRONOMETRO_TYPES, verbose_name='Tipo Cronômetro') + + +class Painel(models.Model): + PAINEL_TYPES = ( + ('C', 'Completo'), + ('P', 'Parlamentares'), + ('V', 'Votação'), + ('M', 'Mensagem'), + ) + + abrir = models.PositiveIntegerField(verbose_name='Abrir painel', default=0) + fechar = models.PositiveIntegerField( + verbose_name='Fechar painel', default=1) + data_painel = models.DateField(verbose_name='Data painel') + mostrar = models.CharField(max_length=1, + choices=PAINEL_TYPES, + default='C') diff --git a/painel/urls.py b/painel/urls.py index 88ec93ba4..36e6bb312 100644 --- a/painel/urls.py +++ b/painel/urls.py @@ -1,10 +1,13 @@ from django.conf.urls import url -from .views import (json_presenca, json_votacao, painel_parlamentares_view, - painel_view, painel_votacao_view) +from .views import (controlador_painel, json_presenca, json_votacao, + painel_parlamentares_view, painel_view, + painel_votacao_view) urlpatterns = [ url(r'^sistema/painel$', painel_view), + url(r'^sistema/painel/controlador', + controlador_painel, name='controlador_painel'), url(r'^sistema/painel/parlamentares', painel_parlamentares_view), url(r'^sistema/painel/votacao', painel_votacao_view), url(r'^sistema/painel/json_presenca', json_presenca, name='json_presenca'), diff --git a/painel/views.py b/painel/views.py index 763d56cca..973d665f7 100644 --- a/painel/views.py +++ b/painel/views.py @@ -1,16 +1,51 @@ - from django.core import serializers from django.http import HttpResponse, JsonResponse from django.shortcuts import render +from painel.models import Painel from parlamentares.models import Filiacao from sessao.models import (OrdemDia, PresencaOrdemDia, RegistroVotacao, SessaoPlenaria, SessaoPlenariaPresenca, VotoParlamentar) +# UI views + + +def controlador_painel(request): + + painel = Painel.objects.update_or_create(abrir=0, fechar=1, mostrar='C')[0] + + if request.method == 'POST': + if 'start-painel' in request.POST: + painel.abrir = 1 + painel.fechar = 0 + painel.save() + elif 'stop-painel' in request.POST: + painel.abrir = 0 + painel.fechar = 1 + painel.save() + + context = {'painel': painel} + print(painel.abrir) + return render(request, 'painel/controller.html', context) + + +def painel_view(request): + context = {'head_title': 'Painel Plenário', + 'title': '3a. Sessao Ordinária do Município XYZ'} + return render(request, 'painel/index.html', {'context': context}) + + +def painel_parlamentares_view(request): + return render(request, 'painel/parlamentares.html') + + +def painel_votacao_view(request): + return render(request, 'painel/votacao.html') # REST web services + def json_presenca(request): presencas = PresencaOrdemDia.objects.filter(sessao_plenaria_id=50) parlamentares = [] @@ -18,7 +53,7 @@ def json_presenca(request): parlamentares.append(p.parlamentar) # parlamentares = serializers.serialize('json', Parlamentar.objects.all()) parlamentares = serializers.serialize('json', parlamentares) - return HttpResponse(parlamentares, content_type='application/json') + return HttpResponse(parlamentares, content_type='application/json') # return JsonResponse(data) # work with python dict @@ -61,7 +96,7 @@ def json_votacao(request): nome_parlamentar = p.parlamentar.nome_parlamentar presentes_ordem_dia.append( {'nome': nome_parlamentar, - 'partido': parlamentar_partido[nome_parlamentar], + 'partido': parlamentar_partido[nome_parlamentar], 'voto': votos.get(nome_parlamentar, '-')}) total_votos = votacao.numero_votos_sim + \ @@ -93,19 +128,3 @@ def json_votacao(request): "presentes_sessao_plenaria": presentes_sessao_plenaria, } return JsonResponse(votacao_json) - - -# UI views - -def painel_view(request): - context = {'head_title': 'Painel Plenário', - 'title': '3a. Sessao Ordinária do Município XYZ'} - return render(request, 'painel/index.html', {'context': context}) - - -def painel_parlamentares_view(request): - return render(request, 'painel/parlamentares.html') - - -def painel_votacao_view(request): - return render(request, 'painel/votacao.html') diff --git a/requirements/dev-requirements.txt b/requirements/dev-requirements.txt index d532fbf88..330ef2854 100644 --- a/requirements/dev-requirements.txt +++ b/requirements/dev-requirements.txt @@ -5,5 +5,6 @@ django-extensions flake8 ipdb isort +autopep8 pygraphviz==1.3rc2 pytest-ipdb==0.1-prerelease2 diff --git a/scripts/voto_parlamentar.sql b/scripts/voto_parlamentar.sql new file mode 100644 index 000000000..88b15f954 --- /dev/null +++ b/scripts/voto_parlamentar.sql @@ -0,0 +1,13 @@ + +INSERT INTO sessao_votoparlamentar (id, parlamentar_id, voto, votacao_id) values (1, 21, 'S', 83); +INSERT INTO sessao_votoparlamentar (id, parlamentar_id, voto, votacao_id) values (2, 23, 'S', 83); +INSERT INTO sessao_votoparlamentar (id, parlamentar_id, voto, votacao_id) values (3, 33, 'S', 83); +INSERT INTO sessao_votoparlamentar (id, parlamentar_id, voto, votacao_id) values (4, 112, 'S', 83); +INSERT INTO sessao_votoparlamentar (id, parlamentar_id, voto, votacao_id) values (5, 117, 'S', 83); + +INSERT INTO sessao_votoparlamentar (id, parlamentar_id, voto, votacao_id) values (9, 116, 'N', 83); +INSERT INTO sessao_votoparlamentar (id, parlamentar_id, voto, votacao_id) values (6, 120, 'N', 83); +INSERT INTO sessao_votoparlamentar (id, parlamentar_id, voto, votacao_id) values (7, 121, 'N', 83); +INSERT INTO sessao_votoparlamentar (id, parlamentar_id, voto, votacao_id) values (8, 122, 'N', 83); + +SELECT * FROM sessao_votoparlamentar; \ No newline at end of file diff --git a/templates/painel/controlador.html b/templates/painel/controlador.html deleted file mode 100644 index 672c86320..000000000 --- a/templates/painel/controlador.html +++ /dev/null @@ -1,45 +0,0 @@ -{% load i18n %} -{% load staticfiles %} - - - - - - -
- - -