An extension to create URL aliases for datasets
Project description
The extension allow you to create a URL aliases for datasets. For example, if you have a dataset with my-dataset
name, it can be accessed via URL like that https://your-domain/dataset/my-dataset
. Now you could add multiple aliases that will redirect user to the dataset.
Creating and managing aliases is easy. There are two ways to create an alias.
- An alias could be created automatically, if the
ckanext.alias.autosave_alias
config option in enabled. (see Config settings section below) The automatic creation will be triggered only if the newname
differs from the previous one. - An alias could be created manually via dataset create/edit form.
Requirements
The extension has only been tested with CKAN 2.10.1
and will most likely not work with versions below 2.10
.
Also, the extension relies on ckanext-scheming
to add an alias
field into schema. It won't work without scheming.
If you don't know what is it and how to use it, check its repo.
Installation
- Use
pip
to install an extension:pip install ckanext-alias
- Add
alias
to theckan.plugins
setting in your CKAN config file.
Add an alias
field to schema
ckanext-alias
requires adjusting a dataset schema, to add an alias field that will store all the information. The extension provides multiple presets, which you could use to easilly adjust the schema.
-
Add presets
scheming.presets = ckanext.alias:presets.yaml
-
Open you schema. You have to edit
name
field and add a newalias
field:- field_name: name preset: dataset_alias_slug - field_name: alias preset: dataset_alias
- The
alias
field name must be the same asckanext.alias.alias_fieldname
. - Check
presets.yaml
file to see the presets in details. - If your
name
field was altered before, you don't have to use thedataset_alias_slug
preset. Just add thename_doesnt_conflict_with_alias
validator to list of yours.
- The
Config settings
The extension provides several configuration options to customize it.
# Specify a list of dataset types that is going to support aliases. Each specified dataset type schema
# must contain an alias field, otherwise, the extension isn't going to work (optional, default: dataset).
ckanext.alias.dataset_types = dataset project
# Specify an alias field name in dataset schema. The extension won't work, if the schema
# doesn't contain a specified field (optional, default: alias).
ckanext.alias.alias_fieldname = pkg_alias
# Specify whether a new alias will be created automatically on dataset update.
# If the name differs from the previous one, the alias will be created (optional, default: false).
ckanext.alias.autosave_alias = true
Developer installation
To install ckanext-alias for development, activate your CKAN virtualenv and do:
git clone https://github.com/mutantsan/ckanext-alias.git
cd ckanext-alias
python setup.py develop
pip install -r dev-requirements.txt
Tests
To run the tests, do:
pytest --ckan-ini=test.ini
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for ckanext_alias-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 449fd2db730c470fa078dc15863ea1cad8ead9e45e2387290f4f03418d737b5b |
|
MD5 | f0cdd5c5e3dca89586a6d08c288863e2 |
|
BLAKE2b-256 | c5b8f833e21b52d387b3b661224f1b1b8a03e537a81c0b86ccf3415cadd3044d |