From 187e445c9ff5a93fe13a00c51ab43bd9dc4ceafa Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 19 Feb 2020 20:12:52 -0800 Subject: [PATCH] Refetch GitHub avatar image when active avatar is not found --- app/dashboard/models.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/dashboard/models.py b/app/dashboard/models.py index 28e9599f652..5edfe12a537 100644 --- a/app/dashboard/models.py +++ b/app/dashboard/models.py @@ -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 @@ -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