From df31e1d6d8751b9845b5d5a68d7b39ec96833752 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Mon, 2 May 2016 11:38:17 -0300 Subject: [PATCH] =?UTF-8?q?Valida=20ultima=20tramita=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- materia/forms.py | 21 ++++++++++++++----- materia/migrations/0031_auto_20160502_1131.py | 20 ++++++++++++++++++ materia/models.py | 3 ++- materia/views.py | 16 +++++++++++++- 4 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 materia/migrations/0031_auto_20160502_1131.py diff --git a/materia/forms.py b/materia/forms.py index 5918bcf31..3793d0d5b 100644 --- a/materia/forms.py +++ b/materia/forms.py @@ -191,11 +191,6 @@ class RelatoriaForm(ModelForm): class TramitacaoForm(ModelForm): - urgente = forms.ChoiceField(required=False, - label='Tramitando', - choices=[(True, 'Sim'), (False, 'Não')], - widget=forms.Select( - attrs={'class': 'selector'})) class Meta: model = Tramitacao @@ -209,6 +204,22 @@ class TramitacaoForm(ModelForm): 'data_fim_prazo', 'texto'] + def clean(self): + if self.errors: + return self.errors + + ultima_tramitacao = Tramitacao.objects.filter( + materia_id=self.instance.materia.id).last() + + if ultima_tramitacao: + destino = ultima_tramitacao.unidade_tramitacao_destino + if (destino != self.cleaned_data['unidade_tramitacao_local']): + msg = _('A origem da nova tramitação deve ser igual ao ' + 'destino da última adicionada!') + raise ValidationError(msg) + + return self.cleaned_data + class LegislacaoCitadaForm(ModelForm): diff --git a/materia/migrations/0031_auto_20160502_1131.py b/materia/migrations/0031_auto_20160502_1131.py new file mode 100644 index 000000000..a51221080 --- /dev/null +++ b/materia/migrations/0031_auto_20160502_1131.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.5 on 2016-05-02 14:31 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('materia', '0030_auto_20160429_1349'), + ] + + operations = [ + migrations.AlterField( + model_name='tramitacao', + name='urgente', + field=models.BooleanField(choices=[(True, 'Sim'), (False, 'Não')], verbose_name='Urgente ?'), + ), + ] diff --git a/materia/models.py b/materia/models.py index 0eb2037c8..b50c48afd 100644 --- a/materia/models.py +++ b/materia/models.py @@ -546,7 +546,8 @@ class Tramitacao(models.Model): UnidadeTramitacao, related_name='tramitacoes_destino', verbose_name=_('Unidade Destino')) - urgente = models.BooleanField(verbose_name=_('Urgente ?')) + urgente = models.BooleanField(verbose_name=_('Urgente ?'), + choices=YES_NO_CHOICES) turno = models.CharField( max_length=1, blank=True, verbose_name=_('Turno'), choices=TURNO_CHOICES) diff --git a/materia/views.py b/materia/views.py index 4b05609a9..d93d8d4ff 100644 --- a/materia/views.py +++ b/materia/views.py @@ -55,7 +55,21 @@ ProposicaoCrud = Crud.build(Proposicao, '') StatusTramitacaoCrud = Crud.build(StatusTramitacao, 'status_tramitacao') UnidadeTramitacaoCrud = Crud.build(UnidadeTramitacao, 'unidade_tramitacao') -TramitacaoCrud = MasterDetailCrud.build(Tramitacao, 'materia', '') + +class TramitacaoCrud(MasterDetailCrud): + model = Tramitacao + parent_field = 'materia' + help_path = '' + + class BaseMixin(MasterDetailCrud.BaseMixin): + list_field_names = ['data_tramitacao', 'unidade_tramitacao_local', + 'unidade_tramitacao_destino', 'status'] + + class CreateView(MasterDetailCrud.CreateView): + form_class = TramitacaoForm + + class UpdateView(MasterDetailCrud.UpdateView): + form_class = TramitacaoForm class AutoriaCrud(MasterDetailCrud):