Browse Source

Merge 6241655a6a into 7ef9c967c7

pull/1197/merge
Eliseu Egewarth 9 years ago
committed by GitHub
parent
commit
a891d27c93
  1. 34
      sapl/materia/forms.py

34
sapl/materia/forms.py

@ -823,13 +823,28 @@ class TipoProposicaoForm(ModelForm):
super(TipoProposicaoForm, self).clean() super(TipoProposicaoForm, self).clean()
cd = self.cleaned_data cd = self.cleaned_data
super(TipoProposicaoForm, self).clean()
content_type = cd['content_type'] content_type = cd['content_type']
try:
if 'tipo_conteudo_related' not in cd or not cd[ tipo_conteudo_related = cd['tipo_conteudo_related']
'tipo_conteudo_related']: if not tipo_conteudo_related:
raise ValidationError(
_('Seleção de Tipo não definida'))
except KeyError:
raise ValidationError( raise ValidationError(
_('Seleção de Tipo não definida')) _('Seleção de Tipo não definida'))
tipo = TipoProposicao.objects.filter(
content_type_id=content_type,
object_id=tipo_conteudo_related).first()
if tipo:
raise ValidationError(
_('O %(model)s: %(content_type)s, %(object_id)s já existe.'),
code='invalid',
params={
'model': self._meta.model._meta.verbose_name,
'content_type': content_type.__str__(),
'object_id': tipo.tipo_conteudo_related.__str__()},
)
if not content_type.model_class().objects.filter( if not content_type.model_class().objects.filter(
pk=cd['tipo_conteudo_related']).exists(): pk=cd['tipo_conteudo_related']).exists():
@ -855,6 +870,17 @@ class TipoProposicaoForm(ModelForm):
return super().clean() return super().clean()
def clean_content_type(self):
try:
content_type = self.cleaned_data['content_type']
if not content_type:
raise ValidationError(
_('Definição de Tipo não definida'))
except KeyError:
raise ValidationError(
_('Definição de Tipo não definida'))
return content_type
@transaction.atomic @transaction.atomic
def save(self, commit=False): def save(self, commit=False):

Loading…
Cancel
Save