Browse Source

Fixed unicode handling in avatar images.

Rafał Pitoń 11 years ago
parent
commit
80c24c8ca8
2 changed files with 7 additions and 10 deletions
  1. 3 2
      misago/apps/usercp/avatar/views.py
  2. 4 8
      misago/utils/strings.py

+ 3 - 2
misago/apps/usercp/avatar/views.py

@@ -1,10 +1,10 @@
 from path import path
 from PIL import Image
+from unidecode import unidecode
 from zipfile import is_zipfile
 from django.core.exceptions import ValidationError
 from django.core.urlresolvers import reverse
 from django.shortcuts import redirect
-from django.utils.encoding import smart_str
 from django.utils.translation import ugettext as _
 from misago import messages
 from misago.apps.errors import error404
@@ -17,6 +17,7 @@ from misago.utils.avatars import resizeimage
 from misago.apps.usercp.template import RequestContext
 from misago.apps.usercp.avatar.forms import UploadAvatarForm
 
+
 def avatar_view(f):
     def decorator(*args, **kwargs):
         request = args[0]
@@ -111,7 +112,7 @@ def upload(request):
         if form.is_valid():
             request.user.delete_avatar_temp()
             image = form.cleaned_data['avatar_upload']
-            image_name, image_extension = path(smart_str(image.name.lower())).splitext()
+            image_name, image_extension = path(unidecode(image.name.lower())).splitext()
             image_name = '%s_tmp_%s%s' % (request.user.pk, random_string(8), image_extension)
             image_path = settings.MEDIA_ROOT + 'avatars/' + image_name
             request.user.avatar_temp = image_name

+ 4 - 8
misago/utils/strings.py

@@ -1,15 +1,11 @@
+from unidecode import unidecode
 from django.template.defaultfilters import slugify as django_slugify
 from django.utils import crypto
-try:
-    from unidecode import unidecode
-    use_unidecode = True
-except ImportError:
-    use_unidecode = False
+
 
 def slugify(string):
     string = unicode(string)
-    if use_unidecode:
-        string = unidecode(string)
+    string = unidecode(string)
     return django_slugify(string.replace('_', ' '))
 
 
@@ -30,4 +26,4 @@ def html_escape(html):
     html = html.replace('&', '&')
     html = html.replace('<', '&lt;')
     html = html.replace('>', '&gt;')
-    return html.replace('"', '&quot;')
+    return html.replace('"', '&quot;')