From fe02a0910c87e92f037704d9d74952575ccba1cb Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Mon, 11 Apr 2016 11:53:12 -0300 Subject: [PATCH 1/5] Create e List funcionando com CRUD --- norma/forms.py | 87 +++++----------- norma/layouts.yaml | 9 +- norma/urls.py | 13 +-- norma/views.py | 111 +++++++++++---------- templates/norma/list_pesquisa.html | 4 +- templates/norma/normajuridica_detail.html | 28 ------ templates/norma/normajuridica_incluir.html | 3 - templates/norma/normajuridica_list.html | 36 ------- templates/norma/pesquisa.html | 16 ++- 9 files changed, 111 insertions(+), 196 deletions(-) delete mode 100644 templates/norma/normajuridica_detail.html delete mode 100644 templates/norma/normajuridica_incluir.html delete mode 100644 templates/norma/normajuridica_list.html diff --git a/norma/forms.py b/norma/forms.py index 866c48ba8..baa01e8bb 100644 --- a/norma/forms.py +++ b/norma/forms.py @@ -1,3 +1,5 @@ +from datetime import datetime + from crispy_forms.helper import FormHelper from crispy_forms.layout import Fieldset, Layout from django import forms @@ -94,23 +96,20 @@ class NormaJuridicaForm(ModelForm): # Campos de MateriaLegislativa tipo_materia = forms.ModelChoiceField( - label='Matéria Legislativa', + label='Matéria', required=False, queryset=TipoMateriaLegislativa.objects.all(), empty_label='Selecione' ) - numero_materia = forms.CharField(label='Número', - required=False) - ano_materia = forms.ChoiceField(label='Ano', - required=False, - choices=RANGE_ANOS) - - def clean_texto_integral(self): - texto_integral = self.cleaned_data.get('texto_integral', False) - if texto_integral: - if texto_integral.size > MAX_DOC_UPLOAD_SIZE: - raise ValidationError("Arquivo muito grande. ( > 5mb )") - return texto_integral + numero_materia = forms.CharField( + label='Número Matéria', + required=False + ) + ano_materia = forms.ChoiceField( + label='Ano Matéria', + required=False, + choices=RANGE_ANOS, + ) class Meta: model = NormaJuridica @@ -130,55 +129,21 @@ class NormaJuridicaForm(ModelForm): 'ementa', 'indexacao', 'observacao', - 'texto_integral', - ] + 'texto_integral'] - def clean(self): - data = super(NormaJuridicaForm, self).clean() + def save(self, commit=False): + norma = super(NormaJuridicaForm, self).save(commit) + norma.timestamp = datetime.now() - if self.cleaned_data['tipo_materia']: - try: - MateriaLegislativa.objects.get( - tipo=self.cleaned_data['tipo_materia'], - numero=self.cleaned_data['numero_materia'], - ano=self.cleaned_data['ano_materia']) - except ObjectDoesNotExist: - msg = 'Matéria adicionada não existe!' - raise forms.ValidationError(msg) + if ('tipo_materia' and + 'numero_materia' and + 'ano_materia' in self.cleaned_data): - return data - - def __init__(self, *args, **kwargs): - - row1 = crispy_layout_mixin.to_row( - [('tipo', 4), ('numero', 4), ('ano', 4)]) - - row2 = crispy_layout_mixin.to_row( - [('data', 4), ('esfera_federacao', 4), ('complemento', 4)]) + materia = MateriaLegislativa.objects.get( + tipo_id=self.cleaned_data['tipo_materia'], + numero=self.cleaned_data['numero_materia'], + ano=self.cleaned_data['ano_materia']) + norma.materia = materia - row3 = crispy_layout_mixin.to_row( - [('tipo_materia', 4), ('numero_materia', 4), ('ano_materia', 4)]) - - row4 = crispy_layout_mixin.to_row( - [('data_publicacao', 3), ('veiculo_publicacao', 3), - ('pagina_inicio_publicacao', 3), ('pagina_fim_publicacao', 3)]) - - row5 = crispy_layout_mixin.to_row( - [('texto_integral', 12)]) - - row6 = crispy_layout_mixin.to_row( - [('ementa', 12)]) - - row7 = crispy_layout_mixin.to_row( - [('indexacao', 12)]) - - row8 = crispy_layout_mixin.to_row( - [('observacao', 12)]) - - self.helper = FormHelper() - self.helper.layout = Layout( - Fieldset('Identificação Básica', - row1, row2, row3, row4, row5, row6, row7, row8), - form_actions() - ) - super(NormaJuridicaForm, self).__init__(*args, **kwargs) + norma.save() + return norma diff --git a/norma/layouts.yaml b/norma/layouts.yaml index cde1cf517..038a37951 100644 --- a/norma/layouts.yaml +++ b/norma/layouts.yaml @@ -11,18 +11,13 @@ NormaJuridica: Identificação Básica: - tipo numero ano - data esfera_federacao complemento - - tip_id_basica_FIXME num_ident_basica_FIXME ano_ident_basica_FIXME + - tipo_materia numero_materia ano_materia - data_publicacao veiculo_publicacao pagina_inicio_publicacao pagina_fim_publicacao - - file_FIXME tip_situacao_norma_FIXME + - texto_integral - ementa - indexacao - observacao -NormaJuridica: - Identificação Básica: - - tipo:5 numero:2 ano:2 data - - ementa - LegislacaoCitada: Legislação Citada: - tip_norma_FIXME num_norma_FIXME ano_norma_FIXME diff --git a/norma/urls.py b/norma/urls.py index 199888813..34d5083af 100644 --- a/norma/urls.py +++ b/norma/urls.py @@ -1,8 +1,9 @@ from django.conf.urls import include, url -from norma.views import (AssuntoNormaCrud, NormaEditView, NormaIncluirView, - NormaPesquisaView, NormaTaView, NormaTemporarioCrud, - PesquisaNormaListView, TipoNormaCrud) +from norma.views import (AssuntoNormaCrud, NormaCrud, + NormaPesquisaView, NormaTaView, + NormaTemporarioCrud, PesquisaNormaListView, + TipoNormaCrud) from .apps import AppConfig @@ -24,14 +25,10 @@ norma_url_patterns = NormaTemporarioCrud.get_urls() + [ ] urlpatterns = [ - url(r'^norma/', include(norma_url_patterns)), + url(r'^norma/', include(NormaCrud.get_urls())), url(r'^sistema/norma/tipo/', include(TipoNormaCrud.get_urls())), url(r'^sistema/norma/assunto/', include(AssuntoNormaCrud.get_urls())), - - url(r'^norma/incluir$', NormaIncluirView.as_view(), name='norma_incluir'), - url(r'^norma/(?P[0-9]+)/editar$', - NormaEditView.as_view(), name='norma_editar'), url(r'^norma/pesquisa$', NormaPesquisaView.as_view(), name='norma_pesquisa'), url(r'^norma/pesquisa-resultado$', diff --git a/norma/views.py b/norma/views.py index 116405ad6..c644f2cf5 100644 --- a/norma/views.py +++ b/norma/views.py @@ -6,6 +6,7 @@ from django.shortcuts import redirect from django.views.generic import CreateView, FormView, ListView, UpdateView from compilacao.views import IntegracaoTaView +import crud.base from crud.base import Crud, make_pagination from materia.models import MateriaLegislativa @@ -15,11 +16,21 @@ from .models import (AssuntoNorma, LegislacaoCitada, NormaJuridica, AssuntoNormaCrud = Crud.build(AssuntoNorma, 'assunto_norma_juridica') TipoNormaCrud = Crud.build(TipoNormaJuridica, 'tipo_norma_juridica') -NormaCrud = Crud.build(NormaJuridica, '') NormaTemporarioCrud = Crud.build(NormaJuridica, 'norma') LegislacaoCitadaCrud = Crud.build(LegislacaoCitada, '') +class NormaCrud(Crud): + model = NormaJuridica + help_path = 'norma_juridica' + + class CreateView(crud.base.CrudCreateView): + form_class = NormaJuridicaForm + + class BaseMixin(crud.base.BaseMixin): + list_field_names = ['tipo', 'numero', 'ano', 'ementa'] + + class NormaPesquisaView(FormView): template_name = "norma/pesquisa.html" success_url = "norma:norma_pesquisa" @@ -110,55 +121,55 @@ class PesquisaNormaListView(ListView): return context -class NormaIncluirView(CreateView): - template_name = "norma/normajuridica_incluir.html" - form_class = NormaJuridicaForm - success_url = reverse_lazy('norma:normajuridica_list') - - def get_success_url(self): - return reverse_lazy('norma:norma_pesquisa') - - def form_valid(self, form): - norma = form.save(commit=False) - norma.timestamp = datetime.now() - if form.cleaned_data['tipo_materia']: - materia = MateriaLegislativa.objects.get( - tipo_id=form.data['tipo_materia'], - numero=form.data['numero_materia'], - ano=form.data['ano_materia']) - norma.materia = materia - norma.save() - return HttpResponseRedirect(self.get_success_url()) - - -class NormaEditView(UpdateView): - template_name = "norma/normajuridica_incluir.html" - form_class = NormaJuridicaForm - model = NormaJuridica - success_url = reverse_lazy('norma:pesquisa_norma') - - def get_initial(self): - data = super(NormaEditView, self).get_initial() - norma = NormaJuridica.objects.get(id=self.kwargs['pk']) - if norma.materia: - data.update({ - 'tipo_materia': norma.materia.tipo, - 'numero_materia': norma.materia.numero, - 'ano_materia': norma.materia.ano, - }) - return data - - def form_valid(self, form): - norma = form.save(commit=False) - norma.timestamp = datetime.now() - if form.cleaned_data['tipo_materia']: - materia = MateriaLegislativa.objects.get( - tipo_id=form.data['tipo_materia'], - numero=form.data['numero_materia'], - ano=form.data['ano_materia']) - norma.materia = materia - norma.save() - return HttpResponseRedirect(self.get_success_url()) +# class NormaIncluirView(CreateView): +# template_name = "norma/normajuridica_incluir.html" +# form_class = NormaJuridicaForm +# success_url = reverse_lazy('norma:normajuridica_list') +# +# def get_success_url(self): +# return reverse_lazy('norma:norma_pesquisa') +# +# def form_valid(self, form): +# norma = form.save(commit=False) +# norma.timestamp = datetime.now() +# if form.cleaned_data['tipo_materia']: +# materia = MateriaLegislativa.objects.get( +# tipo_id=form.data['tipo_materia'], +# numero=form.data['numero_materia'], +# ano=form.data['ano_materia']) +# norma.materia = materia +# norma.save() +# return HttpResponseRedirect(self.get_success_url()) +# +# +# class NormaEditView(UpdateView): +# template_name = "norma/normajuridica_incluir.html" +# form_class = NormaJuridicaForm +# model = NormaJuridica +# success_url = reverse_lazy('norma:pesquisa_norma') +# +# def get_initial(self): +# data = super(NormaEditView, self).get_initial() +# norma = NormaJuridica.objects.get(id=self.kwargs['pk']) +# if norma.materia: +# data.update({ +# 'tipo_materia': norma.materia.tipo, +# 'numero_materia': norma.materia.numero, +# 'ano_materia': norma.materia.ano, +# }) +# return data +# +# def form_valid(self, form): +# norma = form.save(commit=False) +# norma.timestamp = datetime.now() +# if form.cleaned_data['tipo_materia']: +# materia = MateriaLegislativa.objects.get( +# tipo_id=form.data['tipo_materia'], +# numero=form.data['numero_materia'], +# ano=form.data['ano_materia']) +# norma.materia = materia +# norma.save() +# return HttpResponseRedirect(self.get_success_url()) class NormaTaView(IntegracaoTaView): diff --git a/templates/norma/list_pesquisa.html b/templates/norma/list_pesquisa.html index fe46141fe..517fd3969 100644 --- a/templates/norma/list_pesquisa.html +++ b/templates/norma/list_pesquisa.html @@ -4,11 +4,11 @@ {% block actions %}{% endblock %} {% block detail_content %}


{% if object_list %} - +
diff --git a/templates/norma/normajuridica_detail.html b/templates/norma/normajuridica_detail.html deleted file mode 100644 index 13ec219d4..000000000 --- a/templates/norma/normajuridica_detail.html +++ /dev/null @@ -1,28 +0,0 @@ -{% extends "crud/detail.html" %} -{% load i18n %} -{% block sections_nav %} - - - -{% endblock sections_nav %} - -
- {% block actions %} - - {% endblock actions %} -
diff --git a/templates/norma/normajuridica_incluir.html b/templates/norma/normajuridica_incluir.html deleted file mode 100644 index 42eb54de9..000000000 --- a/templates/norma/normajuridica_incluir.html +++ /dev/null @@ -1,3 +0,0 @@ -{% extends "crud/form.html" %} -{% load i18n %} -{% load crispy_forms_tags %} diff --git a/templates/norma/normajuridica_list.html b/templates/norma/normajuridica_list.html deleted file mode 100644 index f39f02bf0..000000000 --- a/templates/norma/normajuridica_list.html +++ /dev/null @@ -1,36 +0,0 @@ -{% extends "crud/list.html" %} -{% load i18n %} -{% load crispy_forms_tags %} -{% block base_content %} - -


- {% if object_list %} -
Tipo da Norma Juridica
- - - - - - - - - - {% for obj in object_list %} - - - - - - - - {% endfor %} -
Tipo da Norma JuridicaNúmeroAnoDataEmenta
{{obj.tipo}}{{obj.numero}}{{obj.ano}}{{obj.data}}{{obj.ementa|safe}}
- {% include "paginacao.html" %} - {% else %} -

Nenhum Registro recuperado

- {% endif %} -{% endblock %} diff --git a/templates/norma/pesquisa.html b/templates/norma/pesquisa.html index 42eb54de9..82edd4116 100644 --- a/templates/norma/pesquisa.html +++ b/templates/norma/pesquisa.html @@ -1,3 +1,17 @@ -{% extends "crud/form.html" %} +{% extends "crud/detail.html" %} {% load i18n %} {% load crispy_forms_tags %} + + +{% block base_content %} + {% block actions %} + +

+ {% endblock %} + + {% block detail_content %} + {% crispy form %} + {% endblock %} +{% endblock %} From 3bfa3628f3a7d6065e9877df75c500d367940a31 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Wed, 13 Apr 2016 09:46:10 -0300 Subject: [PATCH 2/5] =?UTF-8?q?Adiciona=20edi=C3=A7=C3=A3o=20de=20Norma?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- norma/forms.py | 35 ++++++++++++++++++--------- norma/urls.py | 7 +++--- norma/views.py | 64 ++++++++++---------------------------------------- 3 files changed, 39 insertions(+), 67 deletions(-) diff --git a/norma/forms.py b/norma/forms.py index baa01e8bb..8320ebbe7 100644 --- a/norma/forms.py +++ b/norma/forms.py @@ -3,8 +3,10 @@ from datetime import datetime from crispy_forms.helper import FormHelper from crispy_forms.layout import Fieldset, Layout from django import forms +from django.contrib import messages from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.forms import ModelForm +from django.utils.translation import ugettext_lazy as _ import crispy_layout_mixin from crispy_layout_mixin import form_actions @@ -131,19 +133,30 @@ class NormaJuridicaForm(ModelForm): 'observacao', 'texto_integral'] - def save(self, commit=False): - norma = super(NormaJuridicaForm, self).save(commit) - norma.timestamp = datetime.now() + def clean(self): + cleaned_data = self.cleaned_data + + if (cleaned_data['tipo_materia'] and + cleaned_data['numero_materia'] and + cleaned_data['ano_materia']): - if ('tipo_materia' and - 'numero_materia' and - 'ano_materia' in self.cleaned_data): + try: + materia = MateriaLegislativa.objects.get( + tipo_id=cleaned_data['tipo_materia'], + numero=cleaned_data['numero_materia'], + ano=cleaned_data['ano_materia']) + except ObjectDoesNotExist: + raise forms.ValidationError("Matéria escolhida não existe!") + else: + cleaned_data['materia'] = materia - materia = MateriaLegislativa.objects.get( - tipo_id=self.cleaned_data['tipo_materia'], - numero=self.cleaned_data['numero_materia'], - ano=self.cleaned_data['ano_materia']) - norma.materia = materia + else: + cleaned_data['materia'] = None + return cleaned_data + def save(self, commit=False): + norma = super(NormaJuridicaForm, self).save(commit) + norma.timestamp = datetime.now() + norma.materia = self.cleaned_data['materia'] norma.save() return norma diff --git a/norma/urls.py b/norma/urls.py index 34d5083af..c75863a5f 100644 --- a/norma/urls.py +++ b/norma/urls.py @@ -1,9 +1,8 @@ from django.conf.urls import include, url -from norma.views import (AssuntoNormaCrud, NormaCrud, - NormaPesquisaView, NormaTaView, - NormaTemporarioCrud, PesquisaNormaListView, - TipoNormaCrud) +from norma.views import (AssuntoNormaCrud, NormaCrud, NormaPesquisaView, + NormaTaView, NormaTemporarioCrud, + PesquisaNormaListView, TipoNormaCrud) from .apps import AppConfig diff --git a/norma/views.py b/norma/views.py index c644f2cf5..64078ec97 100644 --- a/norma/views.py +++ b/norma/views.py @@ -5,8 +5,8 @@ from django.http import HttpResponseRedirect from django.shortcuts import redirect from django.views.generic import CreateView, FormView, ListView, UpdateView -from compilacao.views import IntegracaoTaView import crud.base +from compilacao.views import IntegracaoTaView from crud.base import Crud, make_pagination from materia.models import MateriaLegislativa @@ -24,6 +24,17 @@ class NormaCrud(Crud): model = NormaJuridica help_path = 'norma_juridica' + class UpdateView(crud.base.CrudUpdateView): + form_class = NormaJuridicaForm + + def get_initial(self): + norma = NormaJuridica.objects.get(id=self.kwargs['pk']) + if norma.materia: + self.initial['tipo_materia'] = norma.materia.tipo + self.initial['ano_materia'] = norma.materia.ano + self.initial['numero_materia'] = norma.materia.numero + return self.initial.copy() + class CreateView(crud.base.CrudCreateView): form_class = NormaJuridicaForm @@ -121,57 +132,6 @@ class PesquisaNormaListView(ListView): return context -# class NormaIncluirView(CreateView): -# template_name = "norma/normajuridica_incluir.html" -# form_class = NormaJuridicaForm -# success_url = reverse_lazy('norma:normajuridica_list') -# -# def get_success_url(self): -# return reverse_lazy('norma:norma_pesquisa') -# -# def form_valid(self, form): -# norma = form.save(commit=False) -# norma.timestamp = datetime.now() -# if form.cleaned_data['tipo_materia']: -# materia = MateriaLegislativa.objects.get( -# tipo_id=form.data['tipo_materia'], -# numero=form.data['numero_materia'], -# ano=form.data['ano_materia']) -# norma.materia = materia -# norma.save() -# return HttpResponseRedirect(self.get_success_url()) -# -# -# class NormaEditView(UpdateView): -# template_name = "norma/normajuridica_incluir.html" -# form_class = NormaJuridicaForm -# model = NormaJuridica -# success_url = reverse_lazy('norma:pesquisa_norma') -# -# def get_initial(self): -# data = super(NormaEditView, self).get_initial() -# norma = NormaJuridica.objects.get(id=self.kwargs['pk']) -# if norma.materia: -# data.update({ -# 'tipo_materia': norma.materia.tipo, -# 'numero_materia': norma.materia.numero, -# 'ano_materia': norma.materia.ano, -# }) -# return data -# -# def form_valid(self, form): -# norma = form.save(commit=False) -# norma.timestamp = datetime.now() -# if form.cleaned_data['tipo_materia']: -# materia = MateriaLegislativa.objects.get( -# tipo_id=form.data['tipo_materia'], -# numero=form.data['numero_materia'], -# ano=form.data['ano_materia']) -# norma.materia = materia -# norma.save() -# return HttpResponseRedirect(self.get_success_url()) - - class NormaTaView(IntegracaoTaView): model = NormaJuridica model_type_foreignkey = TipoNormaJuridica From dbd15b2925007301bbbea09b8783c8b20e6a6a44 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Wed, 13 Apr 2016 09:55:25 -0300 Subject: [PATCH 3/5] Arruma tela de detail --- norma/layouts.yaml | 10 ++++++++++ norma/views.py | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/norma/layouts.yaml b/norma/layouts.yaml index 038a37951..b0bce2d2a 100644 --- a/norma/layouts.yaml +++ b/norma/layouts.yaml @@ -8,6 +8,16 @@ TipoNormaJuridica: - descricao sigla equivalente_lexml NormaJuridica: + Identificação Básica: + - tipo numero ano + - data esfera_federacao complemento + - data_publicacao veiculo_publicacao pagina_inicio_publicacao pagina_fim_publicacao + - texto_integral + - ementa + - indexacao + - observacao + +NormaJuridicaCreate: Identificação Básica: - tipo numero ano - data esfera_federacao complemento diff --git a/norma/views.py b/norma/views.py index 64078ec97..875030249 100644 --- a/norma/views.py +++ b/norma/views.py @@ -27,6 +27,10 @@ class NormaCrud(Crud): class UpdateView(crud.base.CrudUpdateView): form_class = NormaJuridicaForm + @property + def layout_key(self): + return 'NormaJuridicaCreate' + def get_initial(self): norma = NormaJuridica.objects.get(id=self.kwargs['pk']) if norma.materia: @@ -38,6 +42,10 @@ class NormaCrud(Crud): class CreateView(crud.base.CrudCreateView): form_class = NormaJuridicaForm + @property + def layout_key(self): + return 'NormaJuridicaCreate' + class BaseMixin(crud.base.BaseMixin): list_field_names = ['tipo', 'numero', 'ano', 'ementa'] From be50605e55df0c49124c896158cec849a4f94c0f Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Wed, 13 Apr 2016 09:59:13 -0300 Subject: [PATCH 4/5] Conserta qa e testes --- norma/forms.py | 5 +---- norma/test_norma.py | 4 ++-- norma/views.py | 5 +---- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/norma/forms.py b/norma/forms.py index 8320ebbe7..1f80f1b40 100644 --- a/norma/forms.py +++ b/norma/forms.py @@ -3,15 +3,12 @@ from datetime import datetime from crispy_forms.helper import FormHelper from crispy_forms.layout import Fieldset, Layout from django import forms -from django.contrib import messages -from django.core.exceptions import ObjectDoesNotExist, ValidationError +from django.core.exceptions import ObjectDoesNotExist from django.forms import ModelForm -from django.utils.translation import ugettext_lazy as _ import crispy_layout_mixin from crispy_layout_mixin import form_actions from materia.models import MateriaLegislativa, TipoMateriaLegislativa -from sapl.settings import MAX_DOC_UPLOAD_SIZE from sapl.utils import RANGE_ANOS from .models import NormaJuridica diff --git a/norma/test_norma.py b/norma/test_norma.py index 4731995b2..e25b3dbfd 100644 --- a/norma/test_norma.py +++ b/norma/test_norma.py @@ -13,7 +13,7 @@ def test_incluir_norma_submit(client): descricao='Teste') # Testa POST - response = client.post(reverse('norma:norma_incluir'), + response = client.post(reverse('norma:normajuridica_create'), {'tipo': tipo.pk, 'numero': '1', 'ano': '2016', @@ -33,7 +33,7 @@ def test_incluir_norma_submit(client): @pytest.mark.django_db(transaction=False) def test_incluir_norma_errors(client): - response = client.post(reverse('norma:norma_incluir'), + response = client.post(reverse('norma:normajuridica_create'), {'salvar': 'salvar'}, follow=True) diff --git a/norma/views.py b/norma/views.py index 875030249..e454ac7cc 100644 --- a/norma/views.py +++ b/norma/views.py @@ -1,14 +1,11 @@ from datetime import datetime -from django.core.urlresolvers import reverse_lazy -from django.http import HttpResponseRedirect from django.shortcuts import redirect -from django.views.generic import CreateView, FormView, ListView, UpdateView +from django.views.generic import FormView, ListView import crud.base from compilacao.views import IntegracaoTaView from crud.base import Crud, make_pagination -from materia.models import MateriaLegislativa from .forms import NormaJuridicaForm, NormaJuridicaPesquisaForm from .models import (AssuntoNorma, LegislacaoCitada, NormaJuridica, From 6e3be4ab2e9e8aaa36585811a3c3ba9d481df6a6 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Wed, 13 Apr 2016 10:17:40 -0300 Subject: [PATCH 5/5] =?UTF-8?q?Adiciona=20valida=C3=A7=C3=A3o=20do=20taman?= =?UTF-8?q?ho=20do=20arquivo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- norma/forms.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/norma/forms.py b/norma/forms.py index 1f80f1b40..dc254ab08 100644 --- a/norma/forms.py +++ b/norma/forms.py @@ -3,12 +3,13 @@ from datetime import datetime from crispy_forms.helper import FormHelper from crispy_forms.layout import Fieldset, Layout from django import forms -from django.core.exceptions import ObjectDoesNotExist +from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.forms import ModelForm import crispy_layout_mixin from crispy_layout_mixin import form_actions from materia.models import MateriaLegislativa, TipoMateriaLegislativa +from sapl.settings import MAX_DOC_UPLOAD_SIZE from sapl.utils import RANGE_ANOS from .models import NormaJuridica @@ -151,6 +152,13 @@ class NormaJuridicaForm(ModelForm): cleaned_data['materia'] = None return cleaned_data + def clean_texto_integral(self): + texto_integral = self.cleaned_data.get('texto_integral', False) + if texto_integral: + if texto_integral.size > MAX_DOC_UPLOAD_SIZE: + raise ValidationError("Arquivo muito grande. ( > 5mb )") + return texto_integral + def save(self, commit=False): norma = super(NormaJuridicaForm, self).save(commit) norma.timestamp = datetime.now()