def render(self, name, value, attrs=None):
"""
Renders custom widget with the image preview for uploaded images
or the default widget if the image has not yet been uploaded.
"""
# if the image is uploaded, the 'image' argument
# is an instance of GalleryImageFieldFile
if isinstance(value, fields.GalleryImageFieldFile):
# get image data
data = utils.create_image_data(value)
# fill the template and replace the default one
self.template_with_initial = self.template.format(
settings.CONF['preview_width'] + 14,
settings.CONF['preview_height'] + 14,
settings.CONF['preview_width'],
settings.CONF['preview_height'],
settings.CONF['preview_height'],
html.escape(json.dumps(data)),
utils.create_static_url("content_gallery/img/zoom.png"),
settings.CONF['preview_width'] - 55
)
# render the widget
return super().render(name, value, attrs)
评论列表
文章目录