mirror of
https://github.com/jazzband/django-avatar.git
synced 2026-05-05 22:24:46 +00:00
Fixed some Python 3 bug.
This commit is contained in:
parent
5e2785e5a5
commit
a47e2e2811
6 changed files with 19 additions and 15 deletions
|
|
@ -15,12 +15,12 @@ def avatar_img(avatar, size):
|
|||
if not avatar.thumbnail_exists(size):
|
||||
avatar.create_thumbnail(size)
|
||||
return mark_safe('<img src="%s" alt="%s" width="%s" height="%s" />' %
|
||||
(avatar.avatar_url(size), unicode(avatar), size, size))
|
||||
(avatar.avatar_url(size), avatar, size, size))
|
||||
|
||||
|
||||
class UploadAvatarForm(forms.Form):
|
||||
|
||||
avatar = forms.ImageField(label=_(u"avatar"))
|
||||
avatar = forms.ImageField(label=_("avatar"))
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.user = kwargs.pop('user')
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@ from avatar.settings import AUTO_GENERATE_AVATAR_SIZES
|
|||
|
||||
|
||||
class Command(NoArgsCommand):
|
||||
help = "Regenerates avatar thumbnails for the sizes specified in " + \
|
||||
"settings.AUTO_GENERATE_AVATAR_SIZES."
|
||||
help = ("Regenerates avatar thumbnails for the sizes specified in "
|
||||
"settings.AUTO_GENERATE_AVATAR_SIZES.")
|
||||
|
||||
def handle_noargs(self, **options):
|
||||
for avatar in Avatar.objects.all():
|
||||
for size in AUTO_GENERATE_AVATAR_SIZES:
|
||||
print "Rebuilding Avatar id=%s at size %s." % (avatar.id, size)
|
||||
print("Rebuilding Avatar id=%s at size %s." % (avatar.id, size))
|
||||
avatar.create_thumbnail(size)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from django.core.files.base import ContentFile
|
|||
from django.core.files.storage import get_storage_class
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils.encoding import smart_str
|
||||
from django.utils import six
|
||||
from django.db.models import signals
|
||||
|
||||
from avatar.util import get_username
|
||||
|
|
@ -86,7 +87,7 @@ class Avatar(models.Model):
|
|||
date_uploaded = models.DateTimeField(default=now)
|
||||
|
||||
def __unicode__(self):
|
||||
return _(u'Avatar for %s') % self.user
|
||||
return _(six.u('Avatar for %s')) % self.user
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
avatars = Avatar.objects.filter(user=self.user)
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@ import urlparse
|
|||
import hashlib
|
||||
|
||||
from django import template
|
||||
from django.template.loader import render_to_string
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.template.loader import render_to_string
|
||||
from django.utils import six
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from avatar.settings import (AVATAR_GRAVATAR_BACKUP, AVATAR_GRAVATAR_DEFAULT,
|
||||
AVATAR_DEFAULT_SIZE, AVATAR_GRAVATAR_BASE_URL)
|
||||
|
|
@ -73,7 +74,7 @@ def primary_avatar(user, size=AVATAR_DEFAULT_SIZE):
|
|||
work for us. If that special view is then cached by a CDN for instance,
|
||||
we will avoid many db calls.
|
||||
"""
|
||||
alt = unicode(user)
|
||||
alt = six.text_type(user)
|
||||
url = reverse('avatar_render_primary', kwargs={'user': user, 'size': size})
|
||||
return """<img src="%s" alt="%s" width="%s" height="%s" />""" % (url, alt,
|
||||
size, size)
|
||||
|
|
@ -109,6 +110,6 @@ class UsersAvatarObjectNode(template.Node):
|
|||
context[key] = avatar[0]
|
||||
else:
|
||||
context[key] = None
|
||||
return u""
|
||||
return six.text_type()
|
||||
|
||||
register.tag('primary_avatar_object', primary_avatar_object)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import hashlib
|
|||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.utils.encoding import smart_str
|
||||
from django.utils import six
|
||||
from django.template.defaultfilters import slugify
|
||||
|
||||
try:
|
||||
|
|
@ -45,9 +46,9 @@ def get_cache_key(user_or_username, size, prefix):
|
|||
"""
|
||||
if isinstance(user_or_username, get_user_model()):
|
||||
user_or_username = get_username(user_or_username)
|
||||
key = u'%s_%s_%s' % (prefix, user_or_username, size)
|
||||
return u'%s_%s' % (slugify(key)[:100],
|
||||
hashlib.md5(smart_str(key)).hexdigest())
|
||||
key = six.u('%s_%s_%s') % (prefix, user_or_username, size)
|
||||
return six.u('%s_%s') % (slugify(key)[:100],
|
||||
hashlib.md5(smart_str(key)).hexdigest())
|
||||
|
||||
|
||||
def cache_result(func):
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from django.core.files.base import ContentFile
|
||||
from django.http import HttpResponse, Http404
|
||||
from django.shortcuts import get_object_or_404, render, redirect
|
||||
from django.utils import six
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
|
|
@ -144,10 +145,10 @@ def delete(request, extra_context=None, next_override=None, *args, **kwargs):
|
|||
if request.method == 'POST':
|
||||
if delete_avatar_form.is_valid():
|
||||
ids = delete_avatar_form.cleaned_data['choices']
|
||||
if unicode(avatar.id) in ids and avatars.count() > len(ids):
|
||||
if six.text_type(avatar.id) in ids and avatars.count() > len(ids):
|
||||
# Find the next best avatar, and set it as the new primary
|
||||
for a in avatars:
|
||||
if unicode(a.id) not in ids:
|
||||
if six.text_type(a.id) not in ids:
|
||||
a.primary = True
|
||||
a.save()
|
||||
avatar_updated.send(sender=Avatar, user=request.user, avatar=avatar)
|
||||
|
|
|
|||
Loading…
Reference in a new issue