Browse Source

add limp de variações de arq em camp baseados em FileField

pull/1728/head
LeandroRoberto 7 years ago
parent
commit
956d6a5a3a
  1. 23
      sapl/parlamentares/migrations/0021_clear_thumbnails_cache.py
  2. 18
      sapl/utils.py

23
sapl/parlamentares/migrations/0021_clear_thumbnails_cache.py

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations
from sapl.utils import clear_thumbnails_cache
def clear_thumbnails_cache_migrate(apps, schema_editor):
Parlamentar = apps.get_model("parlamentares", "Parlamentar")
parlamentares = Parlamentar.objects.all()
clear_thumbnails_cache(parlamentares, 'fotografia')
class Migration(migrations.Migration):
dependencies = [
('parlamentares', '0020_fix_inicio_mandato'),
]
operations = [
migrations.RunPython(clear_thumbnails_cache_migrate),
]

18
sapl/utils.py

@ -22,6 +22,7 @@ from django_filters.filterset import STRICTNESS
from easy_thumbnails import source_generators from easy_thumbnails import source_generators
from floppyforms import ClearableFileInput from floppyforms import ClearableFileInput
from reversion.admin import VersionAdmin from reversion.admin import VersionAdmin
from unipath.path import Path
import django_filters import django_filters
import magic import magic
@ -36,6 +37,23 @@ 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 clear_thumbnails_cache(queryset, field):
for r in queryset:
assert hasattr(r, field), _(
'Objeto da listagem não possui o campo informado')
if not getattr(r, field):
continue
path = Path(getattr(r, field).path)
cache_files = path.parent.walk()
for cf in cache_files:
if cf != path:
cf.remove()
def normalize(txt): def normalize(txt):
return unicodedata_normalize( return unicodedata_normalize(
'NFKD', txt).encode('ASCII', 'ignore').decode('ASCII') 'NFKD', txt).encode('ASCII', 'ignore').decode('ASCII')

Loading…
Cancel
Save