Browse Source

Refatora model choices usando django-model-utils

Fix #122
pull/237/head
Marcio Mazza 9 years ago
parent
commit
4161c8c69c
  1. 9
      comissoes/models.py
  2. 53
      materia/models.py
  3. 11
      norma/models.py
  4. 9
      parlamentares/models.py
  5. 9
      protocoloadm/models.py
  6. 1
      requirements/requirements.txt
  7. 14
      sapl/test_utils.py
  8. 8
      sapl/utils.py
  9. 11
      sessao/models.py

9
comissoes/models.py

@ -1,15 +1,14 @@
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from model_utils import Choices
from parlamentares.models import Parlamentar from parlamentares.models import Parlamentar
from sapl.utils import YES_NO_CHOICES, make_choices from sapl.utils import YES_NO_CHOICES
class TipoComissao(models.Model): class TipoComissao(models.Model):
NATUREZA_CHOICES, TEMPORARIA, PERMANENTE = make_choices( NATUREZA_CHOICES = Choices(('T', 'temporaria', _('Temporária')),
'T', _('Temporária'), ('P', 'permanente', _('Permanente')))
'P', _('Permanente'),
)
nome = models.CharField(max_length=50, verbose_name=_('Nome')) nome = models.CharField(max_length=50, verbose_name=_('Nome'))
natureza = models.CharField( natureza = models.CharField(
max_length=1, verbose_name=_('Natureza'), choices=NATUREZA_CHOICES) max_length=1, verbose_name=_('Natureza'), choices=NATUREZA_CHOICES)

53
materia/models.py

@ -1,9 +1,10 @@
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from model_utils import Choices
from comissoes.models import Comissao from comissoes.models import Comissao
from parlamentares.models import Parlamentar, Partido from parlamentares.models import Parlamentar, Partido
from sapl.utils import YES_NO_CHOICES, make_choices, xstr from sapl.utils import YES_NO_CHOICES, xstr
class TipoMateriaLegislativa(models.Model): class TipoMateriaLegislativa(models.Model):
@ -53,11 +54,11 @@ def texto_upload_path(instance, filename):
return get_materia_media_path(instance, 'materia', filename) return get_materia_media_path(instance, 'materia', filename)
TIPO_APRESENTACAO_CHOICES = Choices(('O', 'oral', _('Oral')),
('E', 'escrita', _('Escrita')))
class MateriaLegislativa(models.Model): class MateriaLegislativa(models.Model):
TIPO_APRESENTACAO_CHOICES, ORAL, ESCRITA = make_choices(
'O', _('Oral'),
'E', _('Escrita'),
)
tipo = models.ForeignKey(TipoMateriaLegislativa, verbose_name=_('Tipo')) tipo = models.ForeignKey(TipoMateriaLegislativa, verbose_name=_('Tipo'))
numero = models.PositiveIntegerField(verbose_name=_('Número')) numero = models.PositiveIntegerField(verbose_name=_('Número'))
@ -375,16 +376,11 @@ class Relatoria(models.Model):
class Parecer(models.Model): class Parecer(models.Model):
APRESENTACAO_CHOICES, ORAL, ESCRITA = make_choices(
'O', _('Oral'),
'E', _('Escrita'),
)
relatoria = models.ForeignKey(Relatoria) relatoria = models.ForeignKey(Relatoria)
materia = models.ForeignKey(MateriaLegislativa) materia = models.ForeignKey(MateriaLegislativa)
tipo_conclusao = models.CharField(max_length=3, blank=True) tipo_conclusao = models.CharField(max_length=3, blank=True)
tipo_apresentacao = models.CharField( tipo_apresentacao = models.CharField(
max_length=1, choices=APRESENTACAO_CHOICES) max_length=1, choices=TIPO_APRESENTACAO_CHOICES)
parecer = models.TextField(blank=True) parecer = models.TextField(blank=True)
class Meta: class Meta:
@ -398,10 +394,8 @@ class Parecer(models.Model):
class TipoProposicao(models.Model): class TipoProposicao(models.Model):
MAT_OU_DOC_CHOICES, MATERIA, DOCUMENTO = make_choices( MAT_OU_DOC_CHOICES = Choices(('M', 'materia', _('Matéria')),
'M', _('Matéria'), ('D', 'documento', _('Documento')))
'D', _('Documento'),
)
descricao = models.CharField(max_length=50, verbose_name=_('Descrição')) descricao = models.CharField(max_length=50, verbose_name=_('Descrição'))
materia_ou_documento = models.CharField( materia_ou_documento = models.CharField(
@ -469,10 +463,8 @@ class Proposicao(models.Model):
class StatusTramitacao(models.Model): class StatusTramitacao(models.Model):
INDICADOR_CHOICES, FIM, RETORNO = make_choices( INDICADOR_CHOICES = Choices(('F', 'fim', _('Fim')),
'F', _('Fim'), ('R', 'retorno', _('Retorno')))
'R', _('Retorno'),
)
sigla = models.CharField(max_length=10, verbose_name=_('Sigla')) sigla = models.CharField(max_length=10, verbose_name=_('Sigla'))
descricao = models.CharField(max_length=60, verbose_name=_('Descrição')) descricao = models.CharField(max_length=60, verbose_name=_('Descrição'))
@ -516,19 +508,16 @@ class UnidadeTramitacao(models.Model):
class Tramitacao(models.Model): class Tramitacao(models.Model):
TURNO_CHOICES, \ TURNO_CHOICES = Choices(
PRIMEIRO, SEGUNDO, UNICO, SUPLEMENTAR, FINAL, \ ('P', 'primeiro', _('Primeiro')),
VOTACAO_UNICA, PRIMEIRA_VOTACAO, \ ('S', 'segundo', _('Segundo')),
SEGUNDA_TERCEIRA_VOTACAO = make_choices( ('Ú', 'unico', _('Único')),
'P', _('Primeiro'), ('L', 'suplementar', _('Suplementar')),
'S', _('Segundo'), ('F', 'final', _('Final')),
'Ú', _('Único'), ('A', 'votacao_unica', _('Votação única em Regime de Urgência')),
'L', _('Suplementar'), ('B', 'primeira_votacao', _('1ª Votação')),
'F', _('Final'), ('C', 'segunda_terceira_votacao', _('2ª e 3ª Votação')),
'A', _('Votação única em Regime de Urgência'), )
'B', _('1ª Votação'),
'C', _('2ª e 3ª Votação'),
)
status = models.ForeignKey( status = models.ForeignKey(
StatusTramitacao, blank=True, null=True, verbose_name=_('Status')) StatusTramitacao, blank=True, null=True, verbose_name=_('Status'))

11
norma/models.py

@ -1,9 +1,10 @@
from django.db import models from django.db import models
from django.template import defaultfilters from django.template import defaultfilters
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from model_utils import Choices
from materia.models import MateriaLegislativa from materia.models import MateriaLegislativa
from sapl.utils import YES_NO_CHOICES, make_choices from sapl.utils import YES_NO_CHOICES
class AssuntoNorma(models.Model): class AssuntoNorma(models.Model):
@ -61,10 +62,10 @@ def texto_upload_path(instance, filename):
class NormaJuridica(models.Model): class NormaJuridica(models.Model):
ESFERA_FEDERACAO_CHOICES, ESTADUAL, FEDERAL, MUNICIPAL = make_choices( ESFERA_FEDERACAO_CHOICES = Choices(
'E', _('Estadual'), ('E', 'estadual', _('Estadual')),
'F', _('Federal'), ('F', 'federal', _('Federal')),
'M', _('Municipal'), ('M', 'municipal', _('Municipal')),
) )
texto_integral = models.FileField( texto_integral = models.FileField(
blank=True, blank=True,

9
parlamentares/models.py

@ -2,8 +2,9 @@ import datetime
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from model_utils import Choices
from sapl.utils import YES_NO_CHOICES, make_choices from sapl.utils import YES_NO_CHOICES
class Legislatura(models.Model): class Legislatura(models.Model):
@ -32,9 +33,9 @@ class Legislatura(models.Model):
class SessaoLegislativa(models.Model): class SessaoLegislativa(models.Model):
TIPO_SESSAO_CHOICES, ORDINARIA, EXTRAORDINARIA = make_choices( TIPO_SESSAO_CHOICES = Choices(
'O', _('Ordinária'), ('O', 'ordinaria', _('Ordinária')),
'E', _('Extraordinária'), ('E', 'extraordinaria', _('Extraordinária')),
) )
legislatura = models.ForeignKey(Legislatura) legislatura = models.ForeignKey(Legislatura)

9
protocoloadm/models.py

@ -2,9 +2,10 @@ from uuid import uuid4
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from model_utils import Choices
from materia.models import Autor, TipoMateriaLegislativa, UnidadeTramitacao from materia.models import Autor, TipoMateriaLegislativa, UnidadeTramitacao
from sapl.utils import YES_NO_CHOICES, make_choices from sapl.utils import YES_NO_CHOICES
class TipoDocumentoAdministrativo(models.Model): class TipoDocumentoAdministrativo(models.Model):
@ -126,9 +127,9 @@ class Protocolo(models.Model):
class StatusTramitacaoAdministrativo(models.Model): class StatusTramitacaoAdministrativo(models.Model):
INDICADOR_CHOICES, FIM, RETORNO = make_choices( INDICADOR_CHOICES = Choices(
'F', _('Fim'), ('F', 'fim', _('Fim')),
'R', _('Retorno'), ('R', 'retorno', _('Retorno')),
) )
sigla = models.CharField(max_length=10, verbose_name=_('Sigla')) sigla = models.CharField(max_length=10, verbose_name=_('Sigla'))

1
requirements/requirements.txt

@ -5,6 +5,7 @@ django-braces
django-compressor django-compressor
django-crispy-forms django-crispy-forms
django-extra-views django-extra-views
django-model-utils
django-sass-processor django-sass-processor
django-vanilla-views django-vanilla-views
django<1.9 django<1.9

14
sapl/test_utils.py

@ -1,16 +1,4 @@
from pytest import mark from .utils import listify
from .utils import listify, make_choices
@mark.parametrize("choice_pairs, result", [
(
['A', 'aaa', 'B', 'bbb'],
[[('A', 'aaa'), ('B', 'bbb')], 'A', 'B']
),
])
def test_make_choices(choice_pairs, result):
assert list(make_choices(*choice_pairs)) == result
def test_listify(): def test_listify():

8
sapl/utils.py

@ -38,14 +38,6 @@ def create_barcode(value):
return data.decode('utf-8') return data.decode('utf-8')
def make_choices(*choice_pairs):
assert len(choice_pairs) % 2 == 0
ipairs = iter(choice_pairs)
choices = list(zip(ipairs, ipairs))
yield choices
for key, value in choices:
yield key
YES_NO_CHOICES = [(True, _('Sim')), (False, _('Não'))] YES_NO_CHOICES = [(True, _('Sim')), (False, _('Não'))]

11
sessao/models.py

@ -1,10 +1,11 @@
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from model_utils import Choices
from materia.models import MateriaLegislativa from materia.models import MateriaLegislativa
from parlamentares.models import (CargoMesa, Legislatura, Parlamentar, from parlamentares.models import (CargoMesa, Legislatura, Parlamentar,
SessaoLegislativa) SessaoLegislativa)
from sapl.utils import YES_NO_CHOICES, make_choices from sapl.utils import YES_NO_CHOICES
class TipoSessaoPlenaria(models.Model): class TipoSessaoPlenaria(models.Model):
@ -92,10 +93,10 @@ class SessaoPlenaria(models.Model):
class AbstractOrdemDia(models.Model): class AbstractOrdemDia(models.Model):
TIPO_VOTACAO_CHOICES, SIMBOLICA, NOMINAL, SECRETA = make_choices( TIPO_VOTACAO_CHOICES = Choices(
1, _('Simbólica'), (1, 'simbolica', (('Simbólica'))),
2, _('Nominal'), (2, 'nominal', (('Nominal'))),
3, _('Secreta'), (3, 'secreta', (('Secreta'))),
) )
sessao_plenaria = models.ForeignKey(SessaoPlenaria) sessao_plenaria = models.ForeignKey(SessaoPlenaria)

Loading…
Cancel
Save