mirror of
https://github.com/jazzband/django-avatar.git
synced 2026-05-17 20:11:07 +00:00
Adding the AVATAR_GRAVATAR_FIELD setting to define the user field used to get
the gravatar email.
This commit is contained in:
parent
206682ce0a
commit
f72a2cdd34
3 changed files with 8 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
-------------------
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue