Commit 39932a6146205b00392eac36c85557a9ddd111ff
1 parent
d9a7dc25
Exists in
master
and in
39 other branches
Using cStringIO on badge forms
Showing
1 changed file
with
8 additions
and
2 deletions
Show diff stats
src/badger/forms.py
1 | +# -*- coding: utf-8 -*- | |
2 | + | |
1 | 3 | import base64 |
2 | -import StringIO | |
3 | 4 | |
4 | 5 | from django import forms |
5 | 6 | from django.utils.translation import ugettext_lazy as _ |
... | ... | @@ -8,6 +9,11 @@ from PIL import Image |
8 | 9 | |
9 | 10 | from .models import Badge |
10 | 11 | |
12 | +try: | |
13 | + from cStringIO import StringIO | |
14 | +except ImportError: | |
15 | + from StringIO import StringIO | |
16 | + | |
11 | 17 | |
12 | 18 | class BadgeForm(forms.ModelForm): |
13 | 19 | image = forms.ImageField(label=_(u'Image'), required=False) |
... | ... | @@ -31,7 +37,7 @@ class BadgeForm(forms.ModelForm): |
31 | 37 | if self.cleaned_data['image']: |
32 | 38 | img = Image.open(self.cleaned_data['image']) |
33 | 39 | img = img.resize((50, 50), Image.ANTIALIAS) |
34 | - f = StringIO.StringIO() | |
40 | + f = StringIO() | |
35 | 41 | img.save(f, 'png') |
36 | 42 | instance.image_base64 = f.getvalue().encode('base64') |
37 | 43 | f.close() | ... | ... |