Skip to content

Commit

Permalink
package_list just show resource types not each resource
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed May 18, 2012
1 parent 7431f6f commit 64c9f88
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 13 additions & 0 deletions ckan/lib/helpers.py
Expand Up @@ -552,6 +552,18 @@ def format_icon(_format):
if ('xml' in _format): return 'page_white_code'
return 'page_white'

def dict_list_reduce(list_, key, unique=True):
''' Take a list of dicts and create a new one containing just the
values for the key with unique values if requested. '''
new_list = []
for item in list_:
value = item.get(key)
if not value or (unique and value in new_list):
continue
new_list.append(value)
return new_list


def linked_gravatar(email_hash, size=100, default=None):
return literal(
'<a href="https://gravatar.com/" target="_blank"' +
Expand Down Expand Up @@ -909,6 +921,7 @@ def debug_inspect(arg):
'include_resource',
'build_nav_main',
'debug_inspect',
'dict_list_reduce',
# imported into ckan.lib.helpers
'literal',
'link_to',
Expand Down
6 changes: 3 additions & 3 deletions ckan/templates/snippets/package_list.html
Expand Up @@ -8,9 +8,9 @@ <h3 class="heading">
</div>
<py:if test="package.resources">
<ul class="dataset-resources unstyled">
<py:for each="resource in package.resources">
<li py:if="resource.get('format')">
<a href="${resource.get('url')}" class="label resource-url-analytics" title="${resource.get('description')}">${resource.get('format')}</a>
<py:for each="resource in h.dict_list_reduce(package.resources, 'format')">
<li>
<a href="${h.url_for(controller='package', action='read', id=package.get('name'))}" class="label">${resource}</a>
</li>
</py:for>
</ul>
Expand Down

0 comments on commit 64c9f88

Please sign in to comment.