From c3a8f6690154bb3296bc5ba20ef816ea3621ed41 Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Tue, 28 Jul 2015 14:49:05 -0300 Subject: [PATCH] Add yes/no choices for fields as an util constant --- comissoes/models.py | 9 ++------- parlamentares/models.py | 5 +++-- sapl/utils.py | 3 +++ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/comissoes/models.py b/comissoes/models.py index 859328165..f7ba3261a 100644 --- a/comissoes/models.py +++ b/comissoes/models.py @@ -2,7 +2,7 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ from parlamentares.models import Parlamentar -from sapl.utils import make_choices +from sapl.utils import YES_NO_CHOICES, make_choices class TipoComissao(models.Model): @@ -29,11 +29,6 @@ class TipoComissao(models.Model): class Comissao(models.Model): - UNIDADE_DELIBERATIVA_CHOICES, SIM, NAO = make_choices( - True, _('Sim'), - False, _('Não'), - ) - tipo = models.ForeignKey(TipoComissao, verbose_name=_('Tipo')) nome = models.CharField(max_length=60, verbose_name=_('Nome')) sigla = models.CharField(max_length=10, verbose_name=_('Sigla')) @@ -81,7 +76,7 @@ class Comissao(models.Model): email = models.CharField( max_length=100, blank=True, null=True, verbose_name=_('E-mail')) unidade_deliberativa = models.BooleanField( - choices=UNIDADE_DELIBERATIVA_CHOICES, + choices=YES_NO_CHOICES, verbose_name=_('Unidade Deliberativa')) class Meta: diff --git a/parlamentares/models.py b/parlamentares/models.py index 33f08e592..64323fd33 100644 --- a/parlamentares/models.py +++ b/parlamentares/models.py @@ -1,7 +1,7 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ -from sapl.utils import make_choices +from sapl.utils import YES_NO_CHOICES, make_choices class Legislatura(models.Model): @@ -371,7 +371,8 @@ class CargoMesa(models.Model): # TODO M2M ???? descricao = models.CharField( max_length=50, verbose_name=_('Cargo na Mesa')) - unico = models.BooleanField(verbose_name=_('Cargo Único')) + unico = models.BooleanField( + choices=YES_NO_CHOICES, verbose_name=_('Cargo Único')) class Meta: verbose_name = _('Cargo na Mesa') diff --git a/sapl/utils.py b/sapl/utils.py index ef1a896e8..3312fd119 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -1,5 +1,6 @@ from django.apps import apps from django.contrib import admin +from django.utils.translation import ugettext_lazy as _ # SAPL business apps # This is a dependency order: each entry depends only on previous ones @@ -33,3 +34,5 @@ def make_choices(*choice_pairs): yield choices for key, value in choices: yield key + +YES_NO_CHOICES = [(True, _('Sim')), (False, _('Não'))]