~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to wlscreens/models.py

  • Committer: kaputtnik
  • Date: 2019-06-14 18:40:56 UTC
  • mfrom: (532.1.31 widelands)
  • Revision ID: kaputtnik-20190614184056-l0ha8pm5zais9mxk
Adapted code for use with python 3.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
from django.template.defaultfilters import slugify
4
4
from PIL import Image
5
 
from PIL.Image import core as _imaging
6
 
from cStringIO import StringIO
7
 
from django.core.files.uploadedfile import SimpleUploadedFile, UploadedFile
 
5
from io import BytesIO
 
6
from django.core.files.uploadedfile import SimpleUploadedFile
8
7
from django.core.files.storage import FileSystemStorage
9
8
import os
10
9
from django.conf import settings
11
 
from django.urls import reverse
12
10
 
13
11
 
14
12
# Taken from django snippet 976
38
36
 
39
37
        return super(Category, self).save(*args, **kwargs)
40
38
 
41
 
    def __unicode__(self):
42
 
        return u"%s" % self.name
 
39
    def __str__(self):
 
40
        return "%s" % self.name
43
41
 
44
42
 
45
43
def screenshot_path(instance, filename):
97
95
            image.thumbnail(settings.THUMBNAIL_SIZE, Image.ANTIALIAS)
98
96
    
99
97
            # Save the thumbnail
100
 
            temp_handle = StringIO()
 
98
            temp_handle = BytesIO()
101
99
            image.save(temp_handle, 'png')
 
100
            image.close()
102
101
            temp_handle.seek(0)
103
102
    
104
103
            # Save to the thumbnail field
114
113
            pass
115
114
 
116
115
 
117
 
    def __unicode__(self):
118
 
        return u"%s:%s" % (self.category.name, self.name)
 
116
    def __str__(self):
 
117
        return "%s:%s" % (self.category.name, self.name)