2013-02-08 23:15:00 +00:00
|
|
|
from ...cachefiles import ImageCacheFile
|
2012-02-14 02:47:53 +00:00
|
|
|
|
|
|
|
|
|
2012-02-17 23:39:51 +00:00
|
|
|
class ImageSpecFileDescriptor(object):
|
2013-04-03 04:21:04 +00:00
|
|
|
def __init__(self, field, attname, source_field_name):
|
2012-02-14 02:47:53 +00:00
|
|
|
self.attname = attname
|
|
|
|
|
self.field = field
|
2013-04-03 04:21:04 +00:00
|
|
|
self.source_field_name = source_field_name
|
2012-02-14 02:47:53 +00:00
|
|
|
|
|
|
|
|
def __get__(self, instance, owner):
|
|
|
|
|
if instance is None:
|
|
|
|
|
return self.field
|
|
|
|
|
else:
|
2013-04-03 04:21:04 +00:00
|
|
|
source = getattr(instance, self.source_field_name)
|
2013-01-24 02:35:38 +00:00
|
|
|
spec = self.field.get_spec(source=source)
|
2013-02-08 23:15:00 +00:00
|
|
|
file = ImageCacheFile(spec)
|
2012-10-17 03:51:26 +00:00
|
|
|
instance.__dict__[self.attname] = file
|
|
|
|
|
return file
|
2012-02-18 01:07:50 +00:00
|
|
|
|
|
|
|
|
def __set__(self, instance, value):
|
|
|
|
|
instance.__dict__[self.attname] = value
|