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(