|
|
@ -1,15 +1,13 @@ |
|
|
|
import hashlib |
|
|
|
import logging |
|
|
|
import os |
|
|
|
import re |
|
|
|
from datetime import date |
|
|
|
from functools import wraps |
|
|
|
from unicodedata import normalize as unicodedata_normalize |
|
|
|
from subprocess import PIPE, call |
|
|
|
from threading import Thread |
|
|
|
from unicodedata import normalize as unicodedata_normalize |
|
|
|
import hashlib |
|
|
|
import logging |
|
|
|
import os |
|
|
|
import re |
|
|
|
|
|
|
|
import django_filters |
|
|
|
import magic |
|
|
|
from crispy_forms.helper import FormHelper |
|
|
|
from crispy_forms.layout import HTML, Button |
|
|
|
from django import forms |
|
|
@ -22,10 +20,13 @@ from django.core.exceptions import ValidationError |
|
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
|
from floppyforms import ClearableFileInput |
|
|
|
from reversion.admin import VersionAdmin |
|
|
|
import django_filters |
|
|
|
import magic |
|
|
|
|
|
|
|
from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row |
|
|
|
from sapl.settings import BASE_DIR, PROJECT_DIR |
|
|
|
|
|
|
|
|
|
|
|
sapl_logger = logging.getLogger(BASE_DIR.name) |
|
|
|
|
|
|
|
|
|
|
@ -159,8 +160,8 @@ class SaplGenericRelation(GenericRelation): |
|
|
|
assert isinstance(field, (tuple, list)), _( |
|
|
|
'fields_search deve ser um array de tuplas ou listas.') |
|
|
|
|
|
|
|
assert len(field) == 2, _( |
|
|
|
'cada tupla de fields_search deve possuir duas strins') |
|
|
|
assert len(field) <= 3, _( |
|
|
|
'cada tupla de fields_search deve possuir até 3 strings') |
|
|
|
|
|
|
|
# TODO implementar assert para validar campos do Model e lookups |
|
|
|
|
|
|
@ -368,8 +369,8 @@ def fabrica_validador_de_tipos_de_arquivo(lista, nome): |
|
|
|
|
|
|
|
def restringe_tipos_de_arquivo(value): |
|
|
|
if not os.path.splitext(value.path)[1][:1]: |
|
|
|
raise ValidationError(_( |
|
|
|
'Não é possível fazer upload de arquivos sem extensão.')) |
|
|
|
raise ValidationError(_( |
|
|
|
'Não é possível fazer upload de arquivos sem extensão.')) |
|
|
|
|
|
|
|
mime = magic.from_buffer(value.read(), mime=True) |
|
|
|
if mime not in lista: |
|
|
@ -637,6 +638,7 @@ def texto_upload_path(instance, filename, subpath=''): |
|
|
|
|
|
|
|
|
|
|
|
class UpdateIndexCommand(Thread): |
|
|
|
|
|
|
|
def run(self): |
|
|
|
call([PROJECT_DIR.child('manage.py'), 'update_index'], |
|
|
|
stdout=PIPE) |
|
|
|