|
|
|
@ -1436,11 +1436,9 @@ class PartidoForm(FileFieldCheckMixin, ModelForm): |
|
|
|
|
|
|
|
class PartidoUpdateForm(PartidoForm): |
|
|
|
|
|
|
|
opcoes = (('nao','Não'), |
|
|
|
('sim','Sim') |
|
|
|
) |
|
|
|
opcoes = YES_NO_CHOICES |
|
|
|
|
|
|
|
historico = forms.ChoiceField(initial='nao', choices=opcoes) |
|
|
|
historico = forms.ChoiceField(initial=False, choices=opcoes) |
|
|
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
@ -1475,7 +1473,7 @@ class PartidoUpdateForm(PartidoForm): |
|
|
|
super(PartidoUpdateForm,self).clean() |
|
|
|
cleaned_data = self.cleaned_data |
|
|
|
|
|
|
|
is_historico = cleaned_data['historico'] == 'sim' |
|
|
|
is_historico = (cleaned_data['historico'] == 'True') |
|
|
|
|
|
|
|
if is_historico: |
|
|
|
if not cleaned_data['data_criacao'] or not cleaned_data['data_extincao']: |
|
|
|
@ -1485,7 +1483,6 @@ class PartidoUpdateForm(PartidoForm): |
|
|
|
if self.instance.data_extincao and self.instance.data_extincao < cleaned_data['data_extincao']: |
|
|
|
raise ValidationError("Data de fim de historico deve ser anterior a data de extinção do partido.") |
|
|
|
|
|
|
|
|
|
|
|
if self.instance.pk: |
|
|
|
partido = Partido.objects.get(pk=self.instance.pk) |
|
|
|
historico = HistoricoPartido.objects.filter(partido=partido).order_by('-inicio_historico') |
|
|
|
@ -1500,11 +1497,13 @@ class PartidoUpdateForm(PartidoForm): |
|
|
|
|
|
|
|
def save(self,commit=False): |
|
|
|
partido = self.instance |
|
|
|
is_historico = self.cleaned_data['historico'] |
|
|
|
|
|
|
|
if is_historico == "nao": |
|
|
|
cleaned_data = self.cleaned_data |
|
|
|
is_historico = (cleaned_data['historico'] == 'True') |
|
|
|
|
|
|
|
if not is_historico: |
|
|
|
partido.save(commit) |
|
|
|
elif is_historico == "sim": |
|
|
|
else: |
|
|
|
sigla = self.cleaned_data['sigla'] |
|
|
|
nome = self.cleaned_data['nome'] |
|
|
|
inicio_historico = self.cleaned_data['data_criacao'] |
|
|
|
@ -1557,3 +1556,4 @@ class RelatorioHistoricoTramitacaoAdmFilterSet(django_filters.FilterSet): |
|
|
|
row1, row2, row3, |
|
|
|
form_actions(label='Pesquisar')) |
|
|
|
) |
|
|
|
|
|
|
|
|