mirror of https://github.com/interlegis/sapl.git
Browse Source
* Fix #1387 Signed-off-by: Eliseu Egewarth <eliseuegewarth@gmail.com> * Adiciona decorator vigencia_atual e aplica ele nas models Legislatura e SessaoLegislativa Signed-off-by: Eliseu Egewarth <eliseuegewarth@gmail.com> * Fix #1387 Signed-off-by: Eliseu Egewarth <eliseuegewarth@gmail.com>pull/1438/head
Eliseu Egewarth
7 years ago
committed by
Edward
3 changed files with 67 additions and 21 deletions
@ -0,0 +1,40 @@ |
|||
from datetime import date |
|||
from functools import wraps |
|||
|
|||
|
|||
def vigencia_atual(decorated_method): |
|||
""" |
|||
concatena a string ' (Atual)' caso a model instancia estiver |
|||
em vigência na data atual do servidor |
|||
|
|||
Premissas: |
|||
* A classe precisa conter os atributos 'data_inicio' e 'data_fim'. |
|||
* 'data_inicio' e 'data_fim' precisam ser do tipo models.DateField |
|||
""" |
|||
@wraps(decorated_method) |
|||
def display_atual(self): |
|||
try: |
|||
string_displayed = decorated_method(self) |
|||
except TypeError: |
|||
string_displayed = "" |
|||
|
|||
if hasattr(self, 'data_inicio') and hasattr(self, 'data_fim'): |
|||
today = date.today() |
|||
e_atual = self.data_inicio <= today <= self.data_fim |
|||
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__() |
|||
) |
|||
) |
|||
) |
|||
|
|||
return string_displayed |
|||
|
|||
return display_atual |
Loading…
Reference in new issue