Python
Switch branches/tags
Pull request Compare This branch is 13 commits ahead, 22 commits behind nvie:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
avatar
LICENSE.txt
README.rst
setup.py

README.rst

django-offsite-avatar

django-offsite-avatar makes it easy to add Facebook and Gravatar avatar support to your Django application through the addition of a template tag.

History

This code is a backwards-incompatible fork of http://django-gravatar.googlecode.com. The newer package https://github.com/ericflo/django-avatar provides more general avatar functionality (including Gravatar as a default backup) but introduces a lot of code for file upload and storage. This project intends to support only avatars hosted by someone else - Facebook, Gravatar, Twitter, etc.

Installation

To install it, use pip:

pip install django-offsite-avatar

Usage

To use it with a Django installation, first place 'avatar' in the INSTALLED_APPS tuple of your settings.py file like so:

INSTALLED_APPS = (
    # ...
    'avatar',
)

This conflicts with the django-avatar package, but they should never really be installed side-by-side.

Here is sample usage in a template:

{% load avatar %}
{% avatar request.user %}

In the previous example, a Facebook profile picture will be displayed if one is available, falling back to a Gravatar if the user has an e-mail address, or finally a default image if there is no Gravatar available.

This templatetag assumes that you are using a custom User profile, and the profile has a facebook_id field. If the identifier is stored elsewhere, you can add a property to the profile like so:

class UserProfile(models.Model):
    ...

    @property
    def facebook_id(self):
        # Do whatever you need to do to find the identifier for this user
        return <...>

If you only want the URL and not the full blown img-tag, you can use the following functions:

{% avatar_for_user 'jtauber' %}

There are a few configuration variables available that you can use in your Django's settings.py:

  • GRAVATAR_URL_PREFIX: The gravatar URL to use. Default: http://www.gravatar.com/
  • FACEBOOK_AVATAR_URL_PREFIX: The Facebook profile picture URL to use. Default: http://www.gravatar.com/
  • AVATAR_DEFAULT_IMAGE: The default image to use, see http://en.gravatar.com/site/implement/images/#default-image
  • AVATAR_IMG_CLASS: The default CSS class name to add to generated <img>-tags.