From cbd59ed2a865858020b50157ee79f4a9e05af0fa Mon Sep 17 00:00:00 2001 From: Teemu Erkkola Date: Wed, 14 Feb 2024 15:09:43 +0200 Subject: [PATCH] LIKA-593: Only show subsystems with a description and services on front page --- .../ckanext-apicatalog/ckanext/apicatalog/plugin.py | 13 +++++++++++-- .../ckanext-apicatalog/ckanext/apicatalog/utils.py | 5 +++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ckanext/ckanext-apicatalog/ckanext/apicatalog/plugin.py b/ckanext/ckanext-apicatalog/ckanext/apicatalog/plugin.py index 3373b469..1d4ce360 100644 --- a/ckanext/ckanext-apicatalog/ckanext/apicatalog/plugin.py +++ b/ckanext/ckanext-apicatalog/ckanext/apicatalog/plugin.py @@ -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 diff --git a/ckanext/ckanext-apicatalog/ckanext/apicatalog/utils.py b/ckanext/ckanext-apicatalog/ckanext/apicatalog/utils.py index 08368a32..bb4b397b 100644 --- a/ckanext/ckanext-apicatalog/ckanext/apicatalog/utils.py +++ b/ckanext/ckanext-apicatalog/ckanext/apicatalog/utils.py @@ -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: