Browse Source

Fix #1776 (#1788)

* Fix #1776

Co-authored-by: Mariana Mendes <mare.s.mendes@gmail.com>

* Fix #1776

Co-authored-by: João Pedro Sconetto <sconetto.joao@gmail.com>
pull/1795/head
Mariana Mendes 7 years ago
committed by Edward
parent
commit
82471d01e3
  1. 16
      sapl/comissoes/forms.py

16
sapl/comissoes/forms.py

@ -18,6 +18,7 @@ class ParticipacaoCreateForm(forms.ModelForm):
class Meta:
model = Participacao
fields = '__all__'
exclude = ['composicao']
def __init__(self, user=None, **kwargs):
@ -51,6 +52,21 @@ class ParticipacaoCreateForm(forms.ModelForm):
qs = Parlamentar.objects.filter(id__in=ids)
self.fields['parlamentar'].queryset = qs
def clean(self):
cleaned_data = super(ParticipacaoCreateForm, self).clean()
if not self.is_valid():
return cleaned_data
composicao = Composicao.objects.get(id=self.initial['parent_pk'])
cargos_unicos = [c.cargo.nome for c in composicao.participacao_set.filter(cargo__unico=True)]
if cleaned_data['cargo'].nome in cargos_unicos:
msg = _('Este cargo é único para esta Comissão.')
raise ValidationError(msg)
def create_participacao(self):
composicao = Composicao.objects.get(id=self.initial['parent_pk'])
data_inicio_comissao = composicao.periodo.data_inicio

Loading…
Cancel
Save