def showcase_package_list(context, data_dict): '''List packages associated with a showcase. :param showcase_id: id or name of the showcase :type showcase_id: string :rtype: list of dictionaries ''' toolkit.check_access('ckanext_showcase_package_list', context, data_dict) # validate the incoming data_dict validated_data_dict, errors = validate(data_dict, showcase_package_list_schema(), context) if errors: raise toolkit.ValidationError(errors) # get a list of package ids associated with showcase id pkg_id_list = ShowcasePackageAssociation.get_package_ids_for_showcase( validated_data_dict['showcase_id']) pkg_list = [] if pkg_id_list is not None: # for each package id, get the package dict and append to list if # active for pkg_id in pkg_id_list: pkg = toolkit.get_action('package_show')(context, {'id': pkg_id}) if pkg['state'] == 'active': pkg_list.append(pkg) return pkg_list
def showcase_package_list(context, data_dict): '''List packages associated with a showcase. :param showcase_id: id or name of the showcase :type showcase_id: string :rtype: list of dictionaries ''' toolkit.check_access('ckanext_showcase_package_list', context, data_dict) # validate the incoming data_dict validated_data_dict, errors = validate(data_dict, showcase_package_list_schema(), context) if errors: raise toolkit.ValidationError(errors) # get a list of package ids associated with showcase id pkg_id_list = ShowcasePackageAssociation.get_package_ids_for_showcase( validated_data_dict['showcase_id']) pkg_list = [] if pkg_id_list is not None: # for each package id, get the package dict and append to list if # active for pkg_id in pkg_id_list: pkg = toolkit.get_action('package_show')(context, {'id': pkg_id}) if pkg['state'] == 'active': pkg_list.append(pkg) return pkg_list
def showcase_package_list(context, data_dict): '''List packages associated with a showcase. :param showcase_id: id or name of the showcase :type showcase_id: string :rtype: list of dictionaries ''' toolkit.check_access('ckanext_showcase_package_list', context, data_dict) # validate the incoming data_dict validated_data_dict, errors = validate(data_dict, showcase_package_list_schema(), context) if errors: raise toolkit.ValidationError(errors) # get a list of package ids associated with showcase id pkg_id_list = ShowcasePackageAssociation.get_package_ids_for_showcase( validated_data_dict['showcase_id']) pkg_list = [] if pkg_id_list: # for each package id, get the package dict and append to list if # active id_list = [] for pkg_id in pkg_id_list: id_list.append(pkg_id[0]) q = 'id:(' + ' OR '.join(['{0}'.format(x) for x in id_list]) + ')' _pkg_list = toolkit.get_action('package_search')(context, { 'q': q, 'rows': 100 }) pkg_list = _pkg_list['results'] return pkg_list
def showcase_package_list(context, data_dict): '''List packages associated with a showcase. The context variable is passed forward as a copy to avoid unexpected side effects :rtype: list of package dictionaries ''' toolkit.check_access('ckanext_showcase_package_list', context.copy(), data_dict) # validate the incoming data_dict validated_data_dict, errors = validate(data_dict, showcase_package_list_schema(), context.copy()) if errors: raise toolkit.ValidationError(errors) # get a list of package ids associated with showcase id pkg_id_list = ShowcasePackageAssociation.get_package_ids_for_showcase( validated_data_dict['showcase_id']) pkg_list = [] if pkg_id_list: # for each package id, get the package dict and append to list if # active id_list = [] for pkg_id in pkg_id_list: id_list.append(pkg_id[0]) q = ' OR '.join(['id:{0}'.format(x) for x in id_list]) _pkg_list = toolkit.get_action('package_search')(context, { 'q': q, 'rows': 100 }) pkg_list = _pkg_list['results'] return pkg_list