From eb214e0541e61ef9b9c5e4a691ca945ca10ae148 Mon Sep 17 00:00:00 2001 From: eduardocalil Date: Wed, 8 Mar 2017 14:48:28 -0300 Subject: [PATCH] Fix #918 cronometro painel set (#919) * Fix #918 * Conserta alguns erros encontrados no teste --- sapl/base/forms.py | 11 ++++++- .../migrations/0032_auto_20170308_1006.py | 30 +++++++++++++++++++ sapl/base/models.py | 15 ++++++++++ sapl/base/templatetags/common_tags.py | 11 +++++++ sapl/parlamentares/models.py | 6 ++-- sapl/sessao/models.py | 4 +-- sapl/sessao/views.py | 24 ++++++++++++++- sapl/static/js/app.js | 1 + sapl/templates/base/layouts.yaml | 3 ++ sapl/templates/painel/index.html | 8 +++-- sapl/templates/sessao/painel.html | 7 +++-- sapl/utils.py | 11 ++++--- 12 files changed, 112 insertions(+), 19 deletions(-) create mode 100644 sapl/base/migrations/0032_auto_20170308_1006.py diff --git a/sapl/base/forms.py b/sapl/base/forms.py index ffca1eaa6..11d93a13f 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -694,7 +694,16 @@ class ConfiguracoesAppForm(ModelForm): 'texto_articulado_proposicao', 'texto_articulado_materia', 'texto_articulado_norma', - 'proposicao_incorporacao_obrigatoria'] + 'proposicao_incorporacao_obrigatoria', + 'cronometro_discurso', + 'cronometro_aparte', + 'cronometro_ordem'] + + def __init__(self, *args, **kwargs): + super(ConfiguracoesAppForm, self).__init__(*args, **kwargs) + self.fields['cronometro_discurso'].widget.attrs['class'] = 'cronometro' + self.fields['cronometro_aparte'].widget.attrs['class'] = 'cronometro' + self.fields['cronometro_ordem'].widget.attrs['class'] = 'cronometro' class RecuperarSenhaForm(PasswordResetForm): diff --git a/sapl/base/migrations/0032_auto_20170308_1006.py b/sapl/base/migrations/0032_auto_20170308_1006.py new file mode 100644 index 000000000..61172bbda --- /dev/null +++ b/sapl/base/migrations/0032_auto_20170308_1006.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2017-03-08 10:06 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0031_auto_20170203_1019'), + ] + + operations = [ + migrations.AddField( + model_name='appconfig', + name='cronometro_aparte', + field=models.TimeField(blank=True, null=True, verbose_name='Cronômetro do Aparte'), + ), + migrations.AddField( + model_name='appconfig', + name='cronometro_discurso', + field=models.TimeField(blank=True, null=True, verbose_name='Cronômetro do Discurso'), + ), + migrations.AddField( + model_name='appconfig', + name='cronometro_ordem', + field=models.TimeField(blank=True, null=True, verbose_name='Cronômetro da Ordem'), + ), + ] diff --git a/sapl/base/models.py b/sapl/base/models.py index ab95553ba..8d87b14cd 100644 --- a/sapl/base/models.py +++ b/sapl/base/models.py @@ -114,6 +114,21 @@ class AppConfig(models.Model): verbose_name=_('Regra de incorporação de proposições e protocolo'), max_length=1, choices=POLITICA_PROTOCOLO_CHOICES, default='O') + cronometro_discurso = models.TimeField( + verbose_name=_('Cronômetro do Discurso'), + blank=True, + null=True) + + cronometro_aparte = models.TimeField( + verbose_name=_('Cronômetro do Aparte'), + blank=True, + null=True) + + cronometro_ordem = models.TimeField( + verbose_name=_('Cronômetro da Ordem'), + blank=True, + null=True) + class Meta: verbose_name = _('Configurações da Aplicação') verbose_name_plural = _('Configurações da Aplicação') diff --git a/sapl/base/templatetags/common_tags.py b/sapl/base/templatetags/common_tags.py index b4f4bb23d..84b966598 100644 --- a/sapl/base/templatetags/common_tags.py +++ b/sapl/base/templatetags/common_tags.py @@ -121,3 +121,14 @@ def url(value): if value.startswith('http://') or value.startswith('https://'): return True return False + + +@register.filter +def cronometro_to_seconds(value): + if not AppConfig.attr('cronometro_' + value): + return 0 + + m, s, x = AppConfig.attr( + 'cronometro_' + value).isoformat().split(':') + + return 60 * int(m) + int(s) diff --git a/sapl/parlamentares/models.py b/sapl/parlamentares/models.py index 8cd2b6d4b..67f87673f 100644 --- a/sapl/parlamentares/models.py +++ b/sapl/parlamentares/models.py @@ -7,9 +7,9 @@ from model_utils import Choices from sapl.base.models import Autor from sapl.utils import (INDICADOR_AFASTAMENTO, UF, YES_NO_CHOICES, - SaplGenericRelation, intervalos_tem_intersecao, - restringe_tipos_de_arquivo_img, - get_settings_auth_user_model, texto_upload_path) + SaplGenericRelation, get_settings_auth_user_model, + intervalos_tem_intersecao, + restringe_tipos_de_arquivo_img, texto_upload_path) class Legislatura(models.Model): diff --git a/sapl/sessao/models.py b/sapl/sessao/models.py index 9a5aae5cc..0a414a1cc 100644 --- a/sapl/sessao/models.py +++ b/sapl/sessao/models.py @@ -8,8 +8,8 @@ from sapl.materia.models import MateriaLegislativa from sapl.parlamentares.models import (CargoMesa, Legislatura, Parlamentar, Partido, SessaoLegislativa) from sapl.utils import (YES_NO_CHOICES, SaplGenericRelation, - restringe_tipos_de_arquivo_txt, texto_upload_path, - get_settings_auth_user_model) + get_settings_auth_user_model, + restringe_tipos_de_arquivo_txt, texto_upload_path) class CargoBancada(models.Model): diff --git a/sapl/sessao/views.py b/sapl/sessao/views.py index 626aa234b..a20a6bda2 100644 --- a/sapl/sessao/views.py +++ b/sapl/sessao/views.py @@ -590,16 +590,38 @@ class PainelView(PermissionRequiredForAppCrudMixin, TemplateView): def get(self, request, *args, **kwargs): if request.user.is_anonymous(): self.template_name = 'painel/index.html' + return TemplateView.get(self, request, *args, **kwargs) def get_context_data(self, **kwargs): + cronometro_discurso = AppsAppConfig.attr('cronometro_discurso') + cronometro_aparte = AppsAppConfig.attr('cronometro_aparte') + cronometro_ordem = AppsAppConfig.attr('cronometro_ordem') + + if not cronometro_discurso or not cronometro_aparte or not cronometro_ordem: + msg = _( + 'Você precisa primeiro configurar os cronômetros nas Configurações da Aplicação') + messages.add_message(self.request, messages.ERROR, msg) + + else: + m, s, x = cronometro_discurso.isoformat().split(':') + cronometro_discurso = int(m) * 60 + int(s) + + m, s, x = cronometro_aparte.isoformat().split(':') + cronometro_aparte = int(m) * 60 + int(s) + + m, s, x = cronometro_ordem.isoformat().split(':') + cronometro_ordem = int(m) * 60 + int(s) context = TemplateView.get_context_data(self, **kwargs) context.update({ 'head_title': str(_('Painel Plenário')), 'sessao_id': kwargs['pk'], 'root_pk': kwargs['pk'], - 'sessaoplenaria': SessaoPlenaria.objects.get(pk=kwargs['pk'])}) + 'sessaoplenaria': SessaoPlenaria.objects.get(pk=kwargs['pk']), + 'cronometro_discurso': cronometro_discurso, + 'cronometro_aparte': cronometro_aparte, + 'cronometro_ordem': cronometro_ordem}) return context diff --git a/sapl/static/js/app.js b/sapl/static/js/app.js index 139806ffb..d96090f5e 100644 --- a/sapl/static/js/app.js +++ b/sapl/static/js/app.js @@ -48,6 +48,7 @@ function refreshMask() { $('.dateinput').mask('00/00/0000', {placeholder:"__/__/____"}); $('.hora').mask("00:00", {placeholder:"hh:mm"}); $('.hora_hms').mask("00:00:00", {placeholder:"hh:mm:ss"}); + $('.cronometro').mask("00:00", {placeholder:"mm:ss"}); } function autorModal() { diff --git a/sapl/templates/base/layouts.yaml b/sapl/templates/base/layouts.yaml index ac9607c3f..cfa78b435 100644 --- a/sapl/templates/base/layouts.yaml +++ b/sapl/templates/base/layouts.yaml @@ -20,6 +20,9 @@ AppConfig: {% trans 'Textos Articulados' %}: - texto_articulado_proposicao texto_articulado_materia texto_articulado_norma + {% trans 'Cronômetros do Painel' %}: + - cronometro_discurso cronometro_aparte cronometro_ordem + TipoAutor: {% trans 'Tipo Autor' %}: - content_type:4 descricao diff --git a/sapl/templates/painel/index.html b/sapl/templates/painel/index.html index a91179cfc..b78fb7774 100644 --- a/sapl/templates/painel/index.html +++ b/sapl/templates/painel/index.html @@ -1,5 +1,6 @@ {% load i18n %} {% load staticfiles sass_tags %} +{% load common_tags %} @@ -39,6 +40,7 @@ +
@@ -119,7 +121,7 @@ $('#cronometro_discurso').runner({ autostart: false, countdown: true, - startAt: 5 * 60 * 1000, // 5 minutes + startAt: {{ 'discurso'|cronometro_to_seconds }} * 1000, stopAt: 0, milliseconds: false }).on('runnerFinish', function(eventObject, info){ @@ -129,7 +131,7 @@ $('#cronometro_aparte').runner({ autostart: false, countdown: true, - startAt: 3 * 60 * 1000, // 3 minutes + startAt: {{ 'aparte'|cronometro_to_seconds }} * 1000, stopAt: 0, milliseconds: false }).on('runnerFinish', function(eventObject, info){ @@ -139,7 +141,7 @@ $('#cronometro_ordem').runner({ autostart: false, countdown: true, - startAt: 2 * 60 * 1000, // 2 minutes + startAt: {{ 'ordem'|cronometro_to_seconds }} * 1000, stopAt: 0, milliseconds: false }).on('runnerFinish', function(eventObject, info){ diff --git a/sapl/templates/sessao/painel.html b/sapl/templates/sessao/painel.html index cd6f80f3f..24a157b0b 100644 --- a/sapl/templates/sessao/painel.html +++ b/sapl/templates/sessao/painel.html @@ -21,6 +21,7 @@
Controlador Painel

+

Operação do Painel Eletrônico


@@ -101,7 +102,7 @@ $(function() { $('#discurso').runner({ autostart: false, countdown: true, - startAt: 60 * 5 * 1000, + startAt: {{cronometro_discurso}} * 1000, stopAt: 0, milliseconds: false }).on('runnerFinish', function(eventObject, info){ @@ -156,7 +157,7 @@ $(function() { $('#aparte').runner({ autostart: false, countdown: true, - startAt: 60 * 3 * 1000, + startAt: {{cronometro_aparte}} * 1000, stopAt: 0, milliseconds: false }).on('runnerFinish', function(eventObject, info){ @@ -210,7 +211,7 @@ $(function() { $('#ordem').runner({ autostart: false, countdown: true, - startAt: 60 * 2 * 1000, + startAt: {{cronometro_ordem}} * 1000, stopAt: 0, milliseconds: false }).on('runnerFinish', function(eventObject, info){ diff --git a/sapl/utils.py b/sapl/utils.py index 11ef6ed84..1ff86f0fd 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -1,10 +1,12 @@ -from datetime import date -from functools import wraps -from unicodedata import normalize as unicodedata_normalize import hashlib import logging import re +from datetime import date +from functools import wraps +from unicodedata import normalize as unicodedata_normalize +import django_filters +import magic from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button from django import forms @@ -17,13 +19,10 @@ from django.core.exceptions import ValidationError from django.utils.text import slugify from django.utils.translation import ugettext_lazy as _ from floppyforms import ClearableFileInput -import django_filters -import magic from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row from sapl.settings import BASE_DIR - sapl_logger = logging.getLogger(BASE_DIR.name)