Skip to content

Commit

Permalink
[#1719,helpers][xs]: fixes #1719 - broken link for users without a re…
Browse files Browse the repository at this point in the history
…al gravatar.

* Problem: we were providing a default user icon to gravatar (see http://en.gravatar.com/site/implement/images/). However, we were not providing an *absolute* url just the relevative url on the CKAN instance (also weren't url-encoding the link ...). This led to the following 404 url: http://en.gravatar.com/images/icons/user.png
* Fix: use identicon default image from gravatar (no longer provide our own default image).
  * Could have corrected this but felt simpler option from multiple persepectives (code, resource usage, ux) was to do this.
  • Loading branch information
rufuspollock committed Feb 6, 2012
1 parent 50f0946 commit 90c76b0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
10 changes: 3 additions & 7 deletions ckan/lib/helpers.py
Expand Up @@ -204,10 +204,7 @@ def linked_user(user, maxlength=0):
return user_name
if user:
_name = user.name if model.User.VALID_NAME.match(user.name) else user.id
# Absolute URL of default user icon
from pylons import config
_icon_url_default = icon_url("user")
_icon = gravatar(user.email_hash, 16, _icon_url_default)+" "
_icon = gravatar(user.email_hash, 20)
displayname = user.display_name
if maxlength and len(user.display_name) > maxlength:
displayname = displayname[:maxlength] + '...'
Expand Down Expand Up @@ -252,14 +249,14 @@ def icon_html(url, alt=None):
def icon(name, alt=None):
return icon_html(icon_url(name),alt)

def linked_gravatar(email_hash, size=100, default="mm"):
def linked_gravatar(email_hash, size=100, default="identicon"):
return literal('''<a href="https://gravatar.com/" target="_blank"
title="Update your avatar at gravatar.com">
%s</a>''' %
gravatar(email_hash,size,default)
)

def gravatar(email_hash, size=100, default="mm"):
def gravatar(email_hash, size=100, default="identicon"):
return literal('''<img src="http://gravatar.com/avatar/%s?s=%d&amp;d=%s"
class="gravatar" />'''
% (email_hash, size, default)
Expand Down Expand Up @@ -289,7 +286,6 @@ def render_datetime(datetime_, date_format='%Y-%m-%d %H:%M'):
(Y-m-d H:m).
If timestamp is badly formatted, then a blank string is returned.
'''
from ckan import model
if isinstance(datetime_, datetime.datetime):
return datetime_.strftime(date_format)
elif isinstance(datetime_, basestring):
Expand Down
4 changes: 3 additions & 1 deletion ckan/public/css/style.css
Expand Up @@ -640,6 +640,7 @@ form.simple-form input[type=password] {
/* ============== */
/* = User Index = */
/* ============== */

ul.userlist,
ul.userlist ul {
list-style-type: none;
Expand All @@ -658,7 +659,8 @@ ul.userlist li ul span.edits {
margin-left: 3px;
}
ul.userlist .username img {
margin-bottom: -3px;
margin: 0 5px -6px 0;
border-radius: 3px;
}
ul.userlist .created {
color: #888;
Expand Down
3 changes: 2 additions & 1 deletion ckan/tests/lib/test_helpers.py
Expand Up @@ -53,7 +53,8 @@ def test_time_ago_in_words_from_str(self):

def test_gravatar(self):
email = 'zephod@gmail.com'
expected =['<a href="https://gravatar.com/"', '<img src="http://gravatar.com/avatar/7856421db6a63efa5b248909c472fbd2?s=200&amp;d=mm"', '</a>']
expected =['<a href="https://gravatar.com/"',
'<img src="http://gravatar.com/avatar/7856421db6a63efa5b248909c472fbd2?s=200&amp;d=identicon"', '</a>']
# Hash the email address
import hashlib
email_hash = hashlib.md5(email).hexdigest()
Expand Down

0 comments on commit 90c76b0

Please sign in to comment.