Example #1
0
 def get_avatar(self):
     """
     Gets avatar from Django Avatar or Facebook
     """
     if get_primary_avatar(self):
         return get_primary_avatar(self).avatar.url
     elif self.socialaccount_set.all().count() > 0:
         return utils.change_picture_size(
             self.socialaccount_set.all()[0].get_avatar_url())
     else:
         return 'http://placehold.it/75x75/'
Example #2
0
def get_user_avatar_url(user):
    the_avatar = get_primary_avatar(user, 80)
    if the_avatar :
        the_avatar = the_avatar.avatar_url(80)
    else:
        the_avatar = get_default_avatar_url()
    return the_avatar
Example #3
0
def get_user_avatar_url(user):
    the_avatar = get_primary_avatar(user, 80)
    if the_avatar :
        the_avatar = the_avatar.avatar_url(80)
    else:
        the_avatar = get_default_avatar_url()
    return the_avatar
Example #4
0
def avatar_print_url(user, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    tt = Orglogo.objects.filter(orgacronym=user.org_acronym)
    # if avatar:
    #     return avatar.avatar_url(size)
    # else:
    #     if tt.count()>0:
    #         return tt[0].logo_url(200)
    #     else:
    #         return get_default_avatar_url()

    if tt.count() > 0:
        return {
            'onpdf': str(tt[0].onpdf).lower(),
            'logo_url': tt[0].logo_url(size)
        }
    elif avatar:
        return {
            'onpdf': str(False).lower(),
            'logo_url': avatar.avatar_url(size)
        }
    else:
        return {
            'onpdf': str(False).lower(),
            'logo_url': get_default_avatar_url()
        }
Example #5
0
def render_primary(request, extra_context={}, user=None, size=AVATAR_DEFAULT_SIZE, *args, **kwargs):
    size = int(size)
    if not isinstance(user, User):
        try:
            user = get_user(user)
        except User.DoesNotExist:
            return None
    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:
        if AVATAR_GRAVATAR_BACKUP:
            params = {'s': str(size)}
            if AVATAR_GRAVATAR_DEFAULT:
                params['d'] = AVATAR_GRAVATAR_DEFAULT
            path = "%s/?%s" % (hashlib.md5(user.email).hexdigest(),
                               urllib.urlencode(params))
            url = urlparse.urljoin(AVATAR_GRAVATAR_BASE_URL, path)
        else:
            url = get_default_avatar_url()
        return HttpResponseRedirect(url)
Example #6
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)
Example #7
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)
Example #8
0
def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        if not avatar.thumbnail_exists(size):
            avatar.create_thumbnail(size)
        url = avatar.avatar_url(size)
        return url

    return get_default_avatar_url(user, size)
Example #9
0
 def test_normal_image_upload(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.assertIsNotNone(avatar)
     self.assertEqual(avatar.user, self.user)
     self.assertTrue(avatar.primary)
Example #10
0
 def field_to_native(self, obj, field_name):
     try:
         a_path = get_primary_avatar(obj, 50)
         if a_path:
             return self.to_native(a_path.avatar_url(50, 50))
         else:
             return self.to_native(get_default_avatar_url())
     except Avatar.DoesNotExist:
         return self.to_native(get_default_avatar_url())
Example #11
0
 def field_to_native(self, obj, field_name):
     try:
         a_path = get_primary_avatar(obj, 50)
         if a_path:
             return self.to_native(a_path.avatar_url(50, 50))
         else:
             return self.to_native(get_default_avatar_url())
     except Avatar.DoesNotExist:
         return self.to_native(get_default_avatar_url())
Example #12
0
 def test_normal_image_upload(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.assertIsNotNone(avatar)
     self.assertEqual(avatar.user, self.user)
     self.assertTrue(avatar.primary)
def test_ambassadors_list(db, client):
    test_country_name = "Austria"
    test_country_code = "AT"

    test_username = "******"
    test_email = "*****@*****.**"
    test_first_name = "Testko"
    test_last_name = "Test"
    test_full_name = test_first_name + " " + test_last_name

    test_ambassador = User.objects.create(
        username=test_username, email=test_email, first_name=test_first_name, last_name=test_last_name
    )
    test_ambassador_profile = UserProfile.objects.create(user=test_ambassador, country=test_country_code)

    group = Group.objects.get(name="ambassadors")
    group.user_set.add(test_ambassador)

    with open(local(__file__).dirname + "/../../static/img/team/alja.jpg") as fp:
        io = StringIO.StringIO()
        io.write(fp.read())
        uploaded_picture = InMemoryUploadedFile(io, None, "alja17.jpg", "jpeg", io.len, None)
        uploaded_picture.seek(0)

    avatar = Avatar(user=test_ambassador, primary=True)
    avatar.avatar.save(uploaded_picture.name, uploaded_picture)
    avatar.save()

    new_avatar = get_primary_avatar(test_ambassador, size=80)
    test_amb_avatar = new_avatar.avatar_url(80)

    response = client.get(reverse("web.ambassadors"))

    # We're expecting to the Ambassador under the right country,
    # with the right avatar and the right email contact
    expected_result = """
	<h2 class="clearfix">%s</h2>
	<div class="ambassador clearfix">
	<img src="%s" alt="%s" width="80" height="80" class="img-circle" />
	<h4>%s&nbsp;<span>&nbsp;<a alt="Send me an email" href="mailto:%s"><i class="fa fa-envelope"></i></a>
	""" % (
        test_country_name,
        test_amb_avatar,
        test_username,
        test_full_name,
        test_email,
    )

    expected_result = expected_result.replace("\t", "").replace("\n", "")
    ambassadors_content = response.content.replace("\t", "").replace("\n", "")

    # Check this test and modify it to integrating the Ambassadors page changes
    # assert expected_result in ambassadors_content

    test_ambassador.delete()
    avatar.delete()
Example #14
0
 def testDeletePrimaryAvatarAndNewPrimary(self):
     self.testThereCanBeOnlyOnePrimaryAvatar()
     primary = get_primary_avatar(self.user)
     oid = primary.id
     response = self.client.post(reverse("avatar_delete"), {"choices": [oid]})
     primaries = Avatar.objects.filter(user=self.user, primary=True)
     self.failUnlessEqual(len(primaries), 1)
     self.failIfEqual(oid, primaries[0].id)
     avatars = Avatar.objects.filter(user=self.user)
     self.failUnlessEqual(avatars[0].id, primaries[0].id)
Example #15
0
 def avatar_display(self, user):
     avatar = get_primary_avatar(user)
     try:
         if avatar and avatar.avatar:
             return '<img width="100" src="%s" />' % \
                 (settings.MEDIA_URL + str(avatar.avatar))
         else:
             return 'No Avatar'
     except Exception, e:
         raise
def test_ambassadors_list(db, client):
    test_country_name = "Austria"
    test_country_code = "AT"

    test_username = '******'
    test_email = '*****@*****.**'
    test_first_name = 'Testko'
    test_last_name = 'Test'
    test_full_name = test_first_name + " " + test_last_name

    test_ambassador = User.objects.create(username=test_username,
                                          email=test_email,
                                          first_name=test_first_name,
                                          last_name=test_last_name)
    test_ambassador_profile = UserProfile.objects.create(
        user=test_ambassador, country=test_country_code)

    group = Group.objects.get(name="ambassadors")
    group.user_set.add(test_ambassador)

    with open(local(__file__).dirname + '/../../static/img/team/alja.jpg') as fp:
        io = StringIO.StringIO()
        io.write(fp.read())
        uploaded_picture = InMemoryUploadedFile(
            io, None, "alja17.jpg", "jpeg", io.len, None)
        uploaded_picture.seek(0)

    avatar = Avatar(user=test_ambassador, primary=True)
    avatar.avatar.save(uploaded_picture.name, uploaded_picture)
    avatar.save()

    new_avatar = get_primary_avatar(test_ambassador, size=80)
    test_amb_avatar = new_avatar.avatar_url(80)

    response = client.get(reverse('web.ambassadors'))

    # We're expecting to the Ambassador under the right country,
    # with the right avatar and the right email contact
    expected_result = '''
	<h2 class="clearfix">%s</h2>
	<div class="ambassador clearfix">
	<img src="%s" alt="%s" width="80" height="80" class="img-circle" />
	<h4>%s&nbsp;<span>&nbsp;<a alt="Send me an email" href="mailto:%s"><i class="fa fa-envelope"></i></a>
	''' % (test_country_name, test_amb_avatar, test_username, test_full_name, test_email)

    expected_result = expected_result.replace('\t', '').replace('\n', '')
    ambassadors_content = response.content.replace('\t', '').replace('\n', '')

# Check this test and modify it to integrating the Ambassadors page changes
    # assert expected_result in ambassadors_content

    test_ambassador.delete()
    avatar.delete()
Example #17
0
 def testDeletePrimaryAvatarAndNewPrimary(self):
     self.testThereCanBeOnlyOnePrimaryAvatar()
     primary = get_primary_avatar(self.user)
     oid = primary.id
     self.client.post(reverse('avatar_delete'), {
         'choices': [oid],
     })
     primaries = Avatar.objects.filter(user=self.user, primary=True)
     self.assertEqual(len(primaries), 1)
     self.assertNotEqual(oid, primaries[0].id)
     avatars = Avatar.objects.filter(user=self.user)
     self.assertEqual(avatars[0].id, primaries[0].id)
Example #18
0
 def test_delete_primary_avatar_and_new_primary(self):
     self.test_there_can_be_only_one_primary_avatar()
     primary = get_primary_avatar(self.user)
     oid = primary.id
     self.client.post(reverse('avatar_delete'), {
         'choices': [oid],
     })
     primaries = Avatar.objects.filter(user=self.user, primary=True)
     self.assertEqual(len(primaries), 1)
     self.assertNotEqual(oid, primaries[0].id)
     avatars = Avatar.objects.filter(user=self.user)
     self.assertEqual(avatars[0].id, primaries[0].id)
Example #19
0
 def test_delete_primary_avatar_and_new_primary(self):
     self.test_there_can_be_only_one_primary_avatar()
     primary = get_primary_avatar(self.user)
     oid = primary.id
     self.client.post(reverse('avatar_delete'), {
         'choices': [oid],
     })
     primaries = Avatar.objects.filter(user=self.user, primary=True)
     self.assertEqual(len(primaries), 1)
     self.assertNotEqual(oid, primaries[0].id)
     avatars = Avatar.objects.filter(user=self.user)
     self.assertEqual(avatars[0].id, primaries[0].id)
Example #20
0
 def testDeletePrimaryAvatarAndNewPrimary(self):
     self.testThereCanBeOnlyOnePrimaryAvatar()
     primary = get_primary_avatar(self.user)
     oid = primary.id
     self.client.post(reverse('avatar_delete'), {
         'choices': [oid],
     })
     primaries = Avatar.objects.filter(user=self.user, primary=True)
     self.assertEqual(len(primaries), 1)
     self.assertNotEqual(oid, primaries[0].id)
     avatars = Avatar.objects.filter(user=self.user)
     self.assertEqual(avatars[0].id, primaries[0].id)
Example #21
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 redirect(avatar.avatar_url(size))
    else:
        return redirect(get_default_avatar_url())
Example #22
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" % (md5_constructor(
                user.email).hexdigest(), urllib.urlencode(params))
        else:
            return get_default_avatar_url()
Example #23
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)
def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        return avatar.avatar_url(size)

    if AVATAR_GRAVATAR_BACKUP:
        params = {"s": str(size)}
        if AVATAR_GRAVATAR_DEFAULT:
            params["d"] = AVATAR_GRAVATAR_DEFAULT
        path = "%s/?%s" % (hashlib.md5(force_bytes(user.email)).hexdigest(), urlencode(params))
        return urljoin(AVATAR_GRAVATAR_BASE_URL, path)

    return get_default_avatar_url()
Example #25
0
def render_primary(request, contact=None, size=settings.AVATAR_DEFAULT_SIZE):
    size = int(size)
    avatar = get_primary_avatar(contact, 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
        url = avatar.avatar_url(size)
    else:
        url = get_default_avatar_url()

    return redirect(url)
Example #26
0
def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        return avatar.avatar_url(size)

    if AVATAR_GRAVATAR_BACKUP:
        params = {'s': str(size)}
        if AVATAR_GRAVATAR_DEFAULT:
            params['d'] = AVATAR_GRAVATAR_DEFAULT
        path = "%s/?%s" % (md5_constructor(
            user.email).hexdigest(), urllib.urlencode(params))
        return urlparse.urljoin(AVATAR_GRAVATAR_BASE_URL, path)

    return get_default_avatar_url()
Example #27
0
def avatar_url(user, size=settings.AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        return avatar.avatar_url(size)

    if settings.AVATAR_GRAVATAR_BACKUP:
        params = {'s': str(size)}
        if settings.AVATAR_GRAVATAR_DEFAULT:
            params['d'] = settings.AVATAR_GRAVATAR_DEFAULT
        path = "%s/?%s" % (hashlib.md5(force_bytes(getattr(user,
            settings.AVATAR_GRAVATAR_FIELD))).hexdigest(), urlencode(params))
        return urljoin(settings.AVATAR_GRAVATAR_BASE_URL, path)

    return get_default_avatar_url()
Example #28
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" % (
                md5_constructor('').hexdigest(),
                urllib.urlencode(params))
        else:
            return get_default_avatar_url()
Example #29
0
def avatar_url(user, size=settings.AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        return avatar.avatar_url(size)

    if settings.AVATAR_GRAVATAR_BACKUP:
        params = {'s': str(size)}
        if settings.AVATAR_GRAVATAR_DEFAULT:
            params['d'] = settings.AVATAR_GRAVATAR_DEFAULT
        path = "%s/?%s" % (hashlib.md5(force_bytes(
            user.email)).hexdigest(), urlencode(params))
        return urljoin(settings.AVATAR_GRAVATAR_BASE_URL, path)

    return get_default_avatar_url()
Example #30
0
def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        return avatar.avatar_url(size)

    if AVATAR_GRAVATAR_BACKUP:
        params = {'s': str(size)}
        if AVATAR_GRAVATAR_DEFAULT:
            params['d'] = AVATAR_GRAVATAR_DEFAULT
        path = "%s/?%s" % (md5(user.email).hexdigest(),
                           urllib.urlencode(params))
        return urlparse.urljoin(AVATAR_GRAVATAR_BASE_URL, path)

    return get_default_avatar_url()
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 "/avatar/%s/?%s" % (
                md5(user.email).hexdigest(),
                urllib.urlencode(params))
        else:
            return get_default_avatar_url()
Example #32
0
def render_primary(request, contact=None, size=settings.AVATAR_DEFAULT_SIZE):
    size = int(size)
    avatar = get_primary_avatar(contact, 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
        url = avatar.avatar_url(size)
    else:
        url = get_default_avatar_url()

    return redirect(url)
Example #33
0
def avatar_url(user, width=settings.AVATAR_DEFAULT_SIZE, height=False):
    if not height:
        height = width
    avatar = get_primary_avatar(user, width=width, height=height)
    if avatar:
        return avatar.avatar_url(width, height)

    if settings.AVATAR_GRAVATAR_BACKUP:
        params = {"s": str(width)}
        if settings.AVATAR_GRAVATAR_DEFAULT:
            params["d"] = settings.AVATAR_GRAVATAR_DEFAULT
        path = "%s/?%s" % (hashlib.md5(force_bytes(user.email)).hexdigest(), urlencode(params))
        return urljoin(settings.AVATAR_GRAVATAR_BASE_URL, path)

    return get_default_avatar_url()
Example #34
0
def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        return avatar.avatar_url(size)
    else:
        use_gravatar = user.profile.use_gravatar if (hasattr(user, 'profile') and hasattr(user.profile, 'use_gravatar')) else True
        if AVATAR_GRAVATAR_BACKUP and use_gravatar:
            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()
Example #35
0
def avatar_url(user, width=AVATAR_DEFAULT_SIZE, height=False):
    if height == False: height = width
    avatar = get_primary_avatar(user, width=width, height=height)
    if avatar:
        return avatar.avatar_url(width,height)
    else:
        if AVATAR_GRAVATAR_BACKUP:
            params = {'s': str(width)}
            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()
Example #36
0
def render_primary(request, user=None, width=settings.AVATAR_DEFAULT_SIZE, height = None):
    if height == None: height = width
    width = int(width)
    height = int(height)
    avatar = get_primary_avatar(user, width=width, height=height)
    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
        url = avatar.avatar_url(width, height)
    else:
        url = get_default_avatar_url()

    return redirect(url)
Example #37
0
def get_accessrights(ars):
    ret = []
    for ar in ars :
        the_avatar = get_primary_avatar(ar.user, 80)
        if the_avatar :
            the_avatar = the_avatar.avatar_url(80)
        else:
            the_avatar = get_default_avatar_url()
        ret.append({
            'book_id': ar.book.id,
            'user_id': ar.user.id,
            'user_name': ar.user.readable_name,
            'rights': ar.rights,
            'avatar': the_avatar
        })
    return ret
Example #38
0
def avatar_url(target, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(target)
    if avatar:
        if not avatar.thumbnail_exists(size):
            avatar.create_thumbnail(size)
        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(get_target_gravatar_url(target)).hexdigest(),
                urllib.urlencode(params))
        else:
            return get_default_avatar_url(target, size)
Example #39
0
def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    tt = Orglogo.objects.filter(orgacronym=user.org_acronym)
    # if avatar:
    #     return avatar.avatar_url(size)
    # else:
    #     if tt.count()>0:
    #         return tt[0].logo_url(200)
    #     else:
    #         return get_default_avatar_url()

    if tt.count()>0:
        return tt[0].logo_url(size)
    elif avatar:
        return avatar.avatar_url(size)
    else:
        return get_default_avatar_url()
Example #40
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:
            gravatar_hash = hashlib.new("md5")
            gravatar_hash.update(user.email)

            params = {'s': str(size)}
            if AVATAR_GRAVATAR_DEFAULT:
                params['d'] = AVATAR_GRAVATAR_DEFAULT
            return "https://secure.gravatar.com/avatar/%s/?%s" % (
                gravatar_hash.hexdigest(),
                urllib.urlencode(params))
        else:
            return get_default_avatar_url()
Example #41
0
def avatar_print_url(user, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    tt = Orglogo.objects.filter(orgacronym=user.org_acronym)
    # if avatar:
    #     return avatar.avatar_url(size)
    # else:
    #     if tt.count()>0:
    #         return tt[0].logo_url(200)
    #     else:
    #         return get_default_avatar_url()

    if tt.count()>0:
        return {'onpdf':str(tt[0].onpdf).lower(), 'logo_url':tt[0].logo_url(size)}
    elif avatar:
        return {'onpdf':str(False).lower(), 'logo_url': avatar.avatar_url(size)}
    else:
        return {'onpdf':str(False).lower(), 'logo_url': get_default_avatar_url()} 
Example #42
0
def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    tt = Orglogo.objects.filter(orgacronym=user.org_acronym)
    # if avatar:
    #     return avatar.avatar_url(size)
    # else:
    #     if tt.count()>0:
    #         return tt[0].logo_url(200)
    #     else:
    #         return get_default_avatar_url()

    if tt.count() > 0:
        return tt[0].logo_url(size)
    elif avatar:
        return avatar.avatar_url(size)
    else:
        return get_default_avatar_url()
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
            proto = "http"
            if AVATAR_GRAVATAR_SSL:
                proto = "https"
            return "%s://www.gravatar.com/avatar/%s/?%s" % (
                proto, hashlib.md5(
                    user.email).hexdigest(), urllib.urlencode(params))
        else:
            return get_default_avatar_url()
Example #44
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
            proto = "http"
            if AVATAR_GRAVATAR_SSL:
                proto = "https"
            return "%s://www.gravatar.com/avatar/%s/?%s" % (
                proto, hashlib.md5(user.email).hexdigest(),
                urllib.urlencode(params))
        else:
            return get_default_avatar_url()
Example #45
0
def get_accessrights(ars):
    ret = []
    for ar in ars:
        the_avatar = get_primary_avatar(ar.user, 80)
        if the_avatar:
            the_avatar = the_avatar.avatar_url(80)
        else:
            the_avatar = get_default_avatar_url()
        ret.append(
            {
                "book_id": ar.book.id,
                "user_id": ar.user.id,
                "user_name": ar.user.readable_name,
                "rights": ar.rights,
                "avatar": the_avatar,
            }
        )
    return ret
Example #46
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
            if AVATAR_GRAVATAR_SSL:
                prefix = 'https://secure'
            else:
                prefix = 'http://www'
            return "%s.gravatar.com/avatar/%s/?%s" % (
                prefix,
                md5_constructor(user.email).hexdigest(),
                urllib.urlencode(params))
        else:
            return get_default_avatar_url()
Example #47
0
def avatar_url(user, size=settings.AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        return avatar.avatar_url(size)

    if settings.AVATAR_FACEBOOK_BACKUP:
        fb_id = get_facebook_id(user)
        if fb_id:
            return 'https://graph.facebook.com/{fb_id}/picture?type=square&width={size}&height={size}'.format(
                fb_id=fb_id, size=size
            )

    if settings.AVATAR_GRAVATAR_BACKUP:
        params = {'s': str(size)}
        if settings.AVATAR_GRAVATAR_DEFAULT:
            params['d'] = settings.AVATAR_GRAVATAR_DEFAULT
        path = "%s/?%s" % (hashlib.md5(force_bytes(user.email)).hexdigest(),
                           urlencode(params))
        return urljoin(settings.AVATAR_GRAVATAR_BASE_URL, path)

    return get_default_avatar_url()
Example #48
0
 def testAutomaticThumbnailCreationCMYK(self):
     upload_helper(self, "django_pony_cmyk.jpg")
     avatar = get_primary_avatar(self.user)
     image = Image.open(avatar.avatar.storage.open(avatar.avatar_name(settings.AVATAR_DEFAULT_SIZE), 'rb'))
     self.assertEqual(image.mode, 'RGB')
Example #49
0
 def testNonExistingUser(self):
     a = get_primary_avatar("nonexistinguser")
     self.failUnlessEqual(a, None)
Example #50
0
 def testNonExistingUser(self):
     a = get_primary_avatar("nonexistinguser")
     self.assertEqual(a, None)
Example #51
0
def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        return avatar.avatar_url(size)
Example #52
0
 def get_avatar_url(self, obj):
     avatar = get_primary_avatar(obj, size=66)
     if avatar:
         return avatar.avatar_url(66)
     return get_default_avatar_url()