David Chambers avatar David Chambers committed f1ba899

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

Comments (0)

Files changed (2)

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
 

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,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.