|
@@ -1,9 +1,11 @@
|
|
|
|
+from io import BytesIO
|
|
|
|
+
|
|
from django.conf import settings
|
|
from django.conf import settings
|
|
from django.core.files import File
|
|
from django.core.files import File
|
|
from django.core.files.base import ContentFile
|
|
from django.core.files.base import ContentFile
|
|
from django.core.urlresolvers import reverse
|
|
from django.core.urlresolvers import reverse
|
|
from django.db import models
|
|
from django.db import models
|
|
-from django.utils import six, timezone
|
|
|
|
|
|
+from django.utils import timezone
|
|
from django.utils.crypto import get_random_string
|
|
from django.utils.crypto import get_random_string
|
|
from PIL import Image
|
|
from PIL import Image
|
|
|
|
|
|
@@ -79,12 +81,9 @@ class Attachment(models.Model):
|
|
thumbnail = Image.open(upload)
|
|
thumbnail = Image.open(upload)
|
|
thumbnail.thumbnail((500, 500))
|
|
thumbnail.thumbnail((500, 500))
|
|
|
|
|
|
- if six.PY3:
|
|
|
|
- thumb_stream = six.StringIO()
|
|
|
|
- else:
|
|
|
|
- thumb_stream = six.BytesIO()
|
|
|
|
|
|
+ thumb_stream = BytesIO()
|
|
thumbnail.save(thumb_stream, fileformat)
|
|
thumbnail.save(thumb_stream, fileformat)
|
|
|
|
|
|
thumb_secret = get_random_string(settings.MISAGO_ATTACHMENT_SECRET_LENGTH)
|
|
thumb_secret = get_random_string(settings.MISAGO_ATTACHMENT_SECRET_LENGTH)
|
|
thumb_filename = '.'.join([thumb_secret, fileformat])
|
|
thumb_filename = '.'.join([thumb_secret, fileformat])
|
|
- self.thumbnail = ContentFile(thumb_stream, thumb_filename)
|
|
|
|
|
|
+ self.thumbnail = ContentFile(thumb_stream.get_value(), thumb_filename)
|