From 7b619e9e465aa3d06279808bbcd6894417f760d8 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Wed, 9 Mar 2016 13:05:19 -0300 Subject: [PATCH] Resolve as questoes discutidas na revisao --- base/models.py | 33 ++------------------------------- comissoes/forms.py | 4 ---- comissoes/models.py | 4 +--- comissoes/views.py | 2 +- materia/forms.py | 31 ------------------------------- materia/models.py | 10 +++------- parlamentares/models.py | 35 ++--------------------------------- protocoloadm/forms.py | 35 ++++++++++------------------------- relatorios/views.py | 6 ++++-- sapl/utils.py | 31 +++++++++++++++++++++++++++++++ 10 files changed, 54 insertions(+), 137 deletions(-) diff --git a/base/models.py b/base/models.py index 22bd80719..e2f1cddf6 100644 --- a/base/models.py +++ b/base/models.py @@ -1,5 +1,6 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ +from sapl.utils import UF def get_sessao_media_path(instance, subpath, filename): @@ -10,36 +11,6 @@ def get_casa_media_path(instance, filename): return get_sessao_media_path(instance, 'Logotipo', filename) -ESTADOS = {"": "", - "AC": "ACRE", - "AL": "ALAGOAS", - "AM": "AMAZONAS", - "AP": "AMAPÁ", - "BA": "BAHIA", - "CE": "CEARÁ", - "DF": "DISTRITO FEDERAL", - "ES": "ESPíRITO SANTO", - "GO": "GOIÁS", - "MA": "MARANHÃO", - "MG": "MINAS GERAIS", - "MS": "MATO GROSSO DO SUL", - "MT": "MATO GROSSO", - "PA": "PARÁ", - "PB": "PARAÍBA", - "PE": "PERNAMBUCO", - "PI": "PIAUÍ", - "PR": "PARANÁ", - "RJ": "RIO DE JANEIRO", - "RN": "RIO GRANDE DO NORTE", - "RO": "RONDÔNIA", - "RR": "RORAIMA", - "RS": "RIO GRANDE DO SUL", - "SC": "SANTA CATARINA", - "SE": "SERGIPE", - "SP": "SÃO PAULO", - "TO": "TOCANTINS"} - - class CasaLegislativa(models.Model): # TODO ajustar todos os max_length !!!! # cod_casa => id (pk) @@ -51,7 +22,7 @@ class CasaLegislativa(models.Model): cep = models.CharField(max_length=100, verbose_name=_('CEP')) municipio = models.CharField(max_length=100, verbose_name=_('Município')) uf = models.CharField(max_length=100, - choices=[(uf, uf) for uf in ESTADOS.keys()], + choices=UF, verbose_name=_('UF')) telefone = models.CharField( max_length=100, blank=True, verbose_name=_('Telefone')) diff --git a/comissoes/forms.py b/comissoes/forms.py index 450a840e6..0843643d7 100644 --- a/comissoes/forms.py +++ b/comissoes/forms.py @@ -138,10 +138,6 @@ class ParticipacaoCadastroForm(ModelForm): 'data_designacao': forms.DateInput(format='%d/%m/%Y'), 'data_desligamento': forms.DateInput(format='%d/%m/%Y'), } - input_formats = { - 'data_designacao': ['%d/%m/%Y'], - 'data_desligamento': ['%d/%m/%Y'], - } def __init__(self, *args, **kwargs): self.helper = FormHelper() diff --git a/comissoes/models.py b/comissoes/models.py index a80bfb8f1..24c476c44 100644 --- a/comissoes/models.py +++ b/comissoes/models.py @@ -125,9 +125,7 @@ class Participacao(models.Model): # ComposicaoComissao parlamentar = models.ForeignKey(Parlamentar) cargo = models.ForeignKey(CargoComissao) titular = models.BooleanField(verbose_name=_('Titular')) - data_designacao = models.DateField(blank=True, - null=True, - verbose_name=_('Data Designação')) + data_designacao = models.DateField(verbose_name=_('Data Designação')) data_desligamento = models.DateField(blank=True, null=True, verbose_name=_('Data Desligamento')) diff --git a/comissoes/views.py b/comissoes/views.py index 4ce30707c..0da73e5f7 100644 --- a/comissoes/views.py +++ b/comissoes/views.py @@ -137,7 +137,7 @@ class ComissaoParlamentarEditView(FormMixin, GenericView): participacao = Participacao.objects.get(id=participacao_id) comissao = Comissao.objects.get(id=self.kwargs['pk']) id_parlamentar = Filiacao.objects.filter( - parlamentar__id=participacao.parlamentar.id) + parlamentar__id=participacao.parlamentar.id).order_by('data') id_parlamentar = id_parlamentar.last().id form = ParticipacaoCadastroForm( initial={'parlamentar_id': id_parlamentar}, diff --git a/materia/forms.py b/materia/forms.py index ac92ba60c..9c6112d55 100644 --- a/materia/forms.py +++ b/materia/forms.py @@ -159,9 +159,6 @@ class DocumentoAcessorioForm(ModelForm): widgets = { 'data': forms.DateInput(attrs={'class': 'dateinput'}) } - input_formats = { - 'data': ['%d/%m/%Y'], - } def __init__(self, *args, **kwargs): @@ -203,10 +200,6 @@ class RelatoriaForm(ModelForm): 'data_destituicao_relator': forms.DateInput(attrs={ 'class': 'dateinput'}), } - input_formats = { - 'data_designacao_relator': ['%d/%m/%Y'], - 'data_destituicao_relator': ['%d/%m/%Y'], - } class TramitacaoForm(ModelForm): @@ -231,17 +224,6 @@ class TramitacaoForm(ModelForm): 'data_fim_prazo': forms.DateInput(attrs={ 'class': 'dateinput'}), } - input_formats = { - 'data_tramitacao': ['%d/%m/%Y'], - 'data_encaminhamento': ['%d/%m/%Y'], - 'data_fim_prazo': ['%d/%m/%Y'], - } - - formats = { - 'data_tramitacao': '%d/%m/%Y', - 'data_encaminhamento': '%d/%m/%Y', - 'data_fim_prazo': '%d/%m/%Y', - } def __init__(self, *args, **kwargs): row1 = crispy_layout_mixin.to_row( @@ -386,9 +368,6 @@ class NumeracaoForm(ModelForm): 'data_materia': forms.DateInput(attrs={'class': 'dateinput'}), 'ano_materia': forms.Select(attrs={'class': 'selector'}), } - input_formats = { - 'data_materia': ['%d/%m/%Y'], - } def __init__(self, *args, **kwargs): @@ -453,10 +432,6 @@ class MateriaAnexadaForm(ModelForm): 'data_anexacao': forms.DateInput(attrs={'class': 'dateinput'}), 'data_desanexacao': forms.DateInput(attrs={'class': 'dateinput'}), } - input_formats = { - 'data_anexacao': ['%d/%m/%Y'], - 'data_desanexacao': ['%d/%m/%Y'], - } def __init__(self, excluir=False, *args, **kwargs): @@ -498,12 +473,6 @@ class FormularioSimplificadoForm(ModelForm): widgets = { 'data_apresentacao': forms.DateInput(attrs={'class': 'dateinput'}), } - input_formats = { - 'data_apresentacao': ['%d/%m/%Y'], - } - formats = { - 'data_apresentacao': '%d/%m/%Y' - } def __init__(self, *args, **kwargs): diff --git a/materia/models.py b/materia/models.py index 1f20732e4..bf3fabd0e 100644 --- a/materia/models.py +++ b/materia/models.py @@ -302,9 +302,7 @@ class MateriaAssunto(models.Model): 'materia': self.materia, 'assunto': self.assunto} -def get_range_anos(): - return [('', 'Selecione')] \ - + [(year, year) for year in range(date.today().year, 1960, -1)] +RANGE_ANOS = [(year, year) for year in range(date.today().year, 1889, -1)] class Numeracao(models.Model): @@ -312,11 +310,9 @@ class Numeracao(models.Model): tipo_materia = models.ForeignKey( TipoMateriaLegislativa, verbose_name=_('Tipo de Matéria')) numero_materia = models.CharField(max_length=5, - verbose_name=_('Número'), - blank=True, - null=True) + verbose_name=_('Número')) ano_materia = models.PositiveSmallIntegerField(verbose_name=_('Ano'), - choices=get_range_anos()) + choices=RANGE_ANOS) data_materia = models.DateField( blank=True, verbose_name=_('Data')) diff --git a/parlamentares/models.py b/parlamentares/models.py index 910d47f25..ac31e0133 100644 --- a/parlamentares/models.py +++ b/parlamentares/models.py @@ -4,7 +4,7 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ from model_utils import Choices -from sapl.utils import YES_NO_CHOICES +from sapl.utils import YES_NO_CHOICES, UF class Legislatura(models.Model): @@ -119,40 +119,9 @@ class Municipio(models.Model): # Localidade ('EX', 'Exterior'), ) - UF_CHOICES = ( - ('AC', 'Acre'), - ('AL', 'Alagoas'), - ('AP', 'Amapá'), - ('AM', 'Amazonas'), - ('BA', 'Bahia'), - ('CE', 'Ceará'), - ('DF', 'Distrito Federal'), - ('ES', 'Espírito Santo'), - ('GO', 'Goiás'), - ('MA', 'Maranhão'), - ('MT', 'Mato Grosso'), - ('MS', 'Mato Grosso do Sul'), - ('MG', 'Minas Gerais'), - ('PR', 'Paraná'), - ('PB', 'Paraíba'), - ('PA', 'Pará'), - ('PE', 'Pernambuco'), - ('PI', 'Piauí'), - ('RJ', 'Rio de Janeiro'), - ('RN', 'Rio Grande do Norte'), - ('RS', 'Rio Grande do Sul'), - ('RO', 'Rondônia'), - ('RR', 'Roraima'), - ('SC', 'Santa Catarina'), - ('SE', 'Sergipe'), - ('SP', 'São Paulo'), - ('TO', 'Tocantins'), - ('EX', 'Exterior'), - ) - nome = models.CharField(max_length=50, blank=True) uf = models.CharField( - max_length=2, blank=True, choices=UF_CHOICES) + max_length=2, blank=True, choices=UF) regiao = models.CharField( max_length=2, blank=True, choices=REGIAO_CHOICES) diff --git a/protocoloadm/forms.py b/protocoloadm/forms.py index fd1a9dc16..338e48e82 100644 --- a/protocoloadm/forms.py +++ b/protocoloadm/forms.py @@ -400,10 +400,6 @@ class ProposicaoSimpleForm(forms.Form): class DocumentoAcessorioAdministrativoForm(ModelForm): - data = forms.DateField(label=u'Data', input_formats=['%d/%m/%Y'], - required=False, - widget=forms.DateInput(format='%d/%m/%Y')) - class Meta: model = DocumentoAcessorioAdministrativo fields = ['tipo', @@ -413,6 +409,10 @@ class DocumentoAcessorioAdministrativoForm(ModelForm): 'arquivo', 'assunto'] + widgets = { + 'data': forms.DateInput(format='%d/%m/%Y') + } + def __init__(self, excluir=False, *args, **kwargs): row1 = crispy_layout_mixin.to_row( @@ -444,27 +444,6 @@ class DocumentoAcessorioAdministrativoForm(ModelForm): class TramitacaoAdmForm(ModelForm): - data_tramitacao = forms.DateField(label=u'Data Tramitação', - input_formats=['%d/%m/%Y'], - required=False, - widget=forms.DateInput( - format='%d/%m/%Y', - attrs={'class': 'dateinput'})) - - data_encaminhamento = forms.DateField(label=u'Data Encaminhamento', - input_formats=['%d/%m/%Y'], - required=False, - widget=forms.DateInput( - format='%d/%m/%Y', - attrs={'class': 'dateinput'})) - - data_fim_prazo = forms.DateField(label=u'Data Fim Prazo', - input_formats=['%d/%m/%Y'], - required=False, - widget=forms.DateInput( - format='%d/%m/%Y', - attrs={'class': 'dateinput'})) - class Meta: model = TramitacaoAdministrativo fields = ['data_tramitacao', @@ -477,6 +456,12 @@ class TramitacaoAdmForm(ModelForm): 'documento', ] + widgets = { + 'data_tramitacao': forms.DateInput(format='%d/%m/%Y'), + 'data_encaminhamento': forms.DateInput(format='%d/%m/%Y'), + 'data_fim_prazo': forms.DateInput(format='%d/%m/%Y'), + } + def __init__(self, *args, **kwargs): self.helper = FormHelper() self.helper.layout = Layout( diff --git a/relatorios/views.py b/relatorios/views.py index 97c069316..fef8bb19f 100644 --- a/relatorios/views.py +++ b/relatorios/views.py @@ -4,7 +4,6 @@ from bs4 import BeautifulSoup from django.http import HttpResponse from django.utils.translation import ugettext_lazy as _ -from base.models import ESTADOS from base.models import CasaLegislativa from comissoes.models import Comissao from materia.models import (Autor, Autoria, MateriaLegislativa, Numeracao, @@ -13,6 +12,9 @@ from parlamentares.models import (CargoMesa, ComposicaoMesa, Filiacao, Parlamentar) from protocoloadm.models import (DocumentoAdministrativo, Protocolo, TramitacaoAdministrativo) + +from sapl.utils import UF + from sessao.models import (ExpedienteMateria, ExpedienteSessao, Orador, OradorExpediente, OrdemDia, PresencaOrdemDia, RegistroVotacao, SessaoPlenaria, @@ -42,7 +44,7 @@ def get_cabecalho(casa): cabecalho = {} cabecalho["nom_casa"] = casa.nome # FIXME i18n - cabecalho["nom_estado"] = "Estado de " + ESTADOS[casa.uf.upper()] + cabecalho["nom_estado"] = "Estado de " + UF[casa.uf.upper()] return cabecalho diff --git a/sapl/utils.py b/sapl/utils.py index ce166c4f0..189372479 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -64,3 +64,34 @@ def listify(function): def f(*args, **kwargs): return list(function(*args, **kwargs)) return f + +UF = ( + ('AC', 'Acre'), + ('AL', 'Alagoas'), + ('AP', 'Amapá'), + ('AM', 'Amazonas'), + ('BA', 'Bahia'), + ('CE', 'Ceará'), + ('DF', 'Distrito Federal'), + ('ES', 'Espírito Santo'), + ('GO', 'Goiás'), + ('MA', 'Maranhão'), + ('MT', 'Mato Grosso'), + ('MS', 'Mato Grosso do Sul'), + ('MG', 'Minas Gerais'), + ('PR', 'Paraná'), + ('PB', 'Paraíba'), + ('PA', 'Pará'), + ('PE', 'Pernambuco'), + ('PI', 'Piauí'), + ('RJ', 'Rio de Janeiro'), + ('RN', 'Rio Grande do Norte'), + ('RS', 'Rio Grande do Sul'), + ('RO', 'Rondônia'), + ('RR', 'Roraima'), + ('SC', 'Santa Catarina'), + ('SE', 'Sergipe'), + ('SP', 'São Paulo'), + ('TO', 'Tocantins'), + ('EX', 'Exterior'), + )