Added ikflush management command

This commit is contained in:
Justin Driscoll 2009-01-08 16:11:15 -05:00
parent b85e171309
commit 749ec2bd9e
11 changed files with 68 additions and 35 deletions

View file

@ -6,23 +6,6 @@ Author: Justin Driscoll <justin.driscoll@gmail.com>
Version: 1.0
"""
# Required PIL classes may or may not be available from the root namespace
# depending on the installation method used.
try:
import Image
import ImageFile
import ImageFilter
import ImageEnhance
import ImageColor
except ImportError:
try:
from PIL import Image
from PIL import ImageFile
from PIL import ImageFilter
from PIL import ImageEnhance
from PIL import ImageColor
except ImportError:
raise ImportError('ImageKit was unable to import the Python Imaging Library. Please confirm it`s installed and available on your current Python path.')

17
src/imagekit/lib.py Normal file
View file

@ -0,0 +1,17 @@
# Required PIL classes may or may not be available from the root namespace
# depending on the installation method used.
try:
import Image
import ImageFile
import ImageFilter
import ImageEnhance
import ImageColor
except ImportError:
try:
from PIL import Image
from PIL import ImageFile
from PIL import ImageFilter
from PIL import ImageEnhance
from PIL import ImageColor
except ImportError:
raise ImportError('ImageKit was unable to import the Python Imaging Library. Please confirm it`s installed and available on your current Python path.')

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@

View file

@ -0,0 +1,38 @@
from django.db.models.loading import cache
from django.core.management.base import BaseCommand, CommandError
from optparse import make_option
from imagekit.models import IKModel
from imagekit.specs import ImageSpec
class Command(BaseCommand):
help = ('Clears all ImageKit cached files.')
args = '[apps]'
requires_model_validation = True
can_import_settings = True
def handle(self, *args, **options):
return flush_cache(args, options)
def flush_cache(apps, options):
""" Clears the image cache
"""
apps = [a.strip(',') for a in apps]
if apps:
print 'Flushing cache for %s...' % ', '.join(apps)
else:
print 'Flushing caches...'
for app_label in apps:
app = cache.get_app(app_label)
models = [m for m in cache.get_models(app) if issubclass(m, IKModel)]
for model in models:
for obj in model.objects.all():
for spec in model._ik.specs:
prop = getattr(obj, spec.name(), None)
if prop is not None:
prop._delete()
if spec.pre_cache:
prop._create()

View file

@ -6,9 +6,9 @@ from django.db import models
from django.db.models.base import ModelBase
from django.utils.translation import ugettext_lazy as _
from imagekit import *
from imagekit.options import Options
from imagekit import specs
from imagekit.lib import *
from imagekit.options import Options
from imagekit.utils import img_to_fobj

View file

@ -1,14 +1,6 @@
# Imagekit options
from imagekit import processors
from imagekit.specs import ImageSpec
class ResizeMax(processors.Resize):
width = 500
height = 500
class PreprocessorSpec(ImageSpec):
processors = [ResizeMax]
class Options(object):
@ -18,7 +10,7 @@ class Options(object):
image_field = 'image'
crop_horz_field = 'crop_horz'
crop_vert_field = 'crop_vert'
preprocessor_spec = PreprocessorSpec
preprocessor_spec = None
cache_dir = 'images'
save_count_as = None
cache_filename_format = "%(filename)s_%(specname)s.%(extension)s"

View file

@ -6,7 +6,7 @@ the class properties as settings. The process method can be overridden as well a
own effects/processes entirely.
"""
from imagekit import *
from imagekit.lib import *
class ImageProcessor(object):
""" Base image processor class """

View file

@ -6,7 +6,7 @@ spec found.
"""
import os
from imagekit import Image
from imagekit.lib import *
from imagekit.utils import img_to_fobj
from django.core.files.base import ContentFile

View file

@ -6,11 +6,10 @@ from django.core.files.base import ContentFile
from django.db import models
from django.test import TestCase
from models import IKModel
from specs import ImageSpec
from imagekit import processors
from imagekit import Image
from imagekit.models import IKModel
from imagekit.specs import ImageSpec
from imagekit.lib import Image
class ResizeToWidth(processors.Resize):

View file

@ -1,3 +1,5 @@
""" ImageKit utility functions """
import tempfile
def img_to_fobj(img, format, **kwargs):
@ -10,4 +12,4 @@ def img_to_fobj(img, format, **kwargs):
pass
img.save(tmp, format, **kwargs)
tmp.seek(0)
return tmp
return tmp