Exemple #1
0
 def save_thumb_content(self, filename, content_file):
     ext = os.path.splitext(filename)[1]
     temp_dir = os.path.join(settings.MEDIA_ROOT, 'tmp')
     util.ensure_dir_exists(temp_dir)
     fd, path = tempfile.mkstemp(prefix='', dir=temp_dir, suffix=ext)
     os.close(fd)
     content_file.seek(0)
     util.copy_obj(path, content_file)
     self.submitted_thumb_path = os.path.basename(path)
     try:
         self.resize_submitted_thumb()
     except ValueError:
         self.submitted_thumb_path = None
     except:
         self.submitted_thumb_path = None
         raise
Exemple #2
0
 def save_thumb_content(self, filename, content_file):
     ext = os.path.splitext(filename)[1]
     temp_dir = os.path.join(settings.MEDIA_ROOT, 'tmp')
     util.ensure_dir_exists(temp_dir)
     fd, path = tempfile.mkstemp(prefix='', dir=temp_dir, suffix=ext)
     os.close(fd)
     content_file.seek(0)
     util.copy_obj(path, content_file)
     self.submitted_thumb_path = os.path.basename(path)
     try:
         self.resize_submitted_thumb()
     except ValueError:
         self.submitted_thumb_path = None
     except:
         self.submitted_thumb_path = None
         raise
Exemple #3
0
 def download_thumbnail(self, redownload=False):
     if self.thumbnail_url is None:
         return
     if (not self.thumbnail_exists()) or redownload:
         util.ensure_dir_exists(settings.IMAGE_DOWNLOAD_CACHE_DIR)
         cache_path = os.path.join(settings.IMAGE_DOWNLOAD_CACHE_DIR,
                 util.hash_string(self.thumbnail_url))
         if os.path.exists(cache_path) and not redownload:
             image_file = file(cache_path, 'rb')
         else:
             url = self.thumbnail_url[:8] + self.thumbnail_url[8:].replace(
                 '//', '/')
             image_file = try_to_download_thumb(url)
             if image_file is None:
                 return
             util.copy_obj(cache_path, image_file)
         self.save_thumbnail(image_file)
Exemple #4
0
 def download_thumbnail(self, redownload=False):
     if self.thumbnail_url is None:
         return
     if (not self.thumbnail_exists()) or redownload:
         util.ensure_dir_exists(settings.IMAGE_DOWNLOAD_CACHE_DIR)
         cache_path = os.path.join(settings.IMAGE_DOWNLOAD_CACHE_DIR,
                                   util.hash_string(self.thumbnail_url))
         if os.path.exists(cache_path) and not redownload:
             image_file = file(cache_path, 'rb')
         else:
             url = self.thumbnail_url[:8] + self.thumbnail_url[8:].replace(
                 '//', '/')
             image_file = try_to_download_thumb(url)
             if image_file is None:
                 return
             util.copy_obj(cache_path, image_file)
         self.save_thumbnail(image_file)
Exemple #5
0
 def _save_original_thumbnail(self, image_file):
     dest = self.thumb_path('original')
     util.copy_obj(dest, image_file)
     self._save_to_s3('original')