示例#1
0
def render_primary(request, extra_context={}, user=None, size=80, *args, **kwargs):
    size = int(size)
    avatar = get_primary_avatar(user, size=size)
    if avatar:
    # FIXME: later, add an option to render the resized avatar dynamically
    # instead of redirecting to an already created static file. This could
    # be useful in certain situations, particulary if there is a CDN and
    # we want to minimize the storage usage on our static server, letting
    # the CDN store those files instead
        return HttpResponseRedirect(avatar.avatar_url(size))
    else:
        url = get_default_avatar_url()
        return HttpResponseRedirect(url)
示例#2
0
def avatar_url(user, size=80):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        return avatar.avatar_url(size)
    else:
        if AVATAR_GRAVATAR_BACKUP:
            params = {'s': str(size)}
            if AVATAR_GRAVATAR_DEFAULT:
                params['d'] = AVATAR_GRAVATAR_DEFAULT
            return "http://www.gravatar.com/avatar/%s/?%s" % (
                md5_constructor(user.email).hexdigest(),
                urllib.urlencode(params))
        else:
            return get_default_avatar_url()