跳转到主要内容

未提供项目描述

项目描述

Tests

ckanext-search-preset

插件,它添加了将搜索分面作为包字段存储和列出所有满足存储分面的数据集的API操作/帮助程序。

以下是一个示例,其中您可以使用此扩展

  • 您需要一个“包含”大量其他数据集的数据集。让我们称这个数据集为 集合
  • 这些“其他”数据集可以由一组固定的搜索分面来描述。例如:所有至少有一个 CSV资源CC-BY 许可证的 公共 数据集。
  • 您想在搜索页面上选择所有必要的分面❶,并从中触发 集合 的创建❷(在看到所有将要包含在 集合 中的目标数据集后)
  • 当集合创建时,您想在集合页面上看到所有满足给定分面的数据集❸。在将来,所有满足给定分面的新数据集应自动添加到集合页面上。

Preview of search page Preview of preset page

在上面的屏幕截图中,您可以观察此插件的默认行为。当然,这些小部件需要适当的样式。只需将它们用作起点(源代码位于当前扩展的 ckanext/search-preset/templates 文件夹中)并根据您的需求进行自定义。

内容

要求

此扩展需要Python v3.7或更高版本。

与核心CKAN版本的兼容性

CKAN版本 兼容?
2.9
2.10

安装

要安装ckanext-search-preset

  1. 通过pip安装扩展

    pip install ckanext-search-preset
    
  2. search-preset添加到您的CKAN配置文件中的ckan.plugins设置。

  3. 创建一个自定义包类型,它将充当预设(集合)的角色。这里您可以找到有关此包类型要求的更多详细信息。

配置设置

# Default preset type created by "Create Preset" button on the search page
ckanext.search_preset.default_type = preset

# List of preset types that should show matching packages(❷) on their details
# page
# (optional, default: <value of default_type option>).
ckanext.search_preset.package_types = preset collection dataset

# Field that is used for grouping the packages before printing them on the
# preset page
# (optional, default: none).
ckanext.search_preset.group_by_field = type

# Prefix of the preset fields that will hold details about active facets
# (optional, default: "search_preset_field_").
ckanext.search_preset.field_prefix = facet_field_

# List of facets that can be used by preset. By default, any existing facet is
# allowed.
# (optional, default: <any existing facet>).
ckanext.search_preset.allowed_facets = license_id organization

# Preset field that holds all the `ext_*` fields that were available during
# preset creation via ❶
# (optional, default: none).
ckanext.search_preset.extras_field = search_extra_field_

# List of `ext_*` that will be captured by preset if `extras_field` specified.
# By default, all the `ext_*` fields are captured.
# (optional, default: <any passed extra field>).
ckanext.search_preset.allowed_extras = ext_bbox ext_start_date

预设要求

为了正常工作,此扩展程序需要一个特殊的“预设”包类型。可以使用ckanext.search_preset.default_type配置选项注册一个默认预设类型(该类型将被现有小部件使用),并使用ckanext.search_preset.package_types配置选项注册任意数量的附加预设类型。

如果没有配置默认类型,搜索页面(❷)上的创建预设按钮将不会显示,但您仍然可以以编程方式创建搜索预设。

如果没有配置默认类型和附加类型,数据集不会显示在预设页面(❸)上。因为没有方法可以判断哪种包类型是“预设”类型,显然。

每次您使用❷创建预设时,所有活动的面元都将存储在预设包的定制字段中。您必须通过自定义包架构预先定义这些字段。插件将尝试将面元的值保存到名为<PREFIX><FACET_NAME>的字段中。默认前缀是search_preset_field_,您可以使用ckanext.search_preset.field_prefix配置选项更改它。因此,为了存储具有默认前缀的license_id面元,您必须定义一个名为search_preset_field_license_id的字段。

有关ckanext-schema的架构示例,其中包含保留license_idres_formattags面元值的预设定义,可以在ckanext/search-preset/example_preset.yaml中找到。

所有活动的面元都存储为值的JSON编码数组。这意味着您可以使用❷避免使用,例如使用ckanapi创建预设。

ckanapi action package_create \
    name=datasets-with-tag-xxx \
    type=<preset-type> \
    search_preset_field_tags='["xxx"]'

您可以从预设的示例架构开始,并根据您的需求进行调整。例如,您可以将纯输入字段替换为隐藏字段。

每次用户访问预设详细信息页面时,与预设的筛选器匹配的数据集列表将显示在页面底部。您可以重写负责此输出的Jinja2块和片段(❸)。

此外,可以通过ckanapi获取预设的包列表。

ckanapi action search_preset_preset_list id=<preset-id-or-name>

开发者安装

要为开发安装ckanext-search-preset,激活您的CKAN虚拟环境并执行

git clone https://github.com/DataShades/ckanext-search-preset.git
cd ckanext-search-preset
pip install -e '.[dev]'

测试

要运行测试,请执行

pytest --ckan-ini=test.ini

许可证

AGPL

项目详情


下载文件

下载适合您平台的自定义文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分发

ckanext-search-preset-0.0.1.tar.gz (25.7 kB 查看哈希

上传时间:

构建分发

ckanext_search_preset-0.0.1-py3-none-any.whl (27.5 kB 查看哈希

上传时间: Python 3