コード例 #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
コード例 #2
0
ファイル: forms.py プロジェクト: kmshi/miroguide
 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
コード例 #3
0
ファイル: models.py プロジェクト: kmshi/miroguide
 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)
コード例 #4
0
ファイル: models.py プロジェクト: kmshi/miroguide
 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)