Skip to content

Commit

Permalink
move popular into a helper function to make easier to include
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed May 30, 2012
1 parent 0c9bed8 commit ee06dad
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
13 changes: 12 additions & 1 deletion ckan/lib/helpers.py
Expand Up @@ -34,7 +34,7 @@
from pylons import request
from pylons import session
from pylons import c
from pylons.i18n import _
from pylons.i18n import _, ungettext

import html_resources
from lib.maintain import deprecated
Expand Down Expand Up @@ -940,6 +940,16 @@ def debug_inspect(arg):
''' Output pprint.pformat view of supplied arg '''
return literal('<pre>') + pprint.pformat(arg) + literal('</pre>')

def popular(type_, number, min=1, title=None):
''' display a popular icon. '''
if type_ == 'views':
title = ungettext('{number} view', '{number} views', number)
elif type_ == 'recent views':
title = ungettext('{number} recent view', '{number} recent views', number)
elif not title:
raise Exception('popular() did not recieve a valid type_ or title')
return snippet('snippets/popular.html', title=title, number=number, min=min)

# these are the functions that will end up in `h` template helpers
# if config option restrict_template_vars is true
__allowed_functions__ = [
Expand Down Expand Up @@ -999,6 +1009,7 @@ def debug_inspect(arg):
'debug_inspect',
'dict_list_reduce',
'full_current_url',
'popular',
# imported into ckan.lib.helpers
'literal',
'link_to',
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/package/read.html
Expand Up @@ -43,7 +43,7 @@ <h3>Data and Resources</h3>
<a class="heading" href="${url}" title="${res.name or res.description}">
${h.truncate(h.resource_display_name(res), 50)}<span class="format-label" property="dc:format" data-format="${res.format.lower() or 'data'}">${res.format}</span>
<!--! popular icon -->
${h.snippet('snippets/popular.html', title=ungettext('{num} view', '{num} views', res.tracking_summary.total), num=res.tracking_summary.total)}
${h.popular('views', res.tracking_summary.total, min=10)}
</a>
<p class="description">
<py:choose test="">
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/snippets/package_list.html
Expand Up @@ -3,7 +3,7 @@
<h3 class="heading" py:with="title = package.get('title') or package.get('name')">
${h.link_to(h.truncate(title, 80), h.url_for(controller='package', action='read', id=package.get('name')))}
<!--! TODO: Hook this up to views -->
${h.snippet('snippets/popular.html', title=ungettext('{num} recent view', '{num} recent views', package.tracking_summary.recent), num=package.tracking_summary.recent)}
${h.popular('recent views', package.tracking_summary.recent, min=10)}
</h3>
<div class="content" py:with="notes = h.markdown_extract(package.notes)">
<py:if test="notes">${notes}</py:if>
Expand Down
6 changes: 3 additions & 3 deletions ckan/templates/snippets/popular.html
@@ -1,4 +1,4 @@
{# show poular icon basic functionality will need updating #}
{% if num > 10 %}
<span class="popular ckan-icon ckan-icon-flame" title="{{ title.format(num=num) }}" xmlns="http://www.w3.org/1999/xhtml">Popular</span>
{# show poular icon #}
{% if number >= min %}
<span class="popular ckan-icon ckan-icon-flame" title="{{ title.format(number=number) }}" xmlns="http://www.w3.org/1999/xhtml">Popular</span>
{% endif %}

0 comments on commit ee06dad

Please sign in to comment.