def _generate_image_filename(self, url_path, file):
if callable(self._image_upload_to):
raise Exception('Callable upload_to fields are not supported')
root_path, extension = posixpath.splitext(url_path)
if file:
# Workaround: imghdr expects the files position on 0
file.seek(0)
extension = imghdr.what(file) or 'jpeg'
basename = posixpath.basename(root_path)
if not basename:
basename = 'bplan'
dirname = datetime.datetime.now().strftime(self._image_upload_to)
filename = posixpath.join(dirname, basename + '.' + extension)
return self._image_storage.get_available_name(filename)
评论列表
文章目录