Skip to content

Commit

Permalink
[2375] Add support for clearing all keys to c.remove_field
Browse files Browse the repository at this point in the history
This change makes the second "value" argument optional. Also hooked
up the "Clear all" buttons in the facet navigation.
  • Loading branch information
aron committed May 14, 2012
1 parent 02efd52 commit 7231093
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions ckan/controllers/package.py
Expand Up @@ -135,9 +135,18 @@ def drill_down_url(alternative_url=None, **by):

c.drill_down_url = drill_down_url

def remove_field(key, value):
def remove_field(key, value=None):
"""
Remove a key from the current search parameters. A specific
key/value pair can be removed by passing a second value argument
otherwise all pairs matching the key will be removed.
"""
params = list(params_nopage)
params.remove((key, value))
if value:
params.remove((key, value))
else:
[params.remove((k, v)) for (k, v) in params[:] if k==key]

return search_url(params)

c.remove_field = remove_field
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/snippets/facet_list.html
Expand Up @@ -24,7 +24,7 @@
-->
<section class="module" xmlns:py="http://genshi.edgewall.org/" py:with="items=h.unselected_facet_items(name, 10)">
<h2 class="heading">${h.facet_title(title)} <a class="btn btn-small">Clear All</a></h2>
<h2 class="heading">${h.facet_title(title)} <a href="${c.remove_field(name)}" class="btn btn-small">Clear All</a></h2>
<nav>
<ul class="unstyled nav nav-simple">
<py:for each="item in items">
Expand Down

0 comments on commit 7231093

Please sign in to comment.