Skip to content

Commit

Permalink
Refetch GitHub avatar image when active avatar is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
KiChjang authored and octavioamu committed Feb 20, 2020
1 parent 01c06b4 commit 187e445
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import pytz
import requests
from app.utils import get_upload_filename
from avatar.models import SocialAvatar
from avatar.utils import get_user_github_avatar_image
from bleach import clean
from bs4 import BeautifulSoup
from dashboard.tokens import addr_to_token, token_by_name
Expand Down Expand Up @@ -3390,6 +3392,17 @@ def avatar_url(self):
return self.admin_override_avatar.url
if self.active_avatar:
return self.active_avatar.avatar_url
else:
github_avatar_img = get_user_github_avatar_image(self.handle)
if github_avatar_img:
try:
github_avatar = SocialAvatar.github_avatar(self, github_avatar_img)
github_avatar.save()
self.activate_avatar(github_avatar.pk)
self.save()
return self.active_avatar.avatar_url
except Exception as e:
logger.warning(f'Encountered ({e}) while attempting to save a user\'s github avatar')
return f"{settings.BASE_URL}dynamic/avatar/{self.handle}"

@property
Expand Down

0 comments on commit 187e445

Please sign in to comment.