From 9b99b253340de7d29d58ac244acb10352c8a97aa Mon Sep 17 00:00:00 2001 From: Ian Murray Date: Wed, 15 Feb 2012 12:13:34 +0000 Subject: [PATCH 1/2] [#1607][facets.html] Added a different function for generating facet filters as an unboxed list of
  • items. This allows for more flexible layout of filters. Such as a nested layout. --- ckan/templates/facets.html | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/ckan/templates/facets.html b/ckan/templates/facets.html index 0ffe47bbd91..15a6ceb013f 100644 --- a/ckan/templates/facets.html +++ b/ckan/templates/facets.html @@ -5,8 +5,8 @@ py:strip="" > - -
    + +

    ${title(code)}

    +

    ${if_empty}

    + + +
  • ${if_empty}
  • +
  • + ${label(name)} (${count}) +
  • + +
    From 765de64a671d213dbb6f40f136af0ed7616c165d Mon Sep 17 00:00:00 2001 From: Ian Murray Date: Wed, 15 Feb 2012 15:27:10 +0000 Subject: [PATCH 2/2] [#1607][gravatar] Made default gravatar image a configuration option. --- ckan/config/deployment.ini_tmpl | 5 +++++ ckan/lib/helpers.py | 14 ++++++++++++-- ckan/tests/lib/test_helpers.py | 34 ++++++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/ckan/config/deployment.ini_tmpl b/ckan/config/deployment.ini_tmpl index 85183c1757a..b0cc65bbc45 100644 --- a/ckan/config/deployment.ini_tmpl +++ b/ckan/config/deployment.ini_tmpl @@ -111,6 +111,11 @@ ckan.site_url = ## Favicon (default is the CKAN software favicon) ckan.favicon = /images/icons/ckan.ico +## The gravatar default to use. This can be any of the pre-defined strings +## as defined on http://en.gravatar.com/site/implement/images/ (e.g. "identicon" +## or "mm"). Or it can be a url, e.g. "http://example.com/images/avatar.jpg" +ckan.gravatar_default = identicon + ## Solr support #solr_url = http://127.0.0.1:8983/solr diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index 80926f47e17..d2f1ee1433e 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -7,6 +7,7 @@ """ import datetime import re +import urllib from webhelpers.html import escape, HTML, literal, url_escape from webhelpers.html.tools import mail_to @@ -249,14 +250,23 @@ 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="identicon"): +def linked_gravatar(email_hash, size=100, default=None): return literal(''' %s''' % gravatar(email_hash,size,default) ) -def gravatar(email_hash, size=100, default="identicon"): +_VALID_GRAVATAR_DEFAULTS = ['404', 'mm', 'identicon', 'monsterid', 'wavatar', 'retro'] +def gravatar(email_hash, size=100, default=None): + if default is None: + from pylons import config + default = config.get('ckan.gravatar_default', 'identicon') + + if not default in _VALID_GRAVATAR_DEFAULTS: + # treat the default as a url + default = urllib.quote(default, safe='') + return literal('''''' % (email_hash, size, default) diff --git a/ckan/tests/lib/test_helpers.py b/ckan/tests/lib/test_helpers.py index 2500c64b69e..aa15287f649 100644 --- a/ckan/tests/lib/test_helpers.py +++ b/ckan/tests/lib/test_helpers.py @@ -3,6 +3,8 @@ import datetime from nose.tools import assert_equal +from pylons import config + from ckan.tests import * from ckan.lib import helpers as h @@ -54,10 +56,40 @@ def test_time_ago_in_words_from_str(self): def test_gravatar(self): email = 'zephod@gmail.com' expected =[''] + ''] + # Hash the email address + import hashlib + email_hash = hashlib.md5(email).hexdigest() + res = h.linked_gravatar(email_hash, 200, default='mm') + for e in expected: + assert e in res, (e,res) + + def test_gravatar_config_set_default(self): + """Test when default gravatar is None, it is pulled from the config file""" + email = 'zephod@gmail.com' + default = config.get('ckan.gravatar_default', 'identicon') + expected =[''] # Hash the email address import hashlib email_hash = hashlib.md5(email).hexdigest() res = h.linked_gravatar(email_hash, 200) for e in expected: assert e in res, (e,res) + + def test_gravatar_encodes_url_correctly(self): + """Test when the default gravatar is a url, it gets urlencoded""" + email = 'zephod@gmail.com' + default = 'http://example.com/images/avatar.jpg' + expected =[''] + # Hash the email address + import hashlib + email_hash = hashlib.md5(email).hexdigest() + res = h.linked_gravatar(email_hash, 200, default=default) + for e in expected: + assert e in res, (e,res) + +