Cloned DMOJ
This commit is contained in:
parent
f623974b58
commit
49dc9ff10c
513 changed files with 132349 additions and 39 deletions
25
judge/jinja2/gravatar.py
Normal file
25
judge/jinja2/gravatar.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
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
|
||||
def gravatar(email, size=80, default=None):
|
||||
if isinstance(email, Profile):
|
||||
if default is None:
|
||||
default = email.mute
|
||||
email = email.user.email
|
||||
elif isinstance(email, AbstractUser):
|
||||
email = email.email
|
||||
|
||||
gravatar_url = '//www.gravatar.com/avatar/' + hashlib.md5(utf8bytes(email.strip().lower())).hexdigest() + '?'
|
||||
args = {'d': 'identicon', 's': str(size)}
|
||||
if default:
|
||||
args['f'] = 'y'
|
||||
gravatar_url += urlencode(args)
|
||||
return gravatar_url
|
Loading…
Add table
Add a link
Reference in a new issue