mirror of
https://github.com/jazzband/django-avatar.git
synced 2026-03-16 22:20:30 +00:00
Enable parameters for LibRavatar (#255)
* Enable parameters for LibRavatar Added support for default parameters to LibRavatar * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
45e741a342
commit
14495e8106
1 changed files with 12 additions and 3 deletions
|
|
@ -68,7 +68,7 @@ class GravatarAvatarProvider(object):
|
|||
|
||||
class LibRAvatarProvider:
|
||||
"""
|
||||
Returns the url of an avatar by the Ravatar service.
|
||||
Returns the url of an avatar by the LibRavatar service.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
|
|
@ -87,8 +87,17 @@ class LibRAvatarProvider:
|
|||
baseurl = "http://" + hostname + ":" + port + "/avatar/"
|
||||
except Exception:
|
||||
baseurl = "https://seccdn.libravatar.org/avatar/"
|
||||
hash = hashlib.md5(email.strip().lower()).hexdigest()
|
||||
return baseurl + hash
|
||||
|
||||
params = {"s": str(width)}
|
||||
if settings.AVATAR_GRAVATAR_DEFAULT:
|
||||
params["d"] = settings.AVATAR_GRAVATAR_DEFAULT
|
||||
if settings.AVATAR_GRAVATAR_FORCEDEFAULT:
|
||||
params["f"] = "y"
|
||||
path = "%s/?%s" % (
|
||||
hashlib.md5(force_bytes(email.strip().lower())).hexdigest(),
|
||||
urlencode(params),
|
||||
)
|
||||
return urljoin(baseurl, path)
|
||||
|
||||
|
||||
class FacebookAvatarProvider(object):
|
||||
|
|
|
|||
Loading…
Reference in a new issue