Commits

Simone Marzola committed b07c5a7

correct thumbnails s3_keys handling

  • Participants
  • Parent commits f6d45d2

Comments (0)

Files changed (1)

tgext/datahelpers/remote_attachments.py

         self.thumb_local_path = os.path.join(self.attachment_dir, thumb_filename)
         self.thumb_url = '/'.join([self.attachments_url, self.uuid, thumb_filename])
 
+    @cached_property
+    def s3_thumb_key(self):
+        bucket = self.s3_connection.get_bucket(self.s3_bucket)
+        key = Key(bucket)
+        key.key = self.thumb_local_path
+        return key
+
     def write(self):
         super(S3AttachedImage, self).write()
 
         thumbnail.save(temp_file)
         temp_file.seek(0)
 	temp_file.name = self.thumb_local_path
-        self.s3_key.set_contents_from_file(temp_file, policy='public-read')
+        self.s3_thumb_key.set_contents_from_file(temp_file, policy='public-read')
+
+    def unlink(self)
+        super(S3AttachedImage, self).unlink()
+        self.s3_thumb_key.delete()