Override __bobo_traverse__ to provide custom URL lookup
Mon, Oct 2, 2006,
100 Words
This technique is lifted from ATContentTypes/content/image.py
def __bobo_traverse__(self, REQUEST, name):
"""Transparent access to image scales
"""
if name.startswith('image'):
field = self.getField('image')
image = None
if name == 'image':
image = field.getScale(self)
else:
scalename = name[len('image_'):]
if scalename in field.getAvailableSizes(self):
image = field.getScale(self, scale=scalename)
if image is not None and not isinstance(image, basestring):
# image might be None or '' for empty images
return image
return ATCTFileContent.__bobo_traverse__(self, REQUEST, name)