Browse Source

Adiciona exception para extensão não suportada

Signed-off-by: Luciano Almeida <lucianoalmeida@interlegis.leg.br>
pull/1090/head
Luciano Almeida 8 years ago
parent
commit
dafc513236
  1. 12
      sapl/base/search_indexes.py

12
sapl/base/search_indexes.py

@ -7,6 +7,8 @@ from haystack import indexes
from sapl.materia.models import DocumentoAcessorio, MateriaLegislativa
from sapl.norma.models import NormaJuridica
from textract.exceptions import ExtensionNotSupported
class DocumentoAcessorioIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
@ -32,15 +34,19 @@ class DocumentoAcessorioIndex(indexes.SearchIndex, indexes.Indexable):
if arquivo:
try:
arquivo.open()
arquivo.close()
except OSError:
return self.prepared_data
if not os.path.splitext(arquivo.path)[1][:1]:
return self.prepared_data
extracted_data = textract.process(
arquivo.path).decode(
'utf-8').replace('\n', ' ')
try:
extracted_data = textract.process(
arquivo.path).decode(
'utf-8').replace('\n', ' ')
except ExtensionNotSupported:
return self.prepared_data
extracted_data = extracted_data.replace('\t', ' ')

Loading…
Cancel
Save