Browse Source

Restringe tipos de texto original em proposicao, adiciona botao de remover texto original e adiciona novos mime types em restricao de textos

pull/268/head
Eduardo Calil 9 years ago
parent
commit
ebe5187310
  1. 11
      materia/forms.py
  2. 5
      materia/models.py
  3. 12
      materia/views.py
  4. 4
      parlamentares/forms.py
  5. 5
      sapl/utils.py

11
materia/forms.py

@ -61,6 +61,17 @@ class ProposicaoForm(ModelForm):
self.helper.layout = Layout( self.helper.layout = Layout(
Fieldset(_('Incluir Proposição'), Fieldset(_('Incluir Proposição'),
row1, row2, row3, row4, row1, row2, row3, row4,
HTML("""
<div class="img-responsive" width="225" height="300"
src="{{ MEDIA_URL }}{{ form.texto_original.value }}">
<br /><br />
<input type="submit"
name="remover-texto"
id="remover-texto"
class="btn btn-warning"
value="Remover Texto"/>
<p></p>
""", ),
form_actions(more=more)) form_actions(more=more))
) )
super(ProposicaoForm, self).__init__( super(ProposicaoForm, self).__init__(

5
materia/models.py

@ -4,7 +4,7 @@ from model_utils import Choices
from comissoes.models import Comissao from comissoes.models import Comissao
from parlamentares.models import Parlamentar, Partido 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) RANGE_ANOS, YES_NO_CHOICES, xstr)
@ -123,7 +123,8 @@ class MateriaLegislativa(models.Model):
blank=True, blank=True,
null=True, null=True,
upload_to=texto_upload_path, upload_to=texto_upload_path,
verbose_name=_('Texto Original (PDF)')) verbose_name=_('Texto Original (PDF)'),
validators=[restringe_tipos_de_arquivo_txt])
class Meta: class Meta:
verbose_name = _('Matéria Legislativa') verbose_name = _('Matéria Legislativa')

12
materia/views.py

@ -1,3 +1,5 @@
import os
from datetime import datetime from datetime import datetime
from random import choice from random import choice
from string import ascii_letters, digits from string import ascii_letters, digits
@ -1377,8 +1379,10 @@ class ProposicaoEditView(CreateView):
proposicao.save() proposicao.save()
else: else:
proposicao.delete() proposicao.delete()
elif 'salvar' in request.POST: if 'salvar' or "remover-foto" in request.POST:
if 'texto_original' in request.FILES: if 'texto_original' in request.FILES:
# if os.unlink(proposicao.texto_original.path):
# proposicao.texto_original = None
proposicao.texto_original = request.FILES['texto_original'] proposicao.texto_original = request.FILES['texto_original']
tipo = TipoProposicao.objects.get(id=form.data['tipo']) tipo = TipoProposicao.objects.get(id=form.data['tipo'])
proposicao.tipo = tipo proposicao.tipo = tipo
@ -1397,6 +1401,12 @@ class ProposicaoEditView(CreateView):
proposicao.autor = materia.autoria_set.first().autor proposicao.autor = materia.autoria_set.first().autor
proposicao.materia = materia proposicao.materia = materia
proposicao.data_envio = datetime.now() 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() proposicao.save()
return redirect(self.get_success_url()) return redirect(self.get_success_url())
else: else:

4
parlamentares/forms.py

@ -142,11 +142,7 @@ class ParlamentaresForm (ModelForm):
id="remover-foto" id="remover-foto"
class="btn btn-warning" class="btn btn-warning"
value="Remover Foto"/> value="Remover Foto"/>
<<<<<<< HEAD
{% endif %}
=======
{% endif %} {% endif %}
>>>>>>> 490fffbf4e0e50be52d47056821e7f626ce76dcd
{% endif %}""", ), {% endif %}""", ),
row14, row14,
form_actions()) form_actions())

5
sapl/utils.py

@ -140,7 +140,10 @@ TIPOS_TEXTO_PERMITIDOS = (
'widetext/paragraph', 'widetext/paragraph',
'application/msword', 'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
) 'application/xml',
'text/xml',
'text/html',
)
TIPOS_IMG_PERMITIDOS = ( TIPOS_IMG_PERMITIDOS = (
'image/jpeg', 'image/jpeg',

Loading…
Cancel
Save