diff --git a/avatar/conf.py b/avatar/conf.py index 05e36af..645fa25 100644 --- a/avatar/conf.py +++ b/avatar/conf.py @@ -13,6 +13,7 @@ class AvatarConf(AppConf): GRAVATAR_FIELD = 'email' GRAVATAR_BACKUP = True GRAVATAR_DEFAULT = None + AVATAR_GRAVATAR_FORCEDEFAULT = False DEFAULT_URL = 'avatar/img/default.jpg' MAX_AVATARS_PER_USER = 42 MAX_SIZE = 1024 * 1024 diff --git a/avatar/templatetags/avatar_tags.py b/avatar/templatetags/avatar_tags.py index bf62e80..4dc7963 100644 --- a/avatar/templatetags/avatar_tags.py +++ b/avatar/templatetags/avatar_tags.py @@ -40,6 +40,8 @@ def avatar_url(user, size=settings.AVATAR_DEFAULT_SIZE): params = {'s': str(size)} if settings.AVATAR_GRAVATAR_DEFAULT: params['d'] = settings.AVATAR_GRAVATAR_DEFAULT + if settings.AVATAR_GRAVATAR_FORCEDEFAULT: + params['f'] = 'y' path = "%s/?%s" % (hashlib.md5(force_bytes(getattr(user, settings.AVATAR_GRAVATAR_FIELD))).hexdigest(), urlencode(params)) return urljoin(settings.AVATAR_GRAVATAR_BASE_URL, path) diff --git a/docs/index.txt b/docs/index.txt index 88767f8..1a6dd05 100644 --- a/docs/index.txt +++ b/docs/index.txt @@ -139,6 +139,11 @@ AVATAR_GRAVATAR_DEFAULT `Gravatar documentation `_. Defaults to ``None``. +AVATAR_GRAVATAR_FORCEDEFAULT + A bool indicating whether or not to always use the default Gravitar. More details can be found + in the `Gravatar documentation `_. + Defaults to ``False``. + AVATAR_GRAVATAR_FIELD The name of the user's field containing the gravatar email. For example, if you set this to ``gravatar`` then django-avatar will get the user's gravatar in ``user.gravatar``.