From d4aeea3255be739bd6178625530437ff91eb1ca1 Mon Sep 17 00:00:00 2001 From: Eliseu Egewarth Date: Wed, 6 Sep 2017 09:01:13 -0300 Subject: [PATCH] =?UTF-8?q?Corrige=20implementa=C3=A7=C3=A3o=20para=20prob?= =?UTF-8?q?lemas=20apontados=20na=20issue=20#1387=20(#1456)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Eliseu Egewarth --- sapl/decorators.py | 27 +++++++++++++++------------ sapl/parlamentares/views.py | 12 ++++++------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/sapl/decorators.py b/sapl/decorators.py index 6bf61d81b..97f9af7a6 100644 --- a/sapl/decorators.py +++ b/sapl/decorators.py @@ -1,6 +1,8 @@ from datetime import date from functools import wraps +from django.utils.translation import ugettext_lazy as _ + def vigencia_atual(decorated_method): """ @@ -13,10 +15,7 @@ def vigencia_atual(decorated_method): """ @wraps(decorated_method) def display_atual(self): - try: - string_displayed = decorated_method(self) - except TypeError: - string_displayed = "" + string_displayed = decorated_method(self) if hasattr(self, 'data_inicio') and hasattr(self, 'data_fim'): today = date.today() @@ -24,16 +23,20 @@ def vigencia_atual(decorated_method): string_displayed = "{} {}".format( string_displayed, "(Atual)" if e_atual else "") else: - print('{} {}'.format( - "Instance does not have the attributes [{}, {}].".format( - 'data_inicio', - 'data_fim' - ), - "Decorator @{} has been disabled.".format( - vigencia_atual.__name__() - ) + instancia_sem_atributo = "{} [{}, {}].".format( + 'Instância não possui os atributos', + 'data_inicio', + 'data_fim') + + mensagem_decorator = "Decorator @{} foi desabilitado.".format( + vigencia_atual.__name__() + ) + print(_('{} {}'.format( + _(instancia_sem_atributo), + _(mensagem_decorator) ) ) + ) return string_displayed diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index fff00b775..75e1494c0 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -661,8 +661,8 @@ class MesaDiretoraView(FormView): sessoes = SessaoLegislativa.objects.filter( legislatura=legislatura).order_by("data_inicio") - today = datetime.now() - sessao_atual = sessoes.filter(data_inicio__year=today.year).first() + year = datetime.now().year + sessao_atual = sessoes.filter(data_inicio__year=year).first() mesa = sessao_atual.composicaomesa_set.all() if sessao_atual else [] @@ -716,9 +716,9 @@ def altera_field_mesa(request): # Caso a mudança tenha sido no campo legislatura, a sessão # atual deve ser a primeira daquela legislatura else: - today = datetime.now() + year = datetime.now().year try: - sessao_selecionada = sessoes.get(data_inicio__year=today.year).id + sessao_selecionada = sessoes.get(data_inicio__year=year).id except ObjectDoesNotExist: sessao_selecionada = sessoes.first().id @@ -884,8 +884,8 @@ def altera_field_mesa_public_view(request): # atual deve ser a primeira daquela legislatura else: try: - today = datetime.now() - sessao_selecionada = sessoes.get(data_inicio__year=today.year).id + year = datetime.now().year + sessao_selecionada = sessoes.get(data_inicio__year=year).id except ObjectDoesNotExist as e: sessao_selecionada = sessoes.first().id