From ebe51873109ad981fb60e07b2a2f5e4c96e494ff Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Wed, 16 Mar 2016 10:57:48 -0300 Subject: [PATCH] Restringe tipos de texto original em proposicao, adiciona botao de remover texto original e adiciona novos mime types em restricao de textos --- materia/forms.py | 11 +++++++++++ materia/models.py | 5 +++-- materia/views.py | 12 +++++++++++- parlamentares/forms.py | 4 ---- sapl/utils.py | 5 ++++- 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/materia/forms.py b/materia/forms.py index 6b260d58e..24c81b4a6 100644 --- a/materia/forms.py +++ b/materia/forms.py @@ -61,6 +61,17 @@ class ProposicaoForm(ModelForm): self.helper.layout = Layout( Fieldset(_('Incluir Proposição'), row1, row2, row3, row4, + HTML(""" +
+

+ +

+ """, ), form_actions(more=more)) ) super(ProposicaoForm, self).__init__( diff --git a/materia/models.py b/materia/models.py index a9e864931..724c7f5ae 100644 --- a/materia/models.py +++ b/materia/models.py @@ -4,7 +4,7 @@ from model_utils import Choices from comissoes.models import Comissao from parlamentares.models import Parlamentar, Partido -from sapl.utils import (restringe_tipos_de_arquivo_txt, +from sapl.utils import (restringe_tipos_de_arquivo_txt, RANGE_ANOS, YES_NO_CHOICES, xstr) @@ -123,7 +123,8 @@ class MateriaLegislativa(models.Model): blank=True, null=True, upload_to=texto_upload_path, - verbose_name=_('Texto Original (PDF)')) + verbose_name=_('Texto Original (PDF)'), + validators=[restringe_tipos_de_arquivo_txt]) class Meta: verbose_name = _('Matéria Legislativa') diff --git a/materia/views.py b/materia/views.py index 078228495..b7251edb6 100644 --- a/materia/views.py +++ b/materia/views.py @@ -1,3 +1,5 @@ +import os + from datetime import datetime from random import choice from string import ascii_letters, digits @@ -1377,8 +1379,10 @@ class ProposicaoEditView(CreateView): proposicao.save() else: proposicao.delete() - elif 'salvar' in request.POST: + if 'salvar' or "remover-foto" in request.POST: if 'texto_original' in request.FILES: + # if os.unlink(proposicao.texto_original.path): + # proposicao.texto_original = None proposicao.texto_original = request.FILES['texto_original'] tipo = TipoProposicao.objects.get(id=form.data['tipo']) proposicao.tipo = tipo @@ -1397,6 +1401,12 @@ class ProposicaoEditView(CreateView): proposicao.autor = materia.autoria_set.first().autor proposicao.materia = materia proposicao.data_envio = datetime.now() + if "remover-texto" in request.POST: + try: + os.unlink(proposicao.texto_original.path) + except OSError: + pass # Should log this error!!!!! + proposicao.texto_original = None proposicao.save() return redirect(self.get_success_url()) else: diff --git a/parlamentares/forms.py b/parlamentares/forms.py index 64c8daff2..5d57d8f22 100644 --- a/parlamentares/forms.py +++ b/parlamentares/forms.py @@ -142,11 +142,7 @@ class ParlamentaresForm (ModelForm): id="remover-foto" class="btn btn-warning" value="Remover Foto"/> -<<<<<<< HEAD - {% endif %} -======= {% endif %} ->>>>>>> 490fffbf4e0e50be52d47056821e7f626ce76dcd {% endif %}""", ), row14, form_actions()) diff --git a/sapl/utils.py b/sapl/utils.py index 83a3fc820..e06092ea9 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -140,7 +140,10 @@ TIPOS_TEXTO_PERMITIDOS = ( 'widetext/paragraph', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', -) + 'application/xml', + 'text/xml', + 'text/html', + ) TIPOS_IMG_PERMITIDOS = ( 'image/jpeg',