def get_avatar(self): weibo = self.get_weibo() if (weibo is not None) and (weibo.avatar is not None) and (len(weibo.avatar) > 0): return weibo.avatar try: return gravatar_for_email(self.email.encode('utf-8')) except Exception, e: logger.exception(self.username + ' get_avtar error ') return ''
def avatar(email, size): avatar_url = "" if email: user = User.objects.get(email=email) profile = user.get_profile() if profile.avatar: im = get_thumbnail(profile.avatar, '{}x{}'.format(size, size), crop='center', quality=99) avatar_url = im.url + "?" else: avatar_url = gravatar_for_email(email, size) return avatar_url
def avatar_url(self): """Returns the gravar address of email""" return gravatar_for_email(self.user.email, size=40)
def avatar_url(self): return gravatar_for_email(self.user.email, size=40)
def get_url(user, source): """ Get avatar URL """ if source in settings.SOCIAL_AUTH_BACKENDS: social_user = user.social_auth.filter(provider=source).first() if not social_user: raise Exception("Social User Binding Not Found") if source == 'facebook': try: # Get Facebook profile picture URL graph = facebook.GraphAPI(social_user.extra_data['access_token']) graph_data = graph.get_object( 'me/picture', width=settings.AVATAR_SIZE_ORIGINAL, height=settings.AVATAR_SIZE_ORIGINAL, redirect='false', ) image_url = graph_data['data']['url'] except StandardError as e: raise Exception(str(e)) elif source == 'twitter': try: # Get Twitter profile picture URL api = twitter.Api( consumer_key=settings.SOCIAL_AUTH_TWITTER_KEY, consumer_secret=settings.SOCIAL_AUTH_TWITTER_SECRET, access_token_key=social_user.extra_data['access_token']['oauth_token'], access_token_secret=social_user.extra_data['access_token']['oauth_token_secret'], ) api_data = api.GetUser(user_id=social_user.uid).GetProfileImageUrl() image_url = api_data.replace('_normal', '') except Exception as e: raise Exception(str(e)) elif source == 'google-oauth2': # Get Google+ profile picture URL api_url = 'https://profiles.google.com/s2/photos/profile/%s' % social_user.extra_data['id'] request = requests.get(api_url) if request.status_code is 200: image_url = request.url else: raise Exception('Google Avatar Not Found') elif source == 'gravatar': # Get from Gravatar image_url = gravatar.gravatar_for_email(user.email, size=settings.AVATAR_SIZE_ORIGINAL, default=False) elif source == 'url': # Get from URL image_url = user.binding.url else: raise Exception("Unknown Avatar Source") return image_url