Skip to content

Commit

Permalink
Fix #1793 (#1807)
Browse files Browse the repository at this point in the history
  • Loading branch information
tapumar committed Mar 27, 2018
1 parent c84b1c2 commit a0de0d7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
28 changes: 27 additions & 1 deletion sapl/comissoes/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,33 @@
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):

Expand Down Expand Up @@ -219,4 +246,3 @@ class Meta:

def __init__(self, user=None, **kwargs):
super(DocumentoAcessorioEditForm, self).__init__(**kwargs)

12 changes: 8 additions & 4 deletions sapl/comissoes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud,
CrudAux, MasterDetailCrud,
PermissionRequiredForAppCrudMixin)
from sapl.comissoes.forms import (ComissaoForm, DocumentoAcessorioCreateForm,
DocumentoAcessorioEditForm, ParticipacaoCreateForm,
from sapl.comissoes.forms import (ComissaoForm,ComposicaoForm, DocumentoAcessorioCreateForm,
DocumentoAcessorioEditForm, ParticipacaoCreateForm,
ParticipacaoEditForm, ReuniaoForm)
from sapl.materia.models import MateriaLegislativa, Tramitacao

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -176,7 +180,7 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

reuniao_pk = self.take_reuniao_pk()

if reuniao_pk == 0:
ultima_reuniao = list(context['reuniao_list'])
if len(ultima_reuniao) > 0:
Expand Down Expand Up @@ -235,4 +239,4 @@ def delete(self, *args, **kwargs):
obj.delete()
return HttpResponseRedirect(
reverse('sapl.comissoes:reuniao_detail',
kwargs={'pk': obj.reuniao.pk}))
kwargs={'pk': obj.reuniao.pk}))

0 comments on commit a0de0d7

Please sign in to comment.