Skip to content

Commit

Permalink
Use package_search to display package count of harvester
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Oderbolz committed Oct 31, 2017
1 parent 685b5c4 commit 0cbb941
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
11 changes: 11 additions & 0 deletions ckanext/harvest/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ def pager_url(q=None, page=None):

return out

def package_count_for_source(source_id):
'''
Returns the current package count for datasets associated with the given
source id
'''
fq = 'harvest_source_id:"{0}"'.format(source.id)
search_dict = {'fq': fq}
context = {'model': model, 'session': model.Session}
result = logic.get_action('package_search')(context, search_dict)
return result.get('count', 0)

def harvesters_info():
context = {'model': model, 'user': p.toolkit.c.user or p.toolkit.c.author}
return logic.get_action('harvesters_info_show')(context,{})
Expand Down
1 change: 1 addition & 0 deletions ckanext/harvest/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ def get_helpers(self):
from ckanext.harvest import helpers as harvest_helpers
return {
'package_list_for_source': harvest_helpers.package_list_for_source,
'package_count_for_source': harvest_helpers.package_count_for_source,
'harvesters_info': harvest_helpers.harvesters_info,
'harvester_types': harvest_helpers.harvester_types,
'harvest_frequencies': harvest_helpers.harvest_frequencies,
Expand Down
4 changes: 1 addition & 3 deletions ckanext/harvest/templates/source/read_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ <h1 class="heading">{{ c.harvest_source.title }}</h1>
{% endif %}
<div class="nums">
<dl>
{% if c.harvest_source.status %}
<dt>{{ _('Datasets') }}</dt>
<dd>{{ c.harvest_source.status.total_datasets }}</dd>
{% endif %}
<dd>{{ h.package_count_for_source(c.harvest_source.id) }}</dd>
</dl>
</div>
</section>
Expand Down

0 comments on commit 0cbb941

Please sign in to comment.