From fa99dddf2f51402568cf5eed0d55d99002d7d327 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Fri, 29 Apr 2016 15:04:21 -0300 Subject: [PATCH] =?UTF-8?q?Valida=20numera=C3=A7=C3=A3o=20igual?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- materia/forms.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/materia/forms.py b/materia/forms.py index c964e8c72..1b9bf27e6 100644 --- a/materia/forms.py +++ b/materia/forms.py @@ -316,6 +316,7 @@ class NumeracaoForm(ModelForm): 'data_materia'] def clean(self): + if self.errors: return self.errors @@ -331,6 +332,21 @@ class NumeracaoForm(ModelForm): return self.cleaned_data + def save(self, commit=False): + numeracao = super(NumeracaoForm, self).save(commit) + try: + Numeracao.objects.get(materia=numeracao.materia, + tipo_materia=numeracao.tipo_materia, + ano_materia=numeracao.ano_materia, + numero_materia=numeracao.numero_materia) + except ObjectDoesNotExist: + numeracao.save() + else: + msg = _('Essa numeração já existe.') + raise ValidationError(msg) + + return numeracao + class AnexadaForm(ModelForm):