From 4310589f6a60e096b3945d09f9e7ca4f9fa36068 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Tue, 14 Aug 2018 15:22:21 -0300 Subject: [PATCH] HOT-FIX: Refactorings --- sapl/materia/forms.py | 9 ++++----- sapl/norma/forms.py | 9 ++++----- sapl/norma/views.py | 9 +++++---- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index b543fda41..88db58f8b 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -1295,12 +1295,11 @@ class ProposicaoForm(forms.ModelForm): def clean_texto_original(self): texto_original = self.cleaned_data.get('texto_original', False) - if texto_original: - if texto_original.size > MAX_DOC_UPLOAD_SIZE: - max_size = str(MAX_DOC_UPLOAD_SIZE / (1024 * 1024)) - raise ValidationError( + if texto_original and texto_original.size > MAX_DOC_UPLOAD_SIZE: + max_size = str(MAX_DOC_UPLOAD_SIZE / (1024 * 1024)) + raise ValidationError( "Arquivo muito grande. ( > {0}MB )".format(max_size)) - return texto_original + return texto_original def gerar_hash(self, inst, receber_recibo): diff --git a/sapl/norma/forms.py b/sapl/norma/forms.py index e3fd6e435..7d791207a 100644 --- a/sapl/norma/forms.py +++ b/sapl/norma/forms.py @@ -164,11 +164,10 @@ class NormaJuridicaForm(ModelForm): 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: - max_size = str(MAX_DOC_UPLOAD_SIZE / (1024 * 1024)) - raise ValidationError( - "Arquivo muito grande. ( > {0}MB )".format(max_size)) + if texto_integral and texto_integral.size > MAX_DOC_UPLOAD_SIZE: + max_size = str(MAX_DOC_UPLOAD_SIZE / (1024 * 1024)) + raise ValidationError( + "Arquivo muito grande. ( > {0}MB )".format(max_size)) return texto_integral def save(self, commit=False): diff --git a/sapl/norma/views.py b/sapl/norma/views.py index de3efa8ef..3f57ad387 100644 --- a/sapl/norma/views.py +++ b/sapl/norma/views.py @@ -110,15 +110,16 @@ class AnexoNormaJuridicaCrud(MasterDetailCrud): class CreateView(MasterDetailCrud.CreateView): form_class = AnexoNormaJuridicaForm layout_key = 'AnexoNormaJuridica' + def get_initial(self): - norma_id = str(self.request).split("/")[-3] - self.initial = super(MasterDetailCrud.CreateView, self).get_initial() - self.initial['norma'] = NormaJuridica.objects.get(id=norma_id) - return self.initial + initial = super(MasterDetailCrud.CreateView, self).get_initial() + initial['norma'] = NormaJuridica.objects.get(id=self.kwargs['pk']) + return initial class UpdateView(MasterDetailCrud.UpdateView): form_class = AnexoNormaJuridicaForm layout_key = 'AnexoNormaJuridica' + def get_initial(self): initial = super(UpdateView, self).get_initial() initial['norma'] = self.object.norma