(email, size=40)
获得gravatar头像
获得gravatar头像
获得gravatar头像
def gravatar_url(email, size=40):
    """获得gravatar头像"""
    cachekey = 'gravatat/' + email
    if cache.get(cachekey):
        return cache.get(cachekey)
    else:
        usermodels = OAuthUser.objects.filter(email=email)
        if usermodels:
            o = list(filter(lambda x: x.picture is not None, usermodels))
            if o:
                return o[0].picture
        email = email.encode('utf-8')

        default = "https://resource.lylinux.net/image/2017/03/26/120117.jpg".encode(
            'utf-8')

        url = "https://www.gravatar.com/avatar/%s?%s" % (hashlib.md5(
            email.lower()).hexdigest(), urllib.parse.urlencode({'d': default, 's': str(size)}))
        cache.set(cachekey, url, 60 * 60 * 10)
        return url
def gravatar_url ( email , size = 40 ) : cachekey = 'gravatat/' + email if cache . get ( cachekey ) : return cache . get ( cachekey ) else : usermodels = OAuthUser . objects . filter ( email = email ) if usermodels : o = list ( filter ( lambda x : x . picture is not None , usermodels ) ) if o : return o [ 0 ] . picture email = email . encode ( 'utf-8' ) default = "https://resource.lylinux.net/image/2017/03/26/120117.jpg" . encode ( 'utf-8' ) url = "https://www.gravatar.com/avatar/%s?%s" % ( hashlib . md5 ( email . lower ( ) ) . hexdigest ( ) , urllib . parse . urlencode ( { 'd' : default , 's' : str ( size ) } ) ) cache . set ( cachekey , url , 60 * 60 * 10 ) return url