Removed specs list from opts.

This commit is contained in:
Matthew Tretter 2011-09-21 20:21:15 -04:00
parent 305d20569c
commit 7167016237
3 changed files with 9 additions and 18 deletions

View file

@ -1,8 +1,7 @@
from django.db.models.loading import cache
from django.core.management.base import BaseCommand, CommandError
from optparse import make_option
from imagekit.models import ImageModel
from imagekit.fields import ImageSpec
from imagekit.utils import get_bound_specs
class Command(BaseCommand):
@ -22,15 +21,13 @@ def flush_cache(apps, options):
if apps:
for app_label in apps:
app = cache.get_app(app_label)
models = [m for m in cache.get_models(app) if issubclass(m, ImageModel)]
for model in models:
for model in [m for m in cache.get_models(app)]:
print 'Flushing cache for "%s.%s"' % (app_label, model.__name__)
for obj in model.objects.order_by('-id'):
for spec in model._ik.specs:
prop = getattr(obj, spec.name(), None)
if prop is not None:
prop._delete()
for spec in get_bound_specs(obj):
if spec is not None:
spec._delete()
if spec.pre_cache:
prop._create()
spec._create()
else:
print 'Please specify on or more app names'

View file

@ -11,7 +11,7 @@ from django.utils.translation import ugettext_lazy as _
from imagekit.fields import ImageSpec
from imagekit.lib import *
from imagekit.options import Options
from imagekit.utils import img_to_fobj
from imagekit.utils import img_to_fobj, get_bound_specs
# Modify image file buffer size.
ImageFile.MAXBLOCK = getattr(settings, 'PIL_IMAGEFILE_MAXBLOCK', 256 * 2 ** 10)
@ -26,16 +26,12 @@ class ImageModelBase(ModelBase):
"""
def __init__(self, name, bases, attrs):
user_opts = getattr(self, 'IKOptions', None)
specs = []
default_image_field = getattr(user_opts, 'default_image_field', None)
for k, v in attrs.items():
if isinstance(v, ImageSpec):
specs.append(v)
elif not default_image_field and isinstance(v, models.ImageField):
if not default_image_field and isinstance(v, models.ImageField):
default_image_field = k
user_opts.specs = specs
user_opts.default_image_field = default_image_field
opts = Options(user_opts)
setattr(self, '_ik', opts)
@ -60,4 +56,4 @@ class ImageModel(models.Model):
@property
def _imgfields(self):
return set([spec._get_imgfield(self) for spec in self._ik.specs])
return set([spec._get_imgfield(self) for spec in get_bound_specs(self)])

View file

@ -37,9 +37,7 @@ class Options(object):
preprocessor_spec = None
save_count_as = None
specs = None
def __init__(self, opts):
for key, value in opts.__dict__.iteritems():
setattr(self, key, value)
self.specs = list(self.specs or [])