Ejemplo n.º 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/'
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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()
        }
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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())
Ejemplo n.º 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())
Ejemplo n.º 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)
Ejemplo n.º 13
0
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()
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 16
0
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()
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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())
Ejemplo n.º 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()
Ejemplo n.º 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)
Ejemplo n.º 24
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" % (hashlib.md5(force_bytes(user.email)).hexdigest(), urlencode(params))
        return urljoin(AVATAR_GRAVATAR_BASE_URL, path)

    return get_default_avatar_url()
Ejemplo n.º 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)
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 31
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 "/avatar/%s/?%s" % (
                md5(user.email).hexdigest(),
                urllib.urlencode(params))
        else:
            return get_default_avatar_url()
Ejemplo n.º 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)
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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()} 
Ejemplo n.º 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()
Ejemplo n.º 43
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()
Ejemplo n.º 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()
Ejemplo n.º 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
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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')
Ejemplo n.º 49
0
 def testNonExistingUser(self):
     a = get_primary_avatar("nonexistinguser")
     self.failUnlessEqual(a, None)
Ejemplo n.º 50
0
 def testNonExistingUser(self):
     a = get_primary_avatar("nonexistinguser")
     self.assertEqual(a, None)
Ejemplo n.º 51
0
def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        return avatar.avatar_url(size)
Ejemplo n.º 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()