Adding the AVATAR_GRAVATAR_FIELD setting to define the user field used to get

the gravatar email.
This commit is contained in:
toogy 2014-03-17 19:58:38 +05:30
parent 206682ce0a
commit f72a2cdd34
3 changed files with 8 additions and 2 deletions

View file

@ -8,6 +8,7 @@ class AvatarConf(AppConf):
DEFAULT_SIZE = 80
RESIZE_METHOD = Image.ANTIALIAS
STORAGE_DIR = 'avatars'
GRAVATAR_FIELD = 'email'
GRAVATAR_BASE_URL = 'http://www.gravatar.com/avatar/'
GRAVATAR_BACKUP = True
GRAVATAR_DEFAULT = None

View file

@ -31,8 +31,8 @@ def avatar_url(user, size=settings.AVATAR_DEFAULT_SIZE):
params = {'s': str(size)}
if settings.AVATAR_GRAVATAR_DEFAULT:
params['d'] = settings.AVATAR_GRAVATAR_DEFAULT
path = "%s/?%s" % (hashlib.md5(force_bytes(user.email)).hexdigest(),
urlencode(params))
path = "%s/?%s" % (hashlib.md5(force_bytes(
getattr(settings.GRAVATAR_FIELD))).hexdigest(), urlencode(params))
return urljoin(settings.AVATAR_GRAVATAR_BASE_URL, path)
return get_default_avatar_url()

View file

@ -117,6 +117,11 @@ AVATAR_DEFAULT_URL
The default URL to default to if ``AVATAR_GRAVATAR_BACKUP`` is set to False
and there is no ``Avatar`` instance found in the system for the given user.
AVATAR_GRAVATAR_FIELD
The name of the user's field containing the gravatar email. Defaults to
``email``. If you put, for example, ``gravatar``, django-avatar will get the
user's gravatar in ``user.gravatar``.
Management Commands
-------------------