2020-01-21 15:35:58 +09:00
|
|
|
import hashlib
|
|
|
|
|
|
|
|
from django.contrib.auth.models import AbstractUser
|
|
|
|
from django.utils.http import urlencode
|
|
|
|
|
|
|
|
from judge.models import Profile
|
|
|
|
from judge.utils.unicode import utf8bytes
|
|
|
|
from . import registry
|
|
|
|
|
|
|
|
|
|
|
|
@registry.function
|
2023-08-23 23:14:53 -05:00
|
|
|
def gravatar(profile, size=80, default=None, profile_image=None, email=None):
|
2023-08-23 22:14:09 -05:00
|
|
|
if profile_image:
|
2023-08-23 23:14:53 -05:00
|
|
|
return profile_image
|
2023-10-10 21:01:06 -05:00
|
|
|
if profile and profile.profile_image_url:
|
|
|
|
return profile.profile_image_url
|
2023-08-24 00:02:02 -05:00
|
|
|
if profile:
|
2023-10-10 19:37:36 -05:00
|
|
|
email = email or profile.email
|
2023-08-24 00:02:02 -05:00
|
|
|
if default is None:
|
2023-10-10 19:37:36 -05:00
|
|
|
default = profile.is_muted
|
2022-05-14 12:57:27 -05:00
|
|
|
gravatar_url = (
|
|
|
|
"//www.gravatar.com/avatar/"
|
|
|
|
+ hashlib.md5(utf8bytes(email.strip().lower())).hexdigest()
|
|
|
|
+ "?"
|
|
|
|
)
|
|
|
|
args = {"d": "identicon", "s": str(size)}
|
2020-01-21 15:35:58 +09:00
|
|
|
if default:
|
2022-05-14 12:57:27 -05:00
|
|
|
args["f"] = "y"
|
2020-01-21 15:35:58 +09:00
|
|
|
gravatar_url += urlencode(args)
|
|
|
|
return gravatar_url
|