Add caching for user basic info
This commit is contained in:
parent
7f854c40dd
commit
ed287b6ff3
15 changed files with 110 additions and 33 deletions
|
@ -12,12 +12,12 @@ from . import registry
|
|||
def gravatar(profile, size=80, default=None, profile_image=None, email=None):
|
||||
if profile_image:
|
||||
return profile_image
|
||||
if profile and profile.profile_image:
|
||||
return profile.profile_image.url
|
||||
if profile and profile.cached_profile_image:
|
||||
return profile.cached_profile_image.url
|
||||
if profile:
|
||||
email = email or profile.user.email
|
||||
email = email or profile.email
|
||||
if default is None:
|
||||
default = profile.mute
|
||||
default = profile.is_muted
|
||||
gravatar_url = (
|
||||
"//www.gravatar.com/avatar/"
|
||||
+ hashlib.md5(utf8bytes(email.strip().lower())).hexdigest()
|
||||
|
|
|
@ -157,14 +157,14 @@ def item_title(item):
|
|||
@registry.render_with("user/link.html")
|
||||
def link_user(user):
|
||||
if isinstance(user, Profile):
|
||||
user, profile = user.user, user
|
||||
profile = user
|
||||
elif isinstance(user, AbstractUser):
|
||||
profile = user.profile
|
||||
elif type(user).__name__ == "ContestRankingProfile":
|
||||
user, profile = user.user, user
|
||||
profile = user
|
||||
else:
|
||||
raise ValueError("Expected profile or user, got %s" % (type(user),))
|
||||
return {"user": user, "profile": profile}
|
||||
return {"profile": profile}
|
||||
|
||||
|
||||
@registry.function
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue