Skip to content

Commit

Permalink
Merge pull request #429 from vrk-kpa/LIKA-593_featured-datasets-criteria
Browse files Browse the repository at this point in the history
LIKA-593: Only show subsystems with a description and services on front page
  • Loading branch information
bzar authored Feb 14, 2024
2 parents c835b3c + cbd59ed commit bea990e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 11 additions & 2 deletions ckanext/ckanext-apicatalog/ckanext/apicatalog/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,17 @@ def get_orgs_with_visible_packages(ids):


def get_homepage_datasets(count=1):
datasets = get_action('package_search')({}, {'q': 'type:dataset', 'rows': count}).get('results', [])
return datasets
context = {}
datasets = package_generator(context=context,
query='res_name:*',
page_size=count*5,
sort='metadata_created desc',
dataset_type='dataset')

def criteria(dataset):
return dataset.get('notes') and len(dataset.get('resources', [])) > 0

return list(itertools.islice(filter(criteria, datasets), count))


NEWS_CACHE = None
Expand Down
5 changes: 3 additions & 2 deletions ckanext/ckanext-apicatalog/ckanext/apicatalog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
ResourceDict = Dict[str, Any]


def package_generator(context, query='*:*', page_size=1000, dataset_type='dataset'):
def package_generator(context, query='*:*', page_size=1000,
sort='score desc, metadata_modified desc', dataset_type='dataset'):
package_search = toolkit.get_action('package_search')

# Loop through all items. Each page has {page_size} items.
# Stop iteration when all items have been looped.
for index in itertools.count(start=0, step=page_size):
data_dict = {'include_private': True, 'rows': page_size, 'q': query, 'start': index,
'fq': '+dataset_type:' + dataset_type}
'fq': '+dataset_type:' + dataset_type, 'sort': sort}
data = package_search(context, data_dict)
packages = data.get('results', [])
for package in packages:
Expand Down

0 comments on commit bea990e

Please sign in to comment.