Browse Source

Fix #1793 (#1807)

pull/1811/head
Talitha Pumar 7 years ago
committed by Edward
parent
commit
96bb6d8b56
  1. 28
      sapl/comissoes/forms.py
  2. 6
      sapl/comissoes/views.py

28
sapl/comissoes/forms.py

@ -11,6 +11,33 @@ from sapl.comissoes.models import (Comissao, Composicao, DocumentoAcessorio,
Participacao, Reuniao)
from sapl.parlamentares.models import Legislatura, Mandato, Parlamentar
class ComposicaoForm(forms.ModelForm):
class Meta:
model = Composicao
exclude = []
def clean(self):
cleaned_data = super(ComposicaoForm, self).clean()
if not self.is_valid():
return cleaned_data
periodo = cleaned_data['periodo']
comissao_pk = cleaned_data['comissao'].id
intersecao_periodo = Composicao.objects.filter(
Q(periodo__data_inicio__lte=periodo.data_fim,
periodo__data_fim__gte=periodo.data_fim) |
Q(periodo__data_inicio__gte=periodo.data_inicio,
periodo__data_fim__lte=periodo.data_inicio),
comissao_id=comissao_pk)
if intersecao_periodo:
raise ValidationError('O período informado '
'choca com períodos já '
'cadastrados para esta comissão')
return cleaned_data
class ParticipacaoCreateForm(forms.ModelForm):
@ -219,4 +246,3 @@ class DocumentoAcessorioEditForm(forms.ModelForm):
def __init__(self, user=None, **kwargs):
super(DocumentoAcessorioEditForm, self).__init__(**kwargs)

6
sapl/comissoes/views.py

@ -13,7 +13,7 @@ from sapl.base.models import AppConfig as AppsAppConfig
from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud,
CrudAux, MasterDetailCrud,
PermissionRequiredForAppCrudMixin)
from sapl.comissoes.forms import (ComissaoForm, DocumentoAcessorioCreateForm,
from sapl.comissoes.forms import (ComissaoForm,ComposicaoForm, DocumentoAcessorioCreateForm,
DocumentoAcessorioEditForm, ParticipacaoCreateForm,
ParticipacaoEditForm, ReuniaoForm)
from sapl.materia.models import MateriaLegislativa, Tramitacao
@ -81,6 +81,10 @@ class ComposicaoCrud(MasterDetailCrud):
model_set = 'participacao_set'
public = [RP_LIST, RP_DETAIL, ]
class CreateView(MasterDetailCrud.CreateView):
form_class = ComposicaoForm
class ListView(MasterDetailCrud.ListView):
template_name = "comissoes/composicao_list.html"
paginate_by = None

Loading…
Cancel
Save