Commits

David Chambers  committed f1ba899

rename Gravatar settings ("identicon" is certainly not an image URL)

  • Participants
  • Parent commits 6fee418

Comments (0)

Files changed (2)

File settings/defaults.py

 
 FEED_MAX_POSTS = 20
 
-GRAVATAR_DEFAULT_IMAGE_URL = None
-GRAVATAR_IMAGE_SIZE = 32
+# The `gravatar` template filter checks for the presence of these
+# settings. If absent, it then checks for the presence of the older
+# (deprecated) settings. Were the settings defined here, this would
+# not be possible. For now, these default values live in the filter
+# function itself.
+# GRAVATAR_DEFAULT = None
+# GRAVATAR_SIZE = 32
 
 INDEX_CACHE_SECONDS = 5 * 60
 

File templatetags/mango_extras.py

 @register.filter
 @stringfilter
 def gravatar(email_hash):
+    try:
+        size = getattr(mango.settings, 'GRAVATAR_SIZE')
+    except AttributeError:
+        try:
+            size = getattr(mango.settings, 'GRAVATAR_IMAGE_SIZE')
+        except AttributeError:
+            size = 32
+    try:
+        default = getattr(mango.settings, 'GRAVATAR_DEFAULT')
+    except AttributeError:
+        try:
+            default = getattr(mango.settings, 'GRAVATAR_DEFAULT_IMAGE_URL')
+        except AttributeError:
+            default = None
+
     pairs = []
-    if mango.settings.GRAVATAR_IMAGE_SIZE:
-        pairs.append(('s', mango.settings.GRAVATAR_IMAGE_SIZE))
-    if mango.settings.GRAVATAR_DEFAULT_IMAGE_URL:
-        pairs.append(('d', mango.settings.GRAVATAR_DEFAULT_IMAGE_URL))
+    if size:
+        pairs.append(('s', size))
+    if default:
+        pairs.append(('d', default))
     # Passing a tuple of tuples produces a canonical URL, avoiding unnecessary
     # HTTP requests which could result if a dictionary were passed instead.
     return 'http://www.gravatar.com/avatar/%s?%s' % (email_hash,