mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-17 13:50:24 +00:00
This needs to be known earlier, when registering the source group, so we do it in `contribute_to_class` instead. Closes #188.
21 lines
685 B
Python
21 lines
685 B
Python
from ...cachefiles import ImageCacheFile
|
|
|
|
|
|
class ImageSpecFileDescriptor(object):
|
|
def __init__(self, field, attname, source_field_name):
|
|
self.attname = attname
|
|
self.field = field
|
|
self.source_field_name = source_field_name
|
|
|
|
def __get__(self, instance, owner):
|
|
if instance is None:
|
|
return self.field
|
|
else:
|
|
source = getattr(instance, self.source_field_name)
|
|
spec = self.field.get_spec(source=source)
|
|
file = ImageCacheFile(spec)
|
|
instance.__dict__[self.attname] = file
|
|
return file
|
|
|
|
def __set__(self, instance, value):
|
|
instance.__dict__[self.attname] = value
|