Browse Source

Fix qa

pull/440/head
Eduardo Edson Batista Cordeiro Alves 9 years ago
parent
commit
bdbafc86cf
  1. 26
      materia/forms.py
  2. 4
      materia/tests/test_materia.py
  3. 8
      materia/tests/test_materia_urls.py
  4. 33
      materia/views.py

26
materia/forms.py

@ -1,13 +1,14 @@
from datetime import datetime
import django_filters
from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Button, Column, Fieldset, Layout, Submit
from crispy_forms.layout import HTML, Button, Column, Fieldset, Layout
from django import forms
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.db import models
from django.db.models import Max
from django.forms import ModelForm
from django.utils.translation import ugettext_lazy as _
from datetime import datetime
import crispy_layout_mixin
import sapl
@ -61,7 +62,6 @@ class ProposicaoForm(ModelForm):
def clean(self):
cleaned_data = self.cleaned_data
if cleaned_data['tipo'].descricao == 'Parecer':
try:
materia = MateriaLegislativa.objects.get(
@ -165,26 +165,6 @@ class RelatoriaForm(ModelForm):
return cleaned_data
class Meta:
model = Relatoria
fields = ['data_designacao_relator', 'comissao', 'parlamentar',
'data_destituicao_relator', 'tipo_fim_relatoria']
widgets = {'comissao': forms.Select(attrs={'disabled': 'disabled'})}
def clean(self):
cleaned_data = self.cleaned_data
try:
comissao = Comissao.objects.get(id=self.initial['comissao'])
except ObjectDoesNotExist:
msg = _('A localização atual deve ser uma comissão.')
raise ValidationError(msg)
else:
cleaned_data['comissao'] = comissao
return cleaned_data
class TramitacaoForm(ModelForm):

4
materia/tests/test_materia.py

@ -416,7 +416,7 @@ def test_form_errors_relatoria(client):
@pytest.mark.django_db(transaction=False)
def test_proposicao_submit(client):
response = client.post(reverse('materia:adicionar_proposicao'),
response = client.post(reverse('materia:proposicao_create'),
{'tipo': mommy.make(TipoProposicao, pk=3).pk,
'descricao': 'Teste proposição',
'salvar': 'salvar'},
@ -432,7 +432,7 @@ def test_proposicao_submit(client):
@pytest.mark.django_db(transaction=False)
def test_form_errors_proposicao(client):
response = client.post(reverse('materia:adicionar_proposicao'),
response = client.post(reverse('materia:proposicao_create'),
{'salvar': 'salvar'},
follow=True)

8
materia/tests/test_materia_urls.py

@ -9,11 +9,11 @@ from django.core.urlresolvers import reverse
('materia:tramitacao_update',
{'pk': '8'},
'/materia/tramitacao/8/edit'),
('materia:adicionar_proposicao', {}, '/materia/proposicao'),
('materia:editar_proposicao',
('materia:proposicao_create', {}, '/proposicao/create'),
('materia:proposicao_update',
{'pk': '3'},
'/materia/proposicao/3/edit'),
('materia:list_proposicao', {}, '/materia/proposicao_list'),
'/proposicao/3/edit'),
('materia:proposicao_list', {}, '/proposicao/'),
])
def test_reverse(test_input, kwargs, expected):
assert reverse(test_input, kwargs=kwargs) == expected

33
materia/views.py

@ -1,4 +1,3 @@
import os
from datetime import datetime
from random import choice
from string import ascii_letters, digits
@ -11,10 +10,9 @@ from django.core.exceptions import ObjectDoesNotExist
from django.core.mail import send_mail
from django.core.urlresolvers import reverse
from django.http.response import HttpResponseRedirect
from django.shortcuts import redirect
from django.template import Context, loader
from django.utils.translation import ugettext_lazy as _
from django.views.generic import CreateView, ListView, TemplateView, UpdateView
from django.views.generic import CreateView, TemplateView, UpdateView
from django_filters.views import FilterView
import crispy_layout_mixin
@ -164,35 +162,6 @@ class RelatoriaCrud(MasterDetailCrud):
form_class = RelatoriaForm
class RelatoriaCrud(MasterDetailCrud):
model = Relatoria
parent_field = 'materia'
help_path = ''
class CreateView(MasterDetailCrud.CreateView):
form_class = RelatoriaForm
def get_initial(self):
materia = MateriaLegislativa.objects.get(id=self.kwargs['pk'])
loc_atual = Tramitacao.objects.filter(
materia=materia).last()
if loc_atual is None:
localizacao = 0
else:
comissao = loc_atual.unidade_tramitacao_destino.comissao
if comissao:
localizacao = comissao.pk
else:
localizacao = 0
return {'comissao': localizacao}
class UpdateView(MasterDetailCrud.UpdateView):
form_class = RelatoriaForm
class TramitacaoCrud(MasterDetailCrud):
model = Tramitacao
parent_field = 'materia'

Loading…
Cancel
Save