From e067abb6e8d765dc47435beb13a1bdbcb0f29d58 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Mon, 7 Mar 2016 17:36:08 -0300 Subject: [PATCH 1/8] Coloca as 'choices' do formulario no models --- base/forms.py | 66 +++++---------------------------------------- base/models.py | 36 +++++++++++++++++++++++-- relatorios/views.py | 2 +- 3 files changed, 42 insertions(+), 62 deletions(-) diff --git a/base/forms.py b/base/forms.py index c0905a944..0c80ec947 100644 --- a/base/forms.py +++ b/base/forms.py @@ -9,68 +9,9 @@ from crispy_layout_mixin import form_actions from .models import CasaLegislativa -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 CasaLegislativaTabelaAuxForm(ModelForm): - uf = forms.ChoiceField(required=True, - label='UF', - choices=[(uf, uf) for uf in ESTADOS.keys()], - widget=forms.Select( - attrs={'class': 'selector'})) - - informacao_geral = forms.CharField(widget=forms.Textarea, - label=_('Informação Geral'), - required=False) - - telefone = forms.CharField(label='Telefone', - required=False, - widget=forms.TextInput( - attrs={'class': 'telefone'})) - - logotipo = forms.ImageField(label='Logotipo', - required=False, - widget=forms.FileInput - ) - - cep = forms.CharField(label='Cep', - required=True, - widget=forms.TextInput( - attrs={'class': 'cep'})) - - fax = forms.CharField(label='Fax', - required=False, - widget=forms.TextInput( - attrs={'class': 'telefone'})) - class Meta: model = CasaLegislativa @@ -88,6 +29,13 @@ class CasaLegislativaTabelaAuxForm(ModelForm): 'email', 'informacao_geral'] + widgets = { + 'uf': forms.Select(attrs={'class': 'selector'}), + 'cep': forms.TextInput(attrs={'class': 'cep'}), + 'telefone': forms.TextInput(attrs={'class': 'telefone'}), + 'fax': forms.TextInput(attrs={'class': 'telefone'}), + } + def __init__(self, *args, **kwargs): row1 = crispy_layout_mixin.to_row( diff --git a/base/models.py b/base/models.py index 9080d75e0..22bd80719 100644 --- a/base/models.py +++ b/base/models.py @@ -10,6 +10,36 @@ 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) @@ -20,7 +50,9 @@ class CasaLegislativa(models.Model): endereco = models.CharField(max_length=100, verbose_name=_('Endereço')) 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, verbose_name=_('UF')) + uf = models.CharField(max_length=100, + choices=[(uf, uf) for uf in ESTADOS.keys()], + verbose_name=_('UF')) telefone = models.CharField( max_length=100, blank=True, verbose_name=_('Telefone')) fax = models.CharField( @@ -33,7 +65,7 @@ class CasaLegislativa(models.Model): max_length=100, blank=True, verbose_name=_('HomePage')) email = models.EmailField( max_length=100, blank=True, verbose_name=_('E-mail')) - informacao_geral = models.CharField( + informacao_geral = models.TextField( max_length=100, blank=True, verbose_name=_('Informação Geral')) diff --git a/relatorios/views.py b/relatorios/views.py index 6a79732aa..97c069316 100644 --- a/relatorios/views.py +++ b/relatorios/views.py @@ -4,7 +4,7 @@ from bs4 import BeautifulSoup from django.http import HttpResponse from django.utils.translation import ugettext_lazy as _ -from base.forms import ESTADOS +from base.models import ESTADOS from base.models import CasaLegislativa from comissoes.models import Comissao from materia.models import (Autor, Autoria, MateriaLegislativa, Numeracao, From 88945249a6a8532a87de75da41d525ebe89dc724 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Mon, 7 Mar 2016 18:05:17 -0300 Subject: [PATCH 2/8] Coloca as 'choices' do formulario no models em Comissoes --- comissoes/forms.py | 21 +++++++++------------ comissoes/models.py | 9 ++++++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/comissoes/forms.py b/comissoes/forms.py index 55ca1d2d9..450a840e6 100644 --- a/comissoes/forms.py +++ b/comissoes/forms.py @@ -124,18 +124,6 @@ class ParticipacaoCadastroForm(ModelForm): empty_label='Selecione', ) - data_designacao = forms.DateField(label=u'Data Designação', - input_formats=['%d/%m/%Y'], - required=True, - widget=forms.DateInput( - format='%d/%m/%Y')) - - data_desligamento = forms.DateField(label=u'Data Desligamento', - input_formats=['%d/%m/%Y'], - required=False, - widget=forms.DateInput( - format='%d/%m/%Y')) - class Meta: model = Participacao fields = ['parlamentar_id', @@ -146,6 +134,15 @@ class ParticipacaoCadastroForm(ModelForm): 'motivo_desligamento', 'observacao'] + widgets = { + '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 6e41e0e01..a80bfb8f1 100644 --- a/comissoes/models.py +++ b/comissoes/models.py @@ -125,9 +125,12 @@ class Participacao(models.Model): # ComposicaoComissao parlamentar = models.ForeignKey(Parlamentar) cargo = models.ForeignKey(CargoComissao) titular = models.BooleanField(verbose_name=_('Titular')) - data_designacao = models.DateField(verbose_name=_('Data Designação')) - data_desligamento = models.DateField( - blank=True, null=True, verbose_name=_('Data Desligamento')) + data_designacao = models.DateField(blank=True, + null=True, + verbose_name=_('Data Designação')) + data_desligamento = models.DateField(blank=True, + null=True, + verbose_name=_('Data Desligamento')) motivo_desligamento = models.CharField( max_length=150, blank=True, From e912bc1adf22a7ac7ce648acd3c31402d6ca7510 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Mon, 7 Mar 2016 18:13:45 -0300 Subject: [PATCH 3/8] =?UTF-8?q?Resolve=20quebra=20na=20tela=20de=20composi?= =?UTF-8?q?=C3=A7ao=20de=20uma=20comissao.=20Esta=20quebra=20ocorria=20ao?= =?UTF-8?q?=20clicar=20em=20um=20parlamentar=20com=20mais=20de=20um=20part?= =?UTF-8?q?ido=20cadastrado?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comissoes/views.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/comissoes/views.py b/comissoes/views.py index 46e57aa85..4ce30707c 100644 --- a/comissoes/views.py +++ b/comissoes/views.py @@ -136,9 +136,11 @@ class ComissaoParlamentarEditView(FormMixin, GenericView): participacao_id = kwargs['id'] 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) + id_parlamentar = id_parlamentar.last().id form = ParticipacaoCadastroForm( - initial={'parlamentar_id': (Filiacao.objects.get( - parlamentar__id=participacao.parlamentar.id).id)}, + initial={'parlamentar_id': id_parlamentar}, instance=participacao) return self.render_to_response({'form': form, 'comissao': comissao, From 1e4058129b6e1e2690ce8a102dc7ce23376a7380 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Mon, 7 Mar 2016 19:55:58 -0300 Subject: [PATCH 4/8] Coloca as 'choices' do formulario no models, em Materias --- materia/forms.py | 130 ++++++++++++++++++++++------------------------ materia/models.py | 17 ++++-- 2 files changed, 76 insertions(+), 71 deletions(-) diff --git a/materia/forms.py b/materia/forms.py index 154aa107f..ac92ba60c 100644 --- a/materia/forms.py +++ b/materia/forms.py @@ -1,7 +1,7 @@ from datetime import date from crispy_forms.helper import FormHelper -from crispy_forms.layout import Column, Fieldset, Layout, Submit +from crispy_forms.layout import Column, Fieldset, Layout from django import forms from django.forms import ModelForm from django.utils.safestring import mark_safe @@ -54,9 +54,6 @@ class HorizontalRadioRenderer(forms.RadioSelect.renderer): class ProposicaoForm(ModelForm): - descricao = forms.CharField( - label='Descrição', required=True, - widget=forms.Textarea()) tipo_materia = forms.ModelChoiceField( label=_('Matéria Vinculada'), @@ -143,12 +140,6 @@ class DocumentoAcessorioForm(ModelForm): empty_label='Selecione', ) - data = forms.DateField(label='Data', - required=False, - input_formats=['%d/%m/%Y'], - widget=forms.TextInput( - attrs={'class': 'dateinput'})) - nome = forms.CharField( label='Nome', required=True) @@ -165,6 +156,12 @@ class DocumentoAcessorioForm(ModelForm): 'data', 'autor', 'ementa'] + widgets = { + 'data': forms.DateInput(attrs={'class': 'dateinput'}) + } + input_formats = { + 'data': ['%d/%m/%Y'], + } def __init__(self, *args, **kwargs): @@ -191,21 +188,6 @@ class DocumentoAcessorioForm(ModelForm): class RelatoriaForm(ModelForm): - data_designacao_relator = forms.DateField( - label=u'Data Designação', - input_formats=['%d/%m/%Y'], - required=False, - widget=forms.DateInput( - format='%d/%m/%Y', - attrs={'class': 'dateinput'})) - - data_destituicao_relator = forms.DateField( - label=u'Data Destituição', - input_formats=['%d/%m/%Y'], - required=False, - widget=forms.DateInput( - format='%d/%m/%Y', - attrs={'class': 'dateinput'})) class Meta: model = Relatoria @@ -215,31 +197,20 @@ class RelatoriaForm(ModelForm): 'data_destituicao_relator', 'tipo_fim_relatoria' ] + widgets = { + 'data_designacao_relator': forms.DateInput(attrs={ + 'class': 'dateinput'}), + '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): - 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 = Tramitacao fields = ['data_tramitacao', @@ -252,6 +223,26 @@ class TramitacaoForm(ModelForm): 'data_fim_prazo', 'texto'] + widgets = { + 'data_tramitacao': forms.DateInput(attrs={ + 'class': 'dateinput'}), + 'data_encaminhamento': forms.DateInput(attrs={ + 'class': 'dateinput'}), + '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( [('data_tramitacao', 6), @@ -384,21 +375,6 @@ class NumeracaoForm(ModelForm): empty_label='Selecione', ) - data_materia = forms.DateField(label='Data', - required=True, - input_formats=['%d/%m/%Y'], - widget=forms.TextInput( - attrs={'class': 'dateinput'})) - - ano_materia = forms.ChoiceField(required=True, - label='Ano', - choices=get_range_anos(), - widget=forms.Select( - attrs={'class': 'selector'})) - - numero_materia = forms.CharField( - label='Número', required=True) - class Meta: model = Numeracao fields = ['tipo_materia', @@ -406,6 +382,14 @@ class NumeracaoForm(ModelForm): 'ano_materia', 'data_materia'] + widgets = { + '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): row1 = crispy_layout_mixin.to_row( @@ -437,7 +421,6 @@ class DespachoInicialForm(ModelForm): more = [] if excluir: more = [Submit('Excluir', 'Excluir')] - self.helper = FormHelper() self.helper.layout = Layout( Fieldset( @@ -466,6 +449,14 @@ class MateriaAnexadaForm(ModelForm): model = Anexada fields = ['tipo', 'numero', 'ano', 'data_anexacao', 'data_desanexacao'] + widgets = { + '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): @@ -492,12 +483,6 @@ class MateriaAnexadaForm(ModelForm): class FormularioSimplificadoForm(ModelForm): - data_apresentacao = forms.DateField(label=u'Data Apresentação', - input_formats=['%d/%m/%Y'], - required=False, - widget=forms.DateInput( - format='%d/%m/%Y')) - class Meta: model = MateriaLegislativa fields = ['tipo', @@ -510,6 +495,15 @@ class FormularioSimplificadoForm(ModelForm): 'ementa', 'texto_original'] exclude = ['anexadas'] + 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 5da4beb89..1f20732e4 100644 --- a/materia/models.py +++ b/materia/models.py @@ -1,3 +1,5 @@ +from datetime import date + from django.db import models from django.utils.translation import ugettext_lazy as _ from model_utils import Choices @@ -300,12 +302,21 @@ 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)] + + class Numeracao(models.Model): materia = models.ForeignKey(MateriaLegislativa) tipo_materia = models.ForeignKey( TipoMateriaLegislativa, verbose_name=_('Tipo de Matéria')) - numero_materia = models.CharField(max_length=5, verbose_name=_('Número')) - ano_materia = models.PositiveSmallIntegerField(verbose_name=_('Ano')) + numero_materia = models.CharField(max_length=5, + verbose_name=_('Número'), + blank=True, + null=True) + ano_materia = models.PositiveSmallIntegerField(verbose_name=_('Ano'), + choices=get_range_anos()) data_materia = models.DateField( blank=True, verbose_name=_('Data')) @@ -430,7 +441,7 @@ class Proposicao(models.Model): null=True, verbose_name=_('Data de Envio')) data_recebimento = models.DateTimeField( blank=True, null=True, verbose_name=_('Data de Incorporação')) - descricao = models.CharField(max_length=100, verbose_name=_('Descrição')) + descricao = models.TextField(max_length=100, verbose_name=_('Descrição')) data_devolucao = models.DateTimeField( blank=True, null=True, verbose_name=_('Data de devolução')) justificativa_devolucao = models.CharField( From b9679a6031987b21f72890743298488103d76614 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Tue, 8 Mar 2016 16:18:27 -0300 Subject: [PATCH 5/8] Coloca as 'choices' do formulario no models, em Parlamentares --- parlamentares/forms.py | 59 ++++++++++-------------------------------- 1 file changed, 14 insertions(+), 45 deletions(-) diff --git a/parlamentares/forms.py b/parlamentares/forms.py index b5b496633..0f016668c 100644 --- a/parlamentares/forms.py +++ b/parlamentares/forms.py @@ -30,51 +30,6 @@ class ParlamentaresForm (ModelForm): ) ) - cpf = forms.CharField(label='C.P.F', - required=False, - widget=forms.TextInput( - attrs={'class': 'cpf'})) - - rg = forms.CharField(label='R.G.', - required=False, - widget=forms.TextInput( - attrs={'class': 'rg'})) - - titulo_eleitor = forms.CharField(label=_('Título de Eleitor'), - required=False, - widget=forms.TextInput( - attrs={'class': 'titulo_eleitor'})) - - telefone = forms.CharField(label='Telefone', - required=False, - widget=forms.TextInput( - attrs={'class': 'telefone'})) - - fax = forms.CharField(label='Fax', - required=False, - widget=forms.TextInput( - attrs={'class': 'telefone'})) - - cep_residencia = forms.CharField(label='CEP', - required=False, - widget=forms.TextInput( - attrs={'class': 'cep'})) - - telefone_residencia = forms.CharField(label='Telefone', - required=False, - widget=forms.TextInput( - attrs={'class': 'telefone'})) - - fax_residencia = forms.CharField(label='Fax', - required=False, - widget=forms.TextInput( - attrs={'class': 'telefone'})) - - fotografia = forms.ImageField(label='Fotografia', - required=False, - widget=forms.FileInput - ) - class Meta: model = Parlamentar fields = ['nome_parlamentar', @@ -102,6 +57,20 @@ class ParlamentaresForm (ModelForm): 'fotografia', 'biografia'] + widgets = { + 'cpf': forms.TextInput(attrs={'class': 'cpf'}), + 'rg': forms.TextInput(attrs={'class': 'rg'}), + 'titulo_eleitor': forms.TextInput(attrs={ + 'class': 'titulo_eleitor'}), + 'telefone': forms.TextInput(attrs={'class': 'telefone'}), + 'fax': forms.TextInput(attrs={'class': 'telefone'}), + 'cep_residencia': forms.TextInput(attrs={'class': 'cep'}), + 'telefone_residencia': forms.TextInput(attrs={ + 'class': 'telefone'}), + 'fax_residencia': forms.TextInput(attrs={'class': 'telefone'}), + 'fotografia': forms.FileInput + } + def __init__(self, *args, **kwargs): row1 = crispy_layout_mixin.to_row( From e6744ed292959d92ce5415fb6f6e545ee2dd8713 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Tue, 8 Mar 2016 16:23:08 -0300 Subject: [PATCH 6/8] Coloca as 'choices' do formulario no models, em Sessao --- sessao/forms.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/sessao/forms.py b/sessao/forms.py index 253f533d9..4b2367e52 100644 --- a/sessao/forms.py +++ b/sessao/forms.py @@ -70,16 +70,6 @@ class VotacaoEditForm(forms.Form): class SessaoForm(ModelForm): - hora_inicio = forms.CharField(label=_('Horário Inicio'), - required=True, - widget=forms.TextInput( - attrs={'class': 'hora'})) - - hora_fim = forms.CharField(label=_('Horário Fim'), - required=True, - widget=forms.TextInput( - attrs={'class': 'hora'})) - class Meta: model = SessaoPlenaria fields = ['numero', @@ -97,6 +87,11 @@ class SessaoForm(ModelForm): 'url_audio', 'url_video'] + widgets = { + 'hora_inicio': forms.TextInput(attrs={'class': 'hora'}), + 'hora_fim': forms.TextInput(attrs={'class': 'hora'}), + } + def __init__(self, *args, **kwargs): row1 = crispy_layout_mixin.to_row( From 7b619e9e465aa3d06279808bbcd6894417f760d8 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Wed, 9 Mar 2016 13:05:19 -0300 Subject: [PATCH 7/8] 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'), + ) From 2fd03e15a005a5055032b0d9e67f99ac3a16d616 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Wed, 9 Mar 2016 13:24:18 -0300 Subject: [PATCH 8/8] Altera models de base, materia e protocoladm --- base/migrations/0010_auto_20160309_1323.py | 25 +++++++++++++++++++ materia/migrations/0022_auto_20160309_1323.py | 25 +++++++++++++++++++ .../migrations/0009_auto_20160309_1323.py | 20 +++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 base/migrations/0010_auto_20160309_1323.py create mode 100644 materia/migrations/0022_auto_20160309_1323.py create mode 100644 protocoloadm/migrations/0009_auto_20160309_1323.py diff --git a/base/migrations/0010_auto_20160309_1323.py b/base/migrations/0010_auto_20160309_1323.py new file mode 100644 index 000000000..d0caee056 --- /dev/null +++ b/base/migrations/0010_auto_20160309_1323.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-03-09 16:23 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0009_auto_20160307_0905'), + ] + + operations = [ + migrations.AlterField( + model_name='casalegislativa', + name='informacao_geral', + field=models.TextField(blank=True, max_length=100, verbose_name='Informação Geral'), + ), + migrations.AlterField( + model_name='casalegislativa', + name='uf', + field=models.CharField(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')], max_length=100, verbose_name='UF'), + ), + ] diff --git a/materia/migrations/0022_auto_20160309_1323.py b/materia/migrations/0022_auto_20160309_1323.py new file mode 100644 index 000000000..23c874dc1 --- /dev/null +++ b/materia/migrations/0022_auto_20160309_1323.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-03-09 16:23 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('materia', '0021_auto_20160307_0905'), + ] + + operations = [ + migrations.AlterField( + model_name='numeracao', + name='ano_materia', + field=models.PositiveSmallIntegerField(choices=[(2016, 2016), (2015, 2015), (2014, 2014), (2013, 2013), (2012, 2012), (2011, 2011), (2010, 2010), (2009, 2009), (2008, 2008), (2007, 2007), (2006, 2006), (2005, 2005), (2004, 2004), (2003, 2003), (2002, 2002), (2001, 2001), (2000, 2000), (1999, 1999), (1998, 1998), (1997, 1997), (1996, 1996), (1995, 1995), (1994, 1994), (1993, 1993), (1992, 1992), (1991, 1991), (1990, 1990), (1989, 1989), (1988, 1988), (1987, 1987), (1986, 1986), (1985, 1985), (1984, 1984), (1983, 1983), (1982, 1982), (1981, 1981), (1980, 1980), (1979, 1979), (1978, 1978), (1977, 1977), (1976, 1976), (1975, 1975), (1974, 1974), (1973, 1973), (1972, 1972), (1971, 1971), (1970, 1970), (1969, 1969), (1968, 1968), (1967, 1967), (1966, 1966), (1965, 1965), (1964, 1964), (1963, 1963), (1962, 1962), (1961, 1961), (1960, 1960), (1959, 1959), (1958, 1958), (1957, 1957), (1956, 1956), (1955, 1955), (1954, 1954), (1953, 1953), (1952, 1952), (1951, 1951), (1950, 1950), (1949, 1949), (1948, 1948), (1947, 1947), (1946, 1946), (1945, 1945), (1944, 1944), (1943, 1943), (1942, 1942), (1941, 1941), (1940, 1940), (1939, 1939), (1938, 1938), (1937, 1937), (1936, 1936), (1935, 1935), (1934, 1934), (1933, 1933), (1932, 1932), (1931, 1931), (1930, 1930), (1929, 1929), (1928, 1928), (1927, 1927), (1926, 1926), (1925, 1925), (1924, 1924), (1923, 1923), (1922, 1922), (1921, 1921), (1920, 1920), (1919, 1919), (1918, 1918), (1917, 1917), (1916, 1916), (1915, 1915), (1914, 1914), (1913, 1913), (1912, 1912), (1911, 1911), (1910, 1910), (1909, 1909), (1908, 1908), (1907, 1907), (1906, 1906), (1905, 1905), (1904, 1904), (1903, 1903), (1902, 1902), (1901, 1901), (1900, 1900), (1899, 1899), (1898, 1898), (1897, 1897), (1896, 1896), (1895, 1895), (1894, 1894), (1893, 1893), (1892, 1892), (1891, 1891), (1890, 1890)], verbose_name='Ano'), + ), + migrations.AlterField( + model_name='proposicao', + name='descricao', + field=models.TextField(max_length=100, verbose_name='Descrição'), + ), + ] diff --git a/protocoloadm/migrations/0009_auto_20160309_1323.py b/protocoloadm/migrations/0009_auto_20160309_1323.py new file mode 100644 index 000000000..aa7760eca --- /dev/null +++ b/protocoloadm/migrations/0009_auto_20160309_1323.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-03-09 16:23 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('protocoloadm', '0008_auto_20160308_1436'), + ] + + operations = [ + migrations.AlterField( + model_name='protocolo', + name='numero', + field=models.PositiveIntegerField(verbose_name='Número de Protocolo'), + ), + ]