Skip to content

Commit

Permalink
2147 fix facet display pills in search
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed May 24, 2012
1 parent 3d9e092 commit d4bc4ac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
7 changes: 7 additions & 0 deletions ckan/controllers/package.py
Expand Up @@ -186,6 +186,9 @@ def pager_url(q=None, page=None):

try:
c.fields = []
# c.fields_grouped will contain a dict of params containing
# a list of values eg {'tags':['tag1', 'tag2']}
c.fields_grouped = {}
search_extras = {}
fq = ''
for (param, value) in request.params.items():
Expand All @@ -194,6 +197,10 @@ def pager_url(q=None, page=None):
if not param.startswith('ext_'):
c.fields.append((param, value))
fq += ' %s:"%s"' % (param, value)
if param not in c.fields_grouped:
c.fields_grouped[param] = [value]
else:
c.fields_grouped[param].append(value)
else:
search_extras[param] = value

Expand Down
18 changes: 10 additions & 8 deletions ckan/templates/package/search.html
Expand Up @@ -33,15 +33,17 @@
<py:when test="request.params and c.page.item_count == 0">Sorry no datasets found for &#147;${c.q}&#148;</py:when>
<py:otherwise>All datasets</py:otherwise>
</strong>
<py:for each="(field, value) in c.fields">
<py:for each="field in c.fields_grouped">
<span class="facet">${c.facet_titles.get(field)}:</span>
<span class="filtered pill" py:choose="">
<py:when test="c.translated_fields and c.translated_fields.has_key((field,value))">
${c.translated_fields[(field,value)]}
</py:when>
<py:otherwise>${value}</py:otherwise>
<a href="${c.remove_field(field, value)}" class="remove icon-remove icon-white">[remove]</a>
</span>
<py:for each="value in c.fields_grouped[field]">
<span class="filtered pill" py:choose="">
<py:when test="c.translated_fields and c.translated_fields.has_key((field,value))">
${c.translated_fields[(field,value)]}
</py:when>
<py:otherwise>${value}</py:otherwise>
<a href="${c.remove_field(field, value)}" class="remove icon-remove icon-white">[remove]</a>
</span>
</py:for>
</py:for>
<p class="extra" py:if="request.params and c.page.item_count == 0">Try another search term,
browse the datasets below or <a href="${h.url_for(action='new', id=None)}">add your own data</a>.</p>
Expand Down

0 comments on commit d4bc4ac

Please sign in to comment.