mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-05-20 02:11:53 +00:00
"source" now refers to the file itself
This commit is contained in:
parent
184c13dd4e
commit
d80f2f26a9
7 changed files with 20 additions and 20 deletions
|
|
@ -30,7 +30,7 @@ class AdminThumbnail(object):
|
||||||
raise Exception('The property %s is not defined on %s.' %
|
raise Exception('The property %s is not defined on %s.' %
|
||||||
(self.image_field, obj.__class__.__name__))
|
(self.image_field, obj.__class__.__name__))
|
||||||
|
|
||||||
original_image = getattr(thumbnail, 'source_file', None) or thumbnail
|
original_image = getattr(thumbnail, 'source', None) or thumbnail
|
||||||
template = self.template or 'imagekit/admin/thumbnail.html'
|
template = self.template or 'imagekit/admin/thumbnail.html'
|
||||||
|
|
||||||
return render_to_string(template, {
|
return render_to_string(template, {
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,10 @@ class Command(BaseCommand):
|
||||||
for spec_id in specs:
|
for spec_id in specs:
|
||||||
self.stdout.write('Validating spec: %s\n' % spec_id)
|
self.stdout.write('Validating spec: %s\n' % spec_id)
|
||||||
for source_group in source_group_registry.get(spec_id):
|
for source_group in source_group_registry.get(spec_id):
|
||||||
for source_file in source_group.files():
|
for source in source_group.files():
|
||||||
if source_file:
|
if source:
|
||||||
spec = generator_registry.get(spec_id, source_file=source_file) # TODO: HINTS! (Probably based on source, so this will need to be moved into loop below.)
|
spec = generator_registry.get(spec_id, source=source) # TODO: HINTS! (Probably based on source, so this will need to be moved into loop below.)
|
||||||
self.stdout.write(' %s\n' % source_file)
|
self.stdout.write(' %s\n' % source)
|
||||||
try:
|
try:
|
||||||
# TODO: Allow other validation actions through command option
|
# TODO: Allow other validation actions through command option
|
||||||
GeneratedImageCacheFile(spec).validate()
|
GeneratedImageCacheFile(spec).validate()
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ class ImageSpecFileDescriptor(object):
|
||||||
else:
|
else:
|
||||||
field_name = getattr(self.field, 'source', None)
|
field_name = getattr(self.field, 'source', None)
|
||||||
if field_name:
|
if field_name:
|
||||||
source_file = getattr(instance, field_name)
|
source = getattr(instance, field_name)
|
||||||
else:
|
else:
|
||||||
image_fields = [getattr(instance, f.attname) for f in
|
image_fields = [getattr(instance, f.attname) for f in
|
||||||
instance.__class__._meta.fields if
|
instance.__class__._meta.fields if
|
||||||
|
|
@ -28,8 +28,8 @@ class ImageSpecFileDescriptor(object):
|
||||||
' ImageSpecField.' % (instance.__class__.__name__,
|
' ImageSpecField.' % (instance.__class__.__name__,
|
||||||
self.attname))
|
self.attname))
|
||||||
else:
|
else:
|
||||||
source_file = image_fields[0]
|
source = image_fields[0]
|
||||||
spec = self.field.get_spec(source_file=source_file) # TODO: What "hints" should we pass here?
|
spec = self.field.get_spec(source=source) # TODO: What "hints" should we pass here?
|
||||||
file = GeneratedImageCacheFile(spec)
|
file = GeneratedImageCacheFile(spec)
|
||||||
instance.__dict__[self.attname] = file
|
instance.__dict__[self.attname] = file
|
||||||
return file
|
return file
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ class SourceGroupRegistry(object):
|
||||||
def before_access_receiver(self, sender, generator, file, **kwargs):
|
def before_access_receiver(self, sender, generator, file, **kwargs):
|
||||||
generator.image_cache_strategy.invoke_callback('before_access', file)
|
generator.image_cache_strategy.invoke_callback('before_access', file)
|
||||||
|
|
||||||
def source_group_receiver(self, sender, source_file, signal, info, **kwargs):
|
def source_group_receiver(self, sender, source, signal, info, **kwargs):
|
||||||
"""
|
"""
|
||||||
Redirects signals dispatched on sources to the appropriate specs.
|
Redirects signals dispatched on sources to the appropriate specs.
|
||||||
|
|
||||||
|
|
@ -102,14 +102,14 @@ class SourceGroupRegistry(object):
|
||||||
if source_group not in self._source_groups:
|
if source_group not in self._source_groups:
|
||||||
return
|
return
|
||||||
|
|
||||||
for spec in (generator_registry.get(id, source_file=source_file, **info)
|
for spec in (generator_registry.get(id, source=source, **info)
|
||||||
for id in self._sources_groups[source_group]):
|
for id in self._sources_groups[source_group]):
|
||||||
event_name = {
|
event_name = {
|
||||||
source_created: 'source_created',
|
source_created: 'source_created',
|
||||||
source_changed: 'source_changed',
|
source_changed: 'source_changed',
|
||||||
source_deleted: 'source_deleted',
|
source_deleted: 'source_deleted',
|
||||||
}
|
}
|
||||||
spec._handle_source_event(event_name, source_file)
|
spec._handle_source_event(event_name, source)
|
||||||
|
|
||||||
|
|
||||||
class Register(object):
|
class Register(object):
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ class BaseImageSpec(object):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
# TODO: I don't like this interface. Is there a standard Python one? pubsub?
|
# TODO: I don't like this interface. Is there a standard Python one? pubsub?
|
||||||
def _handle_source_event(self, event_name, source_file):
|
def _handle_source_event(self, event_name, source):
|
||||||
file = GeneratedImageCacheFile(self)
|
file = GeneratedImageCacheFile(self)
|
||||||
self.image_cache_strategy.invoke_callback('on_%s' % event_name, file)
|
self.image_cache_strategy.invoke_callback('on_%s' % event_name, file)
|
||||||
|
|
||||||
|
|
@ -84,15 +84,15 @@ class ImageSpec(BaseImageSpec):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, source_file, **kwargs):
|
def __init__(self, source, **kwargs):
|
||||||
self.source_file = source_file
|
self.source = source
|
||||||
self.processors = self.processors or []
|
self.processors = self.processors or []
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
super(ImageSpec, self).__init__()
|
super(ImageSpec, self).__init__()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def cache_file_name(self):
|
def cache_file_name(self):
|
||||||
source_filename = self.source_file.name
|
source_filename = self.source.name
|
||||||
ext = suggest_extension(source_filename, self.format)
|
ext = suggest_extension(source_filename, self.format)
|
||||||
return os.path.normpath(os.path.join(
|
return os.path.normpath(os.path.join(
|
||||||
settings.IMAGEKIT_CACHE_DIR,
|
settings.IMAGEKIT_CACHE_DIR,
|
||||||
|
|
@ -104,7 +104,7 @@ class ImageSpec(BaseImageSpec):
|
||||||
|
|
||||||
def get_hash(self):
|
def get_hash(self):
|
||||||
return md5(pickle.dumps([
|
return md5(pickle.dumps([
|
||||||
self.source_file,
|
self.source,
|
||||||
self.kwargs,
|
self.kwargs,
|
||||||
self.processors,
|
self.processors,
|
||||||
self.format,
|
self.format,
|
||||||
|
|
@ -115,9 +115,9 @@ class ImageSpec(BaseImageSpec):
|
||||||
def generate(self):
|
def generate(self):
|
||||||
# TODO: Move into a generator base class
|
# TODO: Move into a generator base class
|
||||||
# TODO: Factor out a generate_image function so you can create a generator and only override the PIL.Image creating part. (The tricky part is how to deal with original_format since generator base class won't have one.)
|
# TODO: Factor out a generate_image function so you can create a generator and only override the PIL.Image creating part. (The tricky part is how to deal with original_format since generator base class won't have one.)
|
||||||
source_file = self.source_file
|
source = self.source
|
||||||
filename = self.kwargs.get('filename')
|
filename = self.kwargs.get('filename')
|
||||||
img = open_image(source_file)
|
img = open_image(source)
|
||||||
original_format = img.format
|
original_format = img.format
|
||||||
|
|
||||||
# Run the processors
|
# Run the processors
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ class ModelSignalRouter(object):
|
||||||
instance=instance,
|
instance=instance,
|
||||||
field_name=attname,
|
field_name=attname,
|
||||||
)
|
)
|
||||||
signal.send(sender=source_group, source_file=file, info=info)
|
signal.send(sender=source_group, source=file, info=info)
|
||||||
|
|
||||||
|
|
||||||
class ImageFieldSourceGroup(object):
|
class ImageFieldSourceGroup(object):
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ HTML_ATTRS_DELIMITER = 'with'
|
||||||
|
|
||||||
|
|
||||||
_kwarg_map = {
|
_kwarg_map = {
|
||||||
'from': 'source_file',
|
'from': 'source',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue