Extension Dataset type selector for adding new data


Extension Basics

Title
Dataset type selector for adding new data
Name
ckanext-create_typed_package
Type
Public extension
Description
Select dataset type when clicking 'Add dataset' button with modal or separate page interface
CKAN versions

~2.9, ~2.10, ~2.11

Show details
Download-Url (zip)
Download-Url commit date
2024-01-01
Url to repo
Category
Specialized Tools


Background Infos

Description (long)
Show details

This extension adds a widget/page for selecting dataset type when creating new datasets. Features include: modal dialog for dataset type selection after clicking ‘Add Dataset’, alternative separate page route for type selection (/dataset/select-type), automatic redirection when only one type available, dynamic type list via chained action ctp_list_types for context-dependent options (e.g., organization-specific types), integration with ckanext-scheming for type definitions, optional ‘Add Dataset’ button replacement with type selector link, customizable labels for each dataset type, configurable route path, exclude/include specific types from selector, use scheming API or CKAN internal registry for type list. Works with any custom dataset types (via scheming or CKAN type registry). Requires custom dataset types to be pre-configured. Python 3.8-3.12 compatible. Beta development status. AGPL licensed. Depends on ckantoolkit.

Version
0.5.2
Version release date
2024-01-01
Contact name
DataShades
Contakt email
Contact Url
(not set)


Installation Guide

Configuration hints

Install via pip:

pip install ckanext-create-typed-package

Enable the plugin:

ckan.plugins = create_typed_package

Note: Extension requires pre-configured custom dataset types (via ckanext-scheming or CKAN type registry).

Example with ckanext-scheming:

pip install ckanext-scheming

ckan.plugins = scheming_datasets create_typed_package

scheming.dataset_schemas = path/to/schema1.yaml path/to/schema2.yaml

Configuration options:

Build type list using ckanext-scheming API instead of CKAN’s package_type registry (optional, default: false)

create_typed_package.use_scheming = true

Additional types not automatically added to the list (optional, default: [])

create_typed_package.additional_types = custom_type another_type

Exclude specific types from available list (optional, default: [])

create_typed_package.exclude_types = unwanted_type another_unwanted

Use separate page instead of modal for type selection (optional, default: false)

create_typed_package.use_separate_route = true

Replace ‘Add Dataset’ button with link to type selection (requires use_separate_route=true, optional, default: false)

create_typed_package.replace_dataset_button = true

Custom URL for type selector page (optional, default: /dataset/select-type)

create_typed_package.route_path = /create-package/select-type

Custom labels for dataset types (optional, default: tk._(type_machine_name))

create_typed_package.label_for. = Human Readable Label

create_typed_package.label_for.dataset = Publication

Dynamic type options (advanced):

Implement IAction interface and register chained action ‘ctp_list_types’ to provide context-dependent type lists:

import ckan.plugins.toolkit as tk
from ckan.types import Context

@tk.chained_action
@tk.side_effect_free
def ctp_list_types(next_action, context: Context, data_dict):
    if tk.get_endpoint() == ("organization", "read"):
        organization_id = tk.request.view_args.id
        allowed_types = ...  # compute types for organization
        return [
            {"name": item.VALUE, "label": item.LABEL}
            for item in allowed_types
        ]
    return next_action(context, data_dict)

Action must return list of dicts with ‘name’ (machine name) and ‘label’ (human readable).

Behavior: - If action returns >1 item: modal/page with selector shown - If action returns exactly 1 item: redirect directly to that type’s form

UI modes: 1. Modal (default): JavaScript-based modal after clicking ‘Add Dataset’ 2. Separate page: /dataset/select-type (enable via use_separate_route) 3. Button replacement: Replace original button with selector link (requires use_separate_route)

Requirements: - Python >= 3.8 - Custom dataset types configured (ckanext-scheming recommended) - ckantoolkit dependency

Plugins to configure (ckan.ini)
create_typed_package
CKAN Settings (ckan.ini)
# create_typed_package.use_separate_route = true to the CKAN config file. Then # create_typed_package.replace_dataset_button = true to the CKAN config file: # create_typed_package.use_scheming = true # create_typed_package.additional_types = custom_type another_type # create_typed_package.exclude_types = custom_type another_type # create_typed_package.route_path = /create-package/select-type # create_typed_package.label_for.dataset = Publication
DB migration to be executed
(not set)
<< back to Extensions