|
|
@ -6,10 +6,6 @@ import re |
|
|
from unicodedata import normalize as unicodedata_normalize |
|
|
from unicodedata import normalize as unicodedata_normalize |
|
|
import unicodedata |
|
|
import unicodedata |
|
|
|
|
|
|
|
|
from django.core.files.uploadedfile import UploadedFile |
|
|
|
|
|
from django.forms import BaseForm |
|
|
|
|
|
|
|
|
|
|
|
from sapl.crispy_layout_mixin import SaplFormHelper |
|
|
|
|
|
from crispy_forms.layout import HTML, Button |
|
|
from crispy_forms.layout import HTML, Button |
|
|
from django import forms |
|
|
from django import forms |
|
|
from django.apps import apps |
|
|
from django.apps import apps |
|
|
@ -18,11 +14,14 @@ from django.contrib import admin |
|
|
from django.contrib.contenttypes.fields import (GenericForeignKey, GenericRel, |
|
|
from django.contrib.contenttypes.fields import (GenericForeignKey, GenericRel, |
|
|
GenericRelation) |
|
|
GenericRelation) |
|
|
from django.core.exceptions import ValidationError |
|
|
from django.core.exceptions import ValidationError |
|
|
|
|
|
from django.core.files.uploadedfile import UploadedFile |
|
|
from django.core.mail import get_connection |
|
|
from django.core.mail import get_connection |
|
|
from django.db import models |
|
|
from django.db import models |
|
|
from django.db.models import Q |
|
|
from django.db.models import Q |
|
|
|
|
|
from django.forms import BaseForm |
|
|
from django.forms.widgets import SplitDateTimeWidget |
|
|
from django.forms.widgets import SplitDateTimeWidget |
|
|
from django.utils import six, timezone |
|
|
from django.utils import six, timezone |
|
|
|
|
|
from django.utils.safestring import mark_safe |
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
import django_filters |
|
|
import django_filters |
|
|
from easy_thumbnails import source_generators |
|
|
from easy_thumbnails import source_generators |
|
|
@ -31,9 +30,9 @@ import magic |
|
|
from reversion_compare.admin import CompareVersionAdmin |
|
|
from reversion_compare.admin import CompareVersionAdmin |
|
|
from unipath.path import Path |
|
|
from unipath.path import Path |
|
|
|
|
|
|
|
|
|
|
|
from sapl.crispy_layout_mixin import SaplFormHelper |
|
|
from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row |
|
|
from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# (26/10/2018): O separador foi mudador de '/' para 'K' |
|
|
# (26/10/2018): O separador foi mudador de '/' para 'K' |
|
|
# por conta dos leitores de códigos de barra, que trocavam |
|
|
# por conta dos leitores de códigos de barra, que trocavam |
|
|
# a '/' por '&' ou ';' |
|
|
# a '/' por '&' ou ';' |
|
|
@ -44,6 +43,24 @@ def pil_image(source, exif_orientation=False, **options): |
|
|
return source_generators.pil_image(source, exif_orientation, **options) |
|
|
return source_generators.pil_image(source, exif_orientation, **options) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def split_longtext(value, max_part=50): |
|
|
|
|
|
_safe = value.split() |
|
|
|
|
|
|
|
|
|
|
|
def chunkstring(string): |
|
|
|
|
|
return re.findall('.{%d}' % max_part, string) |
|
|
|
|
|
|
|
|
|
|
|
def __map(a): |
|
|
|
|
|
if len(a) <= max_part: |
|
|
|
|
|
return a |
|
|
|
|
|
return '<br>' + '<br>'.join(chunkstring(a)) |
|
|
|
|
|
|
|
|
|
|
|
_safe = map(__map, _safe) |
|
|
|
|
|
_safe = ' '.join(_safe) |
|
|
|
|
|
|
|
|
|
|
|
_safe = mark_safe(_safe) |
|
|
|
|
|
return value |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def clear_thumbnails_cache(queryset, field): |
|
|
def clear_thumbnails_cache(queryset, field): |
|
|
|
|
|
|
|
|
for r in queryset: |
|
|
for r in queryset: |
|
|
@ -84,7 +101,6 @@ autor_label = ''' |
|
|
</div> |
|
|
</div> |
|
|
''' |
|
|
''' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
autor_modal = ''' |
|
|
autor_modal = ''' |
|
|
<div id="modal_autor" title="Selecione o Autor" align="center"> |
|
|
<div id="modal_autor" title="Selecione o Autor" align="center"> |
|
|
<form> |
|
|
<form> |
|
|
@ -239,6 +255,7 @@ class RangeWidgetOverride(forms.MultiWidget): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CustomSplitDateTimeWidget(SplitDateTimeWidget): |
|
|
class CustomSplitDateTimeWidget(SplitDateTimeWidget): |
|
|
|
|
|
|
|
|
def render(self, name, value, attrs=None, renderer=None): |
|
|
def render(self, name, value, attrs=None, renderer=None): |
|
|
rendered_widgets = [] |
|
|
rendered_widgets = [] |
|
|
for i, x in enumerate(self.widgets): |
|
|
for i, x in enumerate(self.widgets): |
|
|
@ -260,6 +277,7 @@ def register_all_models_in_admin(module_name, exclude_list=[]): |
|
|
appname = appname[1] if appname[0] == 'sapl' else appname[0] |
|
|
appname = appname[1] if appname[0] == 'sapl' else appname[0] |
|
|
app = apps.get_app_config(appname) |
|
|
app = apps.get_app_config(appname) |
|
|
for model in app.get_models(): |
|
|
for model in app.get_models(): |
|
|
|
|
|
|
|
|
class CustomModelAdmin(CompareVersionAdmin): |
|
|
class CustomModelAdmin(CompareVersionAdmin): |
|
|
list_display = [f.name for f in model._meta.fields |
|
|
list_display = [f.name for f in model._meta.fields |
|
|
if f.name != 'id' and f.name not in exclude_list] |
|
|
if f.name != 'id' and f.name not in exclude_list] |
|
|
@ -311,9 +329,11 @@ YES_NO_CHOICES = [(True, _('Sim')), (False, _('Não'))] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def listify(function): |
|
|
def listify(function): |
|
|
|
|
|
|
|
|
@wraps(function) |
|
|
@wraps(function) |
|
|
def f(*args, **kwargs): |
|
|
def f(*args, **kwargs): |
|
|
return list(function(*args, **kwargs)) |
|
|
return list(function(*args, **kwargs)) |
|
|
|
|
|
|
|
|
return f |
|
|
return f |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -351,7 +371,6 @@ LISTA_DE_UFS = [ |
|
|
RANGE_ANOS = [(year, year) for year in range(timezone.now().year + 1, |
|
|
RANGE_ANOS = [(year, year) for year in range(timezone.now().year + 1, |
|
|
1889, -1)] |
|
|
1889, -1)] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RANGE_MESES = [ |
|
|
RANGE_MESES = [ |
|
|
(1, 'Janeiro'), |
|
|
(1, 'Janeiro'), |
|
|
(2, 'Fevereiro'), |
|
|
(2, 'Fevereiro'), |
|
|
@ -431,8 +450,10 @@ def choice_force_optional(callable): |
|
|
o item opcional '---------' já que ChoiceFilter já o adiciona, como dito |
|
|
o item opcional '---------' já que ChoiceFilter já o adiciona, como dito |
|
|
anteriormente. |
|
|
anteriormente. |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
def _func(): |
|
|
def _func(): |
|
|
return [('', '---------')] + callable() |
|
|
return [('', '---------')] + callable() |
|
|
|
|
|
|
|
|
return _func |
|
|
return _func |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -508,6 +529,7 @@ def fabrica_validador_de_tipos_de_arquivo(lista, nome): |
|
|
raise ValidationError(_('Tipo de arquivo não suportado')) |
|
|
raise ValidationError(_('Tipo de arquivo não suportado')) |
|
|
except FileNotFoundError: |
|
|
except FileNotFoundError: |
|
|
raise ValidationError(_('Arquivo não encontrado')) |
|
|
raise ValidationError(_('Arquivo não encontrado')) |
|
|
|
|
|
|
|
|
# o nome é importante para as migrations |
|
|
# o nome é importante para as migrations |
|
|
restringe_tipos_de_arquivo.__name__ = nome |
|
|
restringe_tipos_de_arquivo.__name__ = nome |
|
|
return restringe_tipos_de_arquivo |
|
|
return restringe_tipos_de_arquivo |
|
|
@ -578,6 +600,7 @@ class NormaPesquisaOrderingFilter(django_filters.OrderingFilter): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FileFieldCheckMixin(BaseForm): |
|
|
class FileFieldCheckMixin(BaseForm): |
|
|
|
|
|
|
|
|
def _check(self): |
|
|
def _check(self): |
|
|
cleaned_data = super(FileFieldCheckMixin, self).clean() |
|
|
cleaned_data = super(FileFieldCheckMixin, self).clean() |
|
|
errors = [] |
|
|
errors = [] |
|
|
|