From b97574476d2825f53adff105fbd6e676209f1de1 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Mon, 23 Nov 2015 17:15:09 -0200 Subject: [PATCH] Add sync between stopwatches of Painel two windows. --- barcode.py | 27 ++++++++++++++++++ painel/urls.py | 6 ++-- painel/views.py | 29 +++++++++++++------ templates/painel/index.html | 55 +++++++++++++++++++++++++++++++++--- templates/sessao/painel.html | 36 ++++++++++++----------- 5 files changed, 122 insertions(+), 31 deletions(-) create mode 100644 barcode.py diff --git a/barcode.py b/barcode.py new file mode 100644 index 000000000..bfa265e73 --- /dev/null +++ b/barcode.py @@ -0,0 +1,27 @@ +from reportlab.lib.units import mm +from reportlab.graphics.barcode import createBarcodeDrawing +from reportlab.graphics.shapes import Drawing, String +from reportlab.graphics.charts.barcharts import HorizontalBarChart + + +class BarcodeDrawing(Drawing): + + def __init__(self, text_value, *args, **kw): + barcode = createBarcodeDrawing( + 'Code128', value=text_value, barHeight=10 * mm, humanReadable=True) + Drawing.__init__(self, barcode.width, barcode.height, *args, **kw) + self.add(barcode, name='barcode') + + +# def barcode(request): +# #instantiate a drawing object +# import barcode +# d = barcode.BarcodeDrawing("HELLO WORLD") +# binaryStuff = d.asString('gif') +# return HttpResponse(binaryStuff, 'image/gif') + +if __name__ == '__main__': + # use the standard 'save' method to save barcode.gif, barcode.pdf etc + # for quick feedback while working. + BarcodeDrawing("HELLO WORLD").save( + formats=['gif', 'pdf'], outDir='.', fnRoot='barcode') diff --git a/painel/urls.py b/painel/urls.py index 1dbcb66cc..922b499a4 100644 --- a/painel/urls.py +++ b/painel/urls.py @@ -1,6 +1,7 @@ from django.conf.urls import include, url -from .views import (controlador_painel, cronometro_painel_crud, +from .views import (controlador_painel, #cronometro_painel_crud, + cronometro_painel, get_dados_painel, painel_mensagem_view, painel_parlamentares_view, painel_view, painel_votacao_view) @@ -14,5 +15,6 @@ urlpatterns = [ url(r'^painel/parlamentares$', painel_parlamentares_view, name='painel_parlamentares'), url(r'^painel/votacao$', painel_votacao_view, name='painel_votacao'), - url(r'^painel/cronometro$', include(cronometro_painel_crud.urls)), + url(r'^painel/cronometro$', cronometro_painel, name='cronometro_painel'), + # url(r'^painel/cronometro$', include(cronometro_painel_crud.urls)), ] diff --git a/painel/views.py b/painel/views.py index 9b9c8a59b..235a2db18 100644 --- a/painel/views.py +++ b/painel/views.py @@ -45,15 +45,7 @@ def controlador_painel(request): context = {'painel': painel, 'PAINEL_TYPES': Painel.PAINEL_TYPES} return render(request, 'painel/controlador.html', context) - -def cronometro_painel(request): - print(request.POST) - - return HttpResponse({}) - - def painel_view(request, pk): - print(pk) context = {'head_title': 'Painel Plenário', 'sessao_id': pk} return render(request, 'painel/index.html', {'context': context}) @@ -69,6 +61,19 @@ def painel_parlamentares_view(request): def painel_votacao_view(request): return render(request, 'painel/votacao.html') +def cronometro_painel(request): + print(request.GET['tipo'] + ' ' + request.GET['action']); + + request.session[request.GET['tipo']] = request.GET['action']; + return HttpResponse({}) + +def get_cronometro_status(request, name): + try: + cronometro = request.session[name] + except KeyError: + cronometro = '' + return cronometro + def get_dados_painel(request, pk): # Sessão Plenária @@ -87,7 +92,6 @@ def get_dados_painel(request, pk): # Presença Sessão Plenária sessao_plenaria_presenca = SessaoPlenariaPresenca.objects.filter( sessao_plenaria_id=sessao_plenaria_id) - print(sessao_plenaria_presenca) presentes_sessao_plenaria = [ p.parlamentar.nome_parlamentar for p in sessao_plenaria_presenca] num_presentes_sessao_plen = len(presentes_sessao_plenaria) @@ -149,6 +153,10 @@ def get_dados_painel(request, pk): materia_observacao = "" tipo_votacao = "" + cronometro_discurso = get_cronometro_status(request, 'discurso') + cronometro_aparte = get_cronometro_status(request, 'aparte') + cronometro_ordem = get_cronometro_status(request, 'ordem') + votacao_json = {"sessao_plenaria": str(sessao_plenaria), "sessao_plenaria_data": sessao_plenaria.data_inicio, "sessao_plenaria_hora_inicio": sessao_plenaria.hora_inicio, @@ -167,6 +175,9 @@ def get_dados_painel(request, pk): "total_votos": total_votos, "tipo_resultado": tipo_resultado, "votos": votos, + "cronometro_aparte": cronometro_aparte, + "cronometro_discurso": cronometro_discurso, + "cronometro_ordem": cronometro_ordem, } return JsonResponse(votacao_json) diff --git a/templates/painel/index.html b/templates/painel/index.html index 53dc085f7..35c8cc202 100644 --- a/templates/painel/index.html +++ b/templates/painel/index.html @@ -12,6 +12,7 @@ {% block head_title %}{% trans 'SAPL - Sistema de Apoio ao Processo Legislativo' %}{% endblock %} +