Ejemplo n.º 1
0
    def get_avatar(self, size=None):
        image_size = avatar_size(size) if size else None

        # Get uploaded avatar
        if self.avatar_type == 'upload':
            image_prefix = '%s_' % image_size if image_size else ''
            return settings.MEDIA_URL + 'avatars/' + image_prefix + self.avatar_image

        # Get gallery avatar
        if self.avatar_type == 'gallery':
            image_prefix = '_thumbs/%s/' % image_size if image_size else ''
            return settings.STATIC_URL + 'avatars/' + image_prefix + self.avatar_image

        # No avatar found, get gravatar
        if not image_size:
            image_size = settings.AVATAR_SIZES[0]

        # Decide on default gravatar
        gravatar_default = ''
        if (settings.GRAVATAR_DEFAULT and not '&' in settings.GRAVATAR_DEFAULT
                and not '?' in settings.GRAVATAR_DEFAULT):
            gravatar_default = '&d=%s' % settings.GRAVATAR_DEFAULT

        return 'http://www.gravatar.com/avatar/%s?s=%s%s' % (hashlib.md5(
            self.email.encode('utf-8')).hexdigest(), image_size,
                                                             gravatar_default)
Ejemplo n.º 2
0
    def get_avatar(self, size=None):
        image_size = avatar_size(size) if size else None

        # Get uploaded avatar
        if self.avatar_type == 'upload':
            image_prefix = '%s_' % image_size if image_size else ''
            return settings.MEDIA_URL + 'avatars/' + image_prefix + self.avatar_image

        # Get gallery avatar
        if self.avatar_type == 'gallery':
            image_prefix = '_thumbs/%s/' % image_size if image_size else ''
            return settings.STATIC_URL + 'avatars/' + image_prefix + self.avatar_image

        # No avatar found, get gravatar
        if not image_size:
            image_size = settings.AVATAR_SIZES[0]

        # Decide on default gravatar
        gravatar_default = ''
        if (settings.GRAVATAR_DEFAULT
                and not '&' in settings.GRAVATAR_DEFAULT
                and not '?' in settings.GRAVATAR_DEFAULT):
            gravatar_default = '&d=%s' % settings.GRAVATAR_DEFAULT

        return 'http://www.gravatar.com/avatar/%s?s=%s%s' % (hashlib.md5(self.email).hexdigest(), image_size, gravatar_default)
Ejemplo n.º 3
0
    def get_avatar(self, size=None):
        image_size = avatar_size(size) if size else None

        # Get uploaded avatar
        if self.avatar_type == 'upload':
            image_prefix = '%s_' % image_size if image_size else ''
            return settings.MEDIA_URL + 'avatars/' + image_prefix + self.avatar_image

        # Get gallery avatar
        if self.avatar_type == 'gallery':
            image_prefix = '_thumbs/%s/' % image_size if image_size else ''
            return settings.STATIC_URL + 'avatars/' + image_prefix + self.avatar_image

        # No avatar found, get gravatar
        if not image_size:
            image_size = settings.AVATAR_SIZES[0]
        return 'http://www.gravatar.com/avatar/%s?s=%s' % (hashlib.md5(self.email).hexdigest(), image_size)
Ejemplo n.º 4
0
    def get_avatar(self, size=None):
        image_size = avatar_size(size) if size else None

        # Get uploaded avatar
        if self.avatar_type == 'upload':
            image_prefix = '%s_' % image_size if image_size else ''
            return settings.MEDIA_URL + 'avatars/' + image_prefix + self.avatar_image

        # Get gallery avatar
        if self.avatar_type == 'gallery':
            image_prefix = '_thumbs/%s/' % image_size if image_size else ''
            return settings.STATIC_URL + 'avatars/' + image_prefix + self.avatar_image

        # No avatar found, get gravatar
        if not image_size:
            image_size = settings.AVATAR_SIZES[0]
        return 'http://www.gravatar.com/avatar/%s?s=%s' % (hashlib.md5(
            self.email).hexdigest(), image_size)