mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-17 05:40:25 +00:00
Correct signal relaying
This commit is contained in:
parent
a59330cf2c
commit
440fcb19ef
2 changed files with 10 additions and 8 deletions
|
|
@ -23,7 +23,7 @@ class SpecRegistry(object):
|
|||
self._specs = {}
|
||||
self._sources = {}
|
||||
for signal in self.signals.keys():
|
||||
signal.connect(lambda *a, **k: self.source_receiver(signal, *a, **k))
|
||||
signal.connect(self.source_receiver)
|
||||
|
||||
def register(self, id, spec):
|
||||
if id in self._specs:
|
||||
|
|
@ -51,11 +51,12 @@ class SpecRegistry(object):
|
|||
self._sources[source] = set()
|
||||
self._sources[source].add(spec_id)
|
||||
|
||||
def source_receiver(self, signal, source, source_file):
|
||||
def source_receiver(self, sender, source_file, signal, **kwargs):
|
||||
source = sender
|
||||
if source not in self._sources:
|
||||
return
|
||||
|
||||
callback_name = self._signals[signal]
|
||||
callback_name = self.signals[signal]
|
||||
for spec in (self.get_spec(id) for id in self._sources[source]):
|
||||
spec.image_cache_strategy.invoke_callback(callback_name, source_file)
|
||||
|
||||
|
|
|
|||
|
|
@ -65,20 +65,20 @@ class ModelSignalRouter(object):
|
|||
new_hashes = self.update_source_hashes(instance)
|
||||
for attname, file in self.get_field_dict(instance).items():
|
||||
if created:
|
||||
self.dispatch_signal(source_created, sender, file)
|
||||
self.dispatch_signal(source_created, file, sender)
|
||||
elif old_hashes[attname] != new_hashes[attname]:
|
||||
self.dispatch_signal(source_changed, sender, file)
|
||||
self.dispatch_signal(source_changed, file, sender)
|
||||
|
||||
@ik_model_receiver
|
||||
def post_delete_receiver(self, sender, instance=None, **kwargs):
|
||||
for attname, file in self.get_field_dict(instance):
|
||||
self.dispatch_signal(source_deleted, sender, file)
|
||||
self.dispatch_signal(source_deleted, file, sender)
|
||||
|
||||
@ik_model_receiver
|
||||
def post_init_receiver(self, sender, instance=None, **kwargs):
|
||||
self.update_source_hashes(instance)
|
||||
|
||||
def dispatch_signal(self, signal, model_class, file):
|
||||
def dispatch_signal(self, signal, file, model_class):
|
||||
"""
|
||||
Dispatch the signal for each of the matching sources. Note that more
|
||||
than one source can have the same model and image_field; it's important
|
||||
|
|
@ -86,7 +86,8 @@ class ModelSignalRouter(object):
|
|||
|
||||
"""
|
||||
for source in self._sources:
|
||||
if source.model_class is model_class and source.image_field == file.attname:
|
||||
# TODO: Is it okay to require a field attribute on our file?
|
||||
if source.model_class is model_class and source.image_field == file.field.attname:
|
||||
signal.send(sender=source, source_file=file)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue