Skip to content

Commit

Permalink
Merge branch 'master' of github.com:okfn/ckan into 2375-demo-organiza…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
Sean Hammond committed Sep 18, 2012
2 parents 3adc136 + 076008f commit a8514d0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
40 changes: 15 additions & 25 deletions ckan/lib/helpers.py
Expand Up @@ -522,30 +522,17 @@ def unselected_facet_items(facet, limit=10):
limit -- the max. number of facet items to return.
'''
# TODO if we agree to propossed change then we can just wrap
# get_facet_items_dict()

#return get_facet_items_dict(facet, limit=limit, exclude_active=True)
if not c.search_facets or \
not c.search_facets.get(facet) or \
not c.search_facets.get(facet).get('items'):
return []
facets = []
for facet_item in c.search_facets.get(facet)['items']:
if not len(facet_item['name'].strip()):
continue
if not (facet, facet_item['name']) in request.params.items():
facets.append(facet_item)
facets = sorted(facets, key=lambda item: item['count'], reverse=True)
if c.search_facets_limits:
limit = c.search_facets_limits.get(facet)
if limit:
return facets[:limit]
else:
return facets

return get_facet_items_dict(facet, limit=limit, exclude_active=True)

@deprecated('Please use get_facet_title(name) for i18n improvements.')
def facet_title(name):
'''Returns a title for the given facet name.
If a mapping is declared in the config, this is used. Otherwise it falls
back to capitalizing the given name.
This function is deprecated, use `get_facet_title` instead.
'''
# FIXME this looks like an i18n issue
return config.get('search.facets.%s.title' % name, name.capitalize())

Expand Down Expand Up @@ -1315,7 +1302,8 @@ def format_resource_items(items):
output = []
# regular expressions for detecting types in strings
reg_ex_datetime = '^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{6})?$'
reg_ex_number = '^-?\d{1,}\.?\d*$' # int/float
reg_ex_int = '^-?\d{1,}$'
reg_ex_float = '^-?\d{1,}\.\d{1,}$'
for key, value in items:
if not value or key in blacklist:
continue
Expand All @@ -1327,8 +1315,10 @@ def format_resource_items(items):
if re.search(reg_ex_datetime, value):
datetime_ = date_str_to_datetime(value)
value = formatters.localised_nice_date(datetime_)
elif re.search(reg_ex_number, value):
elif re.search(reg_ex_float, value):
value = formatters.localised_number(float(value))
elif re.search(reg_ex_int, value):
value = formatters.localised_number(int(value))
elif isinstance(value, int) or isinstance(value, float):
value = formatters.localised_number(value)
key = key.replace('_', ' ')
Expand All @@ -1354,7 +1344,7 @@ def format_resource_items(items):
'subnav_link',
'subnav_named_route',
'default_group_type',
'facet_title',
# 'facet_title', # deprecated
# am_authorized, # deprecated
'check_access',
'linked_user',
Expand Down
4 changes: 2 additions & 2 deletions ckan/templates_legacy/facets.html
Expand Up @@ -32,7 +32,7 @@
-->
<py:def function="facet_div(name, title, limit=10, label_function=lambda item: item.display_name, if_empty=None, count_label=lambda c: ' (%d)'%c)">
<div py:if="if_empty is not None or h.unselected_facet_items(name, limit)" class="facet-box">
<h2>${h.facet_title(title)}</h2>
<h2>${h.get_facet_title(title)}</h2>
<ul class="facet-options">
${facet_li(name, limit=limit, label_function=label_function, if_empty=None, count_label=count_label)}
</ul>
Expand Down Expand Up @@ -78,7 +78,7 @@ <h2>${h.facet_title(title)}</h2>
<py:def function="field_list()">
<div class="filter-list" py:if="c.fields">
<div class="filter-entry" py:for="(field, value) in c.fields">
<span class="name">${h.facet_title(field)}</span>
<span class="name">${h.get_facet_title(field)}</span>
<span class="value" py:choose="">
<py:when test="c.translated_fields and c.translated_fields.has_key((field,value))">
${c.translated_fields[(field,value)]}
Expand Down

0 comments on commit a8514d0

Please sign in to comment.