Browse Source

Cache images' URL.

pull/374/head
Jairo Llopis 9 years ago
parent
commit
979b840253
  1. 12
      base_multi_image/models/image.py

12
base_multi_image/models/image.py

@ -104,13 +104,19 @@ class Image(models.Model):
@api.multi
def _get_image_from_url(self):
if self.url:
return self._get_image_from_url_cached(self.url)
@api.model
@tools.ormcache(skiparg=1)
def _get_image_from_url_cached(self, url):
"""Allow to download an image and cache it by its URL."""
if url:
try:
(filename, header) = urllib.urlretrieve(self.url)
(filename, header) = urllib.urlretrieve(url)
with open(filename, 'rb') as f:
return base64.b64encode(f.read())
except:
_logger.error("URL %s cannot be fetched", self.url,
_logger.error("URL %s cannot be fetched", url,
exc_info=True)
return False

Loading…
Cancel
Save