Browse Source

Fix #920

pull/941/head
Eduardo Edson Batista Cordeiro Alves 8 years ago
parent
commit
d0b1d87c4e
  1. 24
      sapl/parlamentares/forms.py
  2. 10
      sapl/parlamentares/views.py

24
sapl/parlamentares/forms.py

@ -5,7 +5,7 @@ from crispy_forms.layout import Fieldset, Layout
from django import forms from django import forms
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group, User from django.contrib.auth.models import Group, User
from django.core.exceptions import ValidationError from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.db import transaction from django.db import transaction
from django.db.models import Q from django.db.models import Q
from django.forms import ModelForm from django.forms import ModelForm
@ -49,6 +49,28 @@ def validar_datas_legislatura(eleicao, inicio, fim, pk=None):
return [True, ''] return [True, '']
class MandatoForm(ModelForm):
class Meta:
model = Mandato
fields = ['legislatura', 'coligacao', 'votos_recebidos',
'data_fim_mandato', 'data_expedicao_diploma',
'tipo_afastamento', 'observacao', 'parlamentar']
widgets = {'parlamentar': forms.HiddenInput()}
def clean(self):
data = self.cleaned_data
try:
mandato = Mandato.objects.get(
parlamentar__pk=self.initial['parlamentar'].pk,
legislatura__pk=data['legislatura'].pk)
except ObjectDoesNotExist:
pass
else:
raise ValidationError('Mandato nesta legislatura já existe.')
return data
class LegislaturaForm(ModelForm): class LegislaturaForm(ModelForm):
class Meta: class Meta:

10
sapl/parlamentares/views.py

@ -14,7 +14,8 @@ from sapl.materia.models import Proposicao, Relatoria
from sapl.parlamentares.apps import AppConfig from sapl.parlamentares.apps import AppConfig
from .forms import (FiliacaoForm, LegislaturaCreateForm, LegislaturaUpdateForm, from .forms import (FiliacaoForm, LegislaturaCreateForm, LegislaturaUpdateForm,
ParlamentarCreateForm, ParlamentarForm, VotanteForm) MandatoForm, ParlamentarCreateForm, ParlamentarForm,
VotanteForm)
from .models import (CargoMesa, Coligacao, ComposicaoColigacao, ComposicaoMesa, from .models import (CargoMesa, Coligacao, ComposicaoColigacao, ComposicaoMesa,
Dependente, Filiacao, Frente, Legislatura, Mandato, Dependente, Filiacao, Frente, Legislatura, Mandato,
NivelInstrucao, Parlamentar, Partido, SessaoLegislativa, NivelInstrucao, Parlamentar, Partido, SessaoLegislativa,
@ -195,6 +196,13 @@ class MandatoCrud(MasterDetailCrud):
class ListView(MasterDetailCrud.ListView): class ListView(MasterDetailCrud.ListView):
ordering = ('-legislatura__numero') ordering = ('-legislatura__numero')
class CreateView(MasterDetailCrud.CreateView):
form_class = MandatoForm
def get_initial(self):
return {'parlamentar': Parlamentar.objects.get(
pk=self.kwargs['pk'])}
class ComposicaoColigacaoCrud(MasterDetailCrud): class ComposicaoColigacaoCrud(MasterDetailCrud):
model = ComposicaoColigacao model = ComposicaoColigacao

Loading…
Cancel
Save