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. 3
      materia/models.py
  3. 12
      materia/views.py
  4. 4
      parlamentares/forms.py
  5. 3
      sapl/utils.py

11
materia/forms.py

@ -61,6 +61,17 @@ class ProposicaoForm(ModelForm):
self.helper.layout = Layout(
Fieldset(_('Incluir Proposição'),
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))
)
super(ProposicaoForm, self).__init__(

3
materia/models.py

@ -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')

12
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:

4
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())

3
sapl/utils.py

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

Loading…
Cancel
Save