Пример #1
0
def api_avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        url = avatar.avatar_url(size)
        date_uploaded = avatar.date_uploaded
        return url, False, date_uploaded
    else:
        return get_default_avatar_url(), True, None
Пример #2
0
def api_avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        url = avatar.avatar_url(size)
        date_uploaded = avatar.date_uploaded
        return url, False, date_uploaded
    else:
        return get_default_avatar_url(), True, None
Пример #3
0
    def testNormalImageUpload(self):
        response = upload_helper(self, "test.png")
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.redirect_chain), 1)
        self.assertEqual(response.context['upload_avatar_form'].errors, {})
        avatar = get_primary_avatar(self.user)

        self.assertNotEqual(avatar, None)
Пример #4
0
 def testNormalImageUpload(self):
     response = upload_helper(self, "test.png")
     self.failUnlessEqual(response.status_code, 200)
     self.failUnlessEqual(len(response.redirect_chain), 1)
     self.failUnlessEqual(response.context['upload_avatar_form'].errors, {})
     avatar = get_primary_avatar(self.user) 
    
     self.failIfEqual(avatar, None)
Пример #5
0
def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    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" % (hashlib.md5(
                user.email).hexdigest(), urllib.urlencode(params))
        else:
            return get_default_avatar_url()
Пример #6
0
def render_primary(request, extra_context={}, user=None, size=AVATAR_DEFAULT_SIZE, *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)
Пример #7
0
def render_primary(request, extra_context={}, user=None, size=AVATAR_DEFAULT_SIZE, *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)
Пример #8
0
def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    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" % (
                hashlib.md5(user.email).hexdigest(),
                urllib.urlencode(params))
        else:
            return get_default_avatar_url()
Пример #9
0
def api_avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    service_url = DTABLE_WEB_SERVICE_URL
    service_url = service_url.rstrip('/')

    # when store avatars in the media directory
    if not AVATAR_FILE_STORAGE:
        # urlparse('https://192.157.12.3:89/demo')
        # ParseResult(scheme='https', netloc='192.157.12.3:89', path='/demo', params='', query='', fragment='')
        parse_result = urlparse(service_url)
        service_url = '%s://%s' % (parse_result[0], parse_result[1])

    avatar = get_primary_avatar(user, size=size)
    if avatar:
        url = avatar.avatar_url(size)
        date_uploaded = avatar.date_uploaded
        # /media/avatars/6/9/5011f01afac2a506b9544c5ce21a0a/resized/32/109af9901c0fd38ab39d018f5cd4baf6.png
        return service_url + url, False, date_uploaded
    else:
        # /media/avatars/default.png
        return service_url + get_default_avatar_url(), True, None
Пример #10
0
def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        url = 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" % (
                hashlib.md5(user.email.encode('utf-8')).hexdigest(),
                urllib.parse.urlencode(params))
        else:
            url = get_default_avatar_url()

    # when store avatars in the media directory
    if not AVATAR_FILE_STORAGE:
        return url

    if SITE_ROOT != '/':
        return '/%s/%s' % (SITE_ROOT.strip('/'), url.strip('/'))
    else:
        return url
Пример #11
0
 def testNonExistingUser(self):
     a = get_primary_avatar("*****@*****.**")
     self.assertEqual(a, None)
Пример #12
0
 def testNonExistingUser(self):
     a = get_primary_avatar("*****@*****.**")
     self.failUnlessEqual(a, None)