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:
Alex Iribarren 2026-01-07 21:46:42 +01:00 committed by GitHub
parent 45e741a342
commit 14495e8106
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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):