mirror of
https://github.com/jazzband/django-avatar.git
synced 2026-03-16 22:20:30 +00:00
Convert the cache key into a smart str before calculating the md5 hash.
This commit is contained in:
parent
df39a60521
commit
6512c38dcb
2 changed files with 6 additions and 3 deletions
|
|
@ -1,6 +1,7 @@
|
|||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.utils.hashcompat import md5_constructor
|
||||
from django.utils.encoding import smart_str
|
||||
from django.template.defaultfilters import slugify
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
|
|
@ -10,14 +11,16 @@ from avatar.settings import (AVATAR_DEFAULT_URL, AVATAR_CACHE_TIMEOUT,
|
|||
|
||||
cached_funcs = set()
|
||||
|
||||
|
||||
def get_cache_key(user_or_username, size, prefix):
|
||||
"""
|
||||
Returns a cache key consisten of a username and image size.
|
||||
"""
|
||||
if isinstance(user_or_username, User):
|
||||
user_or_username = user_or_username.username
|
||||
key = '%s_%s_%s' % (prefix, user_or_username, size)
|
||||
return '%s_%s' % (slugify(key)[:100], md5_constructor(key).hexdigest())
|
||||
key = u'%s_%s_%s' % (prefix, user_or_username, size)
|
||||
return u'%s_%s' % (slugify(key)[:100],
|
||||
md5_constructor(smart_str(key)).hexdigest())
|
||||
|
||||
|
||||
def cache_result(func):
|
||||
|
|
|
|||
2
setup.py
2
setup.py
|
|
@ -1,6 +1,6 @@
|
|||
from setuptools import setup, find_packages
|
||||
|
||||
version = '2.0a8'
|
||||
version = '2.0a9'
|
||||
|
||||
LONG_DESCRIPTION = """
|
||||
Using django-avatar
|
||||
|
|
|
|||
Loading…
Reference in a new issue