ckanext.kata package

Submodules

ckanext.kata.actions module

Kata’s action overrides.

ckanext.kata.actions.dataset_editor_add(context, data_dict)[source]

Adds a user and role to dataset

Parameters:
  • name (string) – dataset name
  • role (string) – admin, editor or reader
  • username (string) – user to be added
Return type:

message dict with ‘success’ and ‘msg’

ckanext.kata.actions.dataset_editor_delete(context, data_dict)[source]

Deletes user and role in a dataset

Parameters:
  • username (string) – user name to delete
  • id (string) – dataset id
  • role (string) – editor, admin or reader
Return type:

message dict with success and msg

ckanext.kata.actions.group_create(*args, **kwargs)
ckanext.kata.actions.group_delete(*args, **kwargs)
ckanext.kata.actions.group_list(context, data_dict)[source]

Return a list of the names of the site’s groups.

ckanext.kata.actions.group_update(*args, **kwargs)
ckanext.kata.actions.member_create(*args, **kwargs)
ckanext.kata.actions.member_delete(*args, **kwargs)
ckanext.kata.actions.organization_create(*args, **kwargs)
ckanext.kata.actions.organization_delete(*args, **kwargs)
ckanext.kata.actions.organization_update(*args, **kwargs)
ckanext.kata.actions.package_create(context, data_dict)[source]

Creates a new dataset.

Extends ckan’s similar method to instantly reindex the SOLR index, so that this newly added package emerges in search results instantly instead of during the next timed reindexing.

Parameters:
  • context – context
  • data_dict – data dictionary (package data)
Return type:

dictionary

ckanext.kata.actions.package_delete(context, data_dict)[source]

Deletes a package

Extends ckan’s similar method to instantly re-index the SOLR index. Otherwise the changes would only be added during a re-index (a rebuild of search index, to be specific).

Parameters:
  • context (dictionary) – context
  • data_dict (dictionary) – package data

Return the metadata of a dataset (package) and its resources.

Parameters:
  • id (string) – the id or name of the dataset
  • context (dictionary) – context
Return type:

dictionary

ckanext.kata.actions.package_show(context, data_dict)[source]

Return the metadata of a dataset (package) and its resources.

Parameters:id (string) – the id or name of the dataset
Return type:dictionary
ckanext.kata.actions.package_update(context, data_dict)[source]

Updates the dataset.

Extends ckan’s similar method to instantly re-index the SOLR index. Otherwise the changes would only be added during a re-index (a rebuild of search index, to be specific).

Parameters:
  • context (dict) – context
  • data_dict (dict) – dataset as dictionary
Return type:

dictionary

ckanext.kata.actions.related_create(context, data_dict)[source]

Uses different schema and adds logging. Otherwise does what ckan’s similar function does.

Parameters:
  • context (dictionary) – context
  • data_dict (dictionary) – related item’s data
Returns:

the newly created related item

Return type:

dictionary

ckanext.kata.actions.related_delete(*args, **kwargs)
ckanext.kata.actions.related_update(context, data_dict)[source]

Uses different schema and adds logging. Otherwise does what ckan’s similar function does.

Parameters:
  • context (dictionary) – context
  • data_dict (dictionary) – related item’s data
Returns:

the newly updated related item

Return type:

dictionary

ckanext.kata.actions.resource_create(*args, **kwargs)
ckanext.kata.actions.resource_delete(*args, **kwargs)
ckanext.kata.actions.resource_update(*args, **kwargs)

ckanext.kata.auth_functions module

ckanext.kata.auth_functions.edit_resource(context, data_dict)[source]

Check if a user is allowed edit a resource.

Parameters:
  • context – context
  • data_dict – data dictionary
Rype:

dictionary

ckanext.kata.auth_functions.is_owner(context, data_dict)[source]

This is used in “request edit rights” feature. Checks if the user is admin or editor of the package in question

Parameters:
  • context – context
  • data_dict (dictionary) – package data
Return type:

dictionary

ckanext.kata.auth_functions.package_delete(context, data_dict)[source]

Modified check from CKAN, whether the user has a permission to delete the package. In addition to privileges given by CKAN’s authorisation, also the package owner has full privileges in Kata.

Parameters:
  • context (dictionary) – context
  • data_dict (dictionary) – package data
Return type:

dictionary with ‘success’: True|False

ckanext.kata.controllers module

Controllers for Kata.

class ckanext.kata.controllers.AccessRequestController[source]

Bases: ckan.lib.base.BaseController

AccessRequestController class provides a feature to ask for editor rights to a dataset. On the other hand, it also provides the process to grant them upon request.

create_request(pkg_id)[source]

Creates a new editor access request in the database. Redirects the user to dataset view page

Parameters:pkg_id (string) – package id
render_edit_request(pkg_id)[source]

Renders a page for requesting editor access to the dataset.

unlock_access(id)[source]

Adds a user to role editor for a dataset and redirects the user to dataset view page

Parameters:id (string) – package id
class ckanext.kata.controllers.ContactController[source]

Bases: ckan.lib.base.BaseController

Add features to contact the dataset’s owner.

From the web page, this can be seen from the link telling that this dataset is accessible by contacting the author. The feature provides a form for message sending, and the message is sent via email.

render_contact(pkg_id)[source]

Render the contact form if allowed.

Parameters:pkg_id (string) – package id
render_request(pkg_id)[source]

Render the access request contact form if allowed.

Parameters:pkg_id (string) – package id
send_contact(pkg_id)[source]

Send a user message from CKAN to dataset distributor contact. Constructs the message and calls _send_if_allowed().

Redirects the user to dataset view page.

Parameters:pkg_id (string) – package id
send_request(pkg_id)[source]

Send a request to access data to CKAN dataset owner.

Constructs the message and calls _send_if_allowed().

Redirects the user to dataset view page.

Parameters:pkg_id (string) – package id
class ckanext.kata.controllers.KATAApiController[source]

Bases: ckan.controllers.api.ApiController

Functions for autocomplete fields in add dataset form

discipline_autocomplete()[source]

Suggestions for discipline

Return type:dictionary
location_autocomplete()[source]

Suggestions for spatial coverage

Return type:dictionary
media_type_autocomplete()[source]

Suggestions for mimetype

Return type:dictionary
tag_autocomplete()[source]

Suggestions for tags (keywords)

Return type:dictionary
class ckanext.kata.controllers.KataInfoController[source]

Bases: ckan.lib.base.BaseController

KataInfoController provides info pages, which are non-dynamic and visible for all

render_faq()[source]

Provides the FAQ page

render_help()[source]

Provides the help page

class ckanext.kata.controllers.KataPackageController[source]

Bases: ckan.controllers.package.PackageController

Adds advanced search feature.

Parse query parameters from different search form inputs, modify into one query string ‘q’ in the context and call basic search() method of the super class.

Returns:dictionary with keys results and count
dataset_editor_delete(name)[source]

Deletes a user from a dataset role.

Parameters:
  • name (string) – dataset name
  • username (string) – user (request.param) and role (request.param) to be deleted from dataset
  • role (string) – user (request.param) and role (request.param) to be deleted from dataset

redirects to dataset_editor_manage.

dataset_editor_manage(name)[source]

Manages (adds) editors and admins of a dataset and sends an invitation email if wanted in case user has not yet logged in to the service. The invitation email feature has no automatic features bound to it, it is a plain email sender.

Parameters:
  • name (string) – package name
  • username (string) – if username (request.param) and role (request.param) are set, the user is added for the role
  • role (string) – if username (request.param) and role (request.param) are set, the user is added for the role
  • email (string) – if email address (request.param) is given, an invitation email is sent

Renders the package_administration page via _show_dataset_role_page()

class ckanext.kata.controllers.KataUserController[source]

Bases: ckan.controllers.user.UserController

Overwrite logged_in function in the super class.

logged_in()[source]

Minor rewrite to redirect the user to the own profile page instead of the dashboard.

class ckanext.kata.controllers.MetadataController[source]

Bases: ckan.lib.base.BaseController

URN export

urnexport()[source]

The urnexport page

Returns:the packages with service generated urns
Return type:string
ckanext.kata.controllers.get_package_owner(package)[source]

Returns the user id of the package admin for the specified package. If multiple user accounts are associated with the package as admins, an arbitrary one is returned.

Parameters:package (dictionary) – package data
Returns:userid
Return type:string

ckanext.kata.converters module

Functions to convert dataset form fields from or to db fields.

ckanext.kata.converters.add_to_group(key, data, errors, context)[source]

Add a new group if it doesn’t yet exist.

Parameters:
  • key – key
  • data – data
  • errors – validation errors
  • context – context
ckanext.kata.converters.checkbox_to_boolean(key, data, errors, context)[source]

Convert HTML checkbox’s value (‘on’ / null) to boolean string

ckanext.kata.converters.convert_from_extras_kata(key, data, errors, context)[source]

Convert all extras fields from extras to data dict and remove fields from extras. Removal helps counter IndexError with unflatten after validation.

Parameters:
  • key – key
  • data – data
  • errors – validation errors
  • context – context
ckanext.kata.converters.convert_languages(key, data, errors, context)[source]

Convert ISO 639 language abbreviations to ISO 639-2 T. data[‘key’] may be a string with comma separated values or a single language code.

Parameters:
  • key – key
  • data – data
  • errors – validation errors
  • context – context
ckanext.kata.converters.convert_to_extras_kata(key, data, errors, context)[source]

Convert one extras fields from extras to data dict and remove fields from extras. Removal helps counter IndexError with unflatten after validation.

Parameters:
  • key – key
  • data – data
  • errors – validation errors
  • context – context

Not used?

ckanext.kata.converters.flattened_from_extras(key, data, errors, context)[source]

Convert a whole bunch of flattened key-value pairs from extras to a list of dicts in data_dict. Format in extras must be like key[0]_index_innerkey. For example: pids_02_provider.

Parameters:
  • key – The key to convert as tuple, for example (‘pids’,)
  • data – data
  • errors – validation errors
  • context – context
ckanext.kata.converters.flattened_to_extras(key, data, errors, context)[source]

Convert a flattened key-value pair from data_dict to extras. For example (pids, 0, provider) -> extras[‘pids_0_provider’].

Note

The key-value pairs to convert are before CKAN’s flattening in format pids: [{ id: ‘some pid’, type: ‘data’, ...},{ id: ‘other pid’, type: ‘data’, ...}]

Parameters:
  • key – key, for example (pids, 0, provider)
  • data – data
  • errors – validation errors
  • context – context
ckanext.kata.converters.from_extras_json(key, data, errors, context)[source]

Convert a field from JSON format in extras to data_dict. The key parameter is the field where to save values, so we need to search data_dict to find the correct value which we are converting.

Parameters:
  • key – key for example (‘pids’,)
  • data – data, contains value somewhere, like (‘extras’, 5, ‘value’)
  • errors – validation errors
  • context – context
ckanext.kata.converters.ltitle_from_extras(key, data, errors, context)[source]

Convert all title & language pairs from db format to dataset form format.

Parameters:
  • key – key
  • data – data
  • errors – validation errors
  • context – context
ckanext.kata.converters.ltitle_to_extras(key, data, errors, context)[source]

Convert title & language pair from dataset form to db format and validate. Title & language pairs will be stored in package_extra.

Parameters:
  • key – key
  • data – data
  • errors – validation errors
  • context – context
ckanext.kata.converters.org_auth_from_extras(key, data, errors, context)[source]

Convert (author, organization) pairs from package.extra to orgauths dict

Parameters:
  • key – key
  • data – data
  • errors – validation errors
  • context – context
ckanext.kata.converters.org_auth_to_extras(key, data, errors, context)[source]

Convert author and organization to extras

ckanext.kata.converters.remove_access_application_new_form(key, data, errors, context)[source]

If availability changes remove access_application_new_form.

Expecting string: True or False in data[‘key’].

Parameters:
  • key – key
  • data – data
  • errors – validation errors
  • context – context
ckanext.kata.converters.remove_disabled_languages(key, data, errors, context)[source]

If langdis == ‘True’, remove all languages.

Expecting language codes in data[‘key’].

Parameters:
  • key – key
  • data – data
  • errors – validation errors
  • context – context
ckanext.kata.converters.to_extras_json(key, data, errors, context)[source]

Convert a field to JSON format and store in extras.

ckanext.kata.converters.update_pid(key, data, errors, context)[source]

Replace an empty unicode string with random PID.

ckanext.kata.converters.xpath_to_extras(key, data, errors, context)[source]

Convert xpaths to extras

Parameters:
  • key – key
  • data – data
  • errors – validation errors
  • context – context

ckanext.kata.helpers module

Template helpers for Kata CKAN extension.

ckanext.kata.helpers.get_authors(data_dict)[source]

Get all authors from agent field in data_dict

ckanext.kata.helpers.get_contact(data_dict)[source]

Get one contact from data_dict

ckanext.kata.helpers.get_dict_field_errors(errors, field, index, name)[source]

Get errors correctly for fields that are represented as nested dict fields in data_dict.

Parameters:
  • errors – the error dict
  • field – field name
  • index – index, eg. agents are repeatable -> a certain agent might lie in index 2
  • name
Returns:

[u’error1’, u’error2’]

ckanext.kata.helpers.get_distributor(data_dict)[source]

Get a single distributor from agent field in data_dict

ckanext.kata.helpers.get_first_admin(id)[source]

Get the url of the first one with an admin role

Parameters:id – the package id
Returns:profile url
Return type:string
ckanext.kata.helpers.get_funder(data_dict)[source]

Get a single funder from agent field in data_dict

ckanext.kata.helpers.get_funders(data_dict)[source]

Get all funders from agent field in data_dict

ckanext.kata.helpers.get_if_url(data)[source]

Try to guess if data is sufficient type for rdf:about

Parameters:data – the data to check out
Return type:boolean
ckanext.kata.helpers.get_owner(data_dict)[source]

Get a single owner from agent field in data_dict

ckanext.kata.helpers.get_package_ratings(data)[source]

Create a metadata rating (1-5) for given dataset

Parameters:data – A CKAN data_dict
Returns:(rating, stars)
ckanext.kata.helpers.get_package_ratings_for_data_dict(data_dict)[source]

Create a metadata rating (1-5) for given data_dict.

This is the same as get_package_ratings() but can be used for getting metadata ratings e.g. for search results where only raw data_dicts are available rather than already-converted package dicts.

Parameters:data_dict – A CKAN data_dict
ckanext.kata.helpers.get_rdf_extras(pkg_dict)[source]

Get extras that have no defined location in rdf

Contains much “manual” stuff for keeping the logical order and for prettier display

Parameters:pkg_dict – the package data dict
Returns:[{ ‘key’: ‘the key’, ‘value’: ‘the value’}, {..}, ..]
Return type:list of dicts

Get related urls for package

ckanext.kata.helpers.get_rightscategory(license)[source]

Return rightscategory based on license id

Returns:LICENSED, COPYRIGHTED or PUBLIC DOMAIN
ckanext.kata.helpers.has_agents_field(data_dict, field)[source]

Return true if some of the data dict’s agents has attribute given in field.

ckanext.kata.helpers.has_contacts_field(data_dict, field)[source]

Return true if some of the data dict’s contacts has attribute given in field’.

ckanext.kata.helpers.kata_sorted_extras(list_)[source]

Used for outputting package extras, skips package_hide_extras

ckanext.kata.helpers.reference_update(ref)[source]
ckanext.kata.helpers.resolve_agent_role(role)[source]

Get a non-translated role name.

ckanext.kata.helpers.string_to_list(data)[source]

Split languages and make it a list for Genshi (read.rdf)

Parameters:data – the string to split
Return type:list

ckanext.kata.model module

Database model additions for Kata

class ckanext.kata.model.KataAccessRequest(follower_id, object_id)[source]

Bases: ckan.model.domain_object.DomainObject

Class for access requests.

created
classmethod get(follower_id, object_id)[source]

Return a UserFollowingDataset object for the given follower_id and object_id, or None if no such follower exists.

id
classmethod is_requesting(follower_id, object_id)[source]

Return True if follower_id is currently following object_id, False otherwise.

pkg_id
user_id
class ckanext.kata.model.UserExtra(**kwargs)[source]

Bases: vdm.sqlalchemy.base.RevisionedObjectMixin, vdm.sqlalchemy.base.StatefulObjectMixin, ckan.model.domain_object.DomainObject

Class for extra user profile info.

classmethod by_userid(userid)[source]

Return all user extra records belonging to User ‘userid’.

classmethod by_userid_key(userid, key)[source]

Return all user extra records belonging to User userid with key=key.

get_user()[source]
id
key
state
user
user_id
value
ckanext.kata.model.delete_tables()[source]

Delete data from some extra tables to prevent IntegrityError between tests.

ckanext.kata.model.setup()[source]

Creates the tables that are specified in this file

ckanext.kata.plugin module

Main plugin file for Kata CKAN extension. Compatible with CKAN 2.1 and 2.2.

class ckanext.kata.plugin.KataPlugin(**kwargs)[source]

Bases: ckan.plugins.core.SingletonPlugin, ckan.lib.plugins.DefaultDatasetForm, ckan.plugins.interfaces.IActions, ckan.plugins.interfaces.IConfigurer, ckan.plugins.interfaces.IFacets, ckan.plugins.interfaces.IRoutes, ckan.plugins.interfaces.IPackageController, ckan.plugins.interfaces.IConfigurable, ckan.plugins.interfaces.IDatasetForm, ckan.plugins.interfaces.IAuthFunctions, ckan.plugins.interfaces.ITemplateHelpers

Kata functionality and UI plugin.

before_index(pkg_dict)[source]

Modification to package dictionary before indexing it to Solr index. For example, we add resource mimetype to the index, modify agents and hide the email address

Parameters:pkg_dict – pkg_dict to modify
Returns:the modified package dict to be indexed
before_map(map)[source]

Override IRoutes.before_map()

Things to do before querying Solr. Basically used by the advanced search feature.

Parameters:data_dict – data_dict to modify
comments_template()[source]

Return location of the package comments page

configure(config)[source]

Pass configuration to plugins and extensions. Called by load_environment.

classmethod create_package_schema()

Return the schema for validating new dataset dicts.

Return type:schema
classmethod create_package_schema_ddi()

Modified schema for datasets imported with ddi reader. Some fields in ddi import are allowed to be missing.

Return type:schema
classmethod create_package_schema_oai_dc()

Modified schema for datasets imported with oai_dc reader. Some fields are missing, as the dublin core format doesn’t provide so many options

Return type:schema
dataset_facets(facets_dict, package_type)[source]

Update the dictionary mapping facet names to facet titles. The dict supplied is actually an ordered dict.

Example: {'facet_name': 'The title of the facet'}

Parameters:
  • facets_dict – the facets dictionary
  • package_type – eg. dataset
Returns:

the modified facets_dict

extract_search_params(data_dict)[source]

Extracts parameters beginning with ext_ from data_dict[‘extras’] for advanced search.

Parameters:data_dict – contains all parameters from search.html
Return type:unordered lists extra_terms and extra_ops, dict extra_dates
get_actions()[source]

Register actions.

get_auth_functions()[source]

Returns a dict of all the authorization functions which the implementation overrides

get_dict_field_errors(errors, field, index, name)[source]

Get errors correctly for fields that are represented as nested dict fields in data_dict.

Parameters:
  • errors – errors dictionary
  • field – field name
  • index – index
  • name
Returns:

[u’error1’, u’error2’]

get_helpers()[source]

Register helpers

has_agents_field(data_dict, field)[source]

Return true if some of the data dict’s agents has attribute given in field.

Return type:boolean
has_contacts_field(data_dict, field)[source]

Return true if some of the data dict’s contacts has attribute given in field’.

Return type:boolean
history_template()[source]

Return location of the package history page

is_custom_form(_dict)[source]

Template helper, used to identify ckan custom form

is_fallback()[source]

Overrides IDatasetForm.is_fallback() From CKAN documentation: “Returns true iff this provides the fallback behaviour, when no other plugin instance matches a package’s type.”

kata_sorted_extras(list_)[source]

Used for outputting package extras, skips package_hide_extras

new_template()[source]

Return location of the add dataset page

package_form()[source]

Return location of the main package page

package_types()[source]

Return an iterable of package types that this plugin handles.

parse_search_dates(data_dict, extra_dates)[source]

Parse extra date into query q into data_dict: data_dict[‘q’]: ((author:*onstabl*) OR (title:*edliest jok* AND tags:*somekeyword*) OR (title:sometitle NOT tags:*otherkeyword*)) AND metadata_modified:[1900-01-01T00:00:00.000Z TO 2000-12-31T23:59:59.999Z]

Parameters:
  • data_dict – full data_dict from package:search
  • extra_dates{'start': 1991, 'end': 1994, 'field': 'metadata_modified'}
parse_search_terms(data_dict, extra_terms, extra_ops)[source]

Parse extra terms and operators into query q into data_dict: data_dict[‘q’]: ((author:*onstabl*) OR (title:*edliest jok* AND tags:*somekeyword*) OR (title:sometitle NOT tags:*otherkeyword*)) Note that all ANDs and NOTs are enclosed in parenthesis by ORs. Outer parenthesis are for date limits to work correctly.

Parameters:
  • data_dict – full data_dict from package:search
  • extra_terms[(ext_organization-2, u’someOrg’), ...]
  • extra_ops[(ext_operator-2, u’AND’), ...]
read_template()[source]

Return location of the package read page

reference_update(ref)[source]
search_template()[source]

Return location of the package search page

setup_template_variables(context, data_dict)[source]

Override DefaultDatasetForm.setup_template_variables() form method from ckan.lib.plugins.py.

classmethod show_package_schema()

The data fields that are returned from CKAN for each dataset can be changed with this method. This method is called when viewing or editing a dataset.

Return type:schema
classmethod tags_schema()
update_config(config)[source]

This IConfigurer implementation causes CKAN to look in the templates directory when looking for the package_form()

classmethod update_package_schema()

Return the schema for validating updated dataset dicts.

Return type:schema
classmethod update_package_schema_oai_dc()

Modified schema for datasets imported with oai_dc reader. Some fields are missing, as the dublin core format doesn’t provide so many options

Return type:schema

ckanext.kata.schemas module

class ckanext.kata.schemas.Schemas[source]
classmethod create_package_schema()[source]

Return the schema for validating new dataset dicts.

Return type:schema
classmethod create_package_schema_ddi()[source]

Modified schema for datasets imported with ddi reader. Some fields in ddi import are allowed to be missing.

Return type:schema
classmethod create_package_schema_oai_dc()[source]

Modified schema for datasets imported with oai_dc reader. Some fields are missing, as the dublin core format doesn’t provide so many options

Return type:schema
classmethod show_package_schema()[source]

The data fields that are returned from CKAN for each dataset can be changed with this method. This method is called when viewing or editing a dataset.

Return type:schema
classmethod tags_schema()[source]
classmethod update_package_schema()[source]

Return the schema for validating updated dataset dicts.

Return type:schema
classmethod update_package_schema_oai_dc()[source]

Modified schema for datasets imported with oai_dc reader. Some fields are missing, as the dublin core format doesn’t provide so many options

Return type:schema

ckanext.kata.settings module

Settings and constants for Kata CKAN extension

ckanext.kata.tieteet module

ckanext.kata.urnhelper module

class ckanext.kata.urnhelper.URNHelper[source]

Bases: object

Class to generate the urn export feature

classmethod list_packages()[source]

Lists packages, which have names like urn:nbn:fi:csc-kata or ida. Generates the required xml data.

Returns:the packages with urns given by the service
Return type:string (xml)

ckanext.kata.utils module

Utility functions for Kata.

ckanext.kata.utils.convert_to_text(resource, resource_fname)[source]

Convert structured documents to pure text.

ckanext.kata.utils.dataset_to_resource(data_dict)[source]

Move some fields from dataset to resources. Used for saving to DB.

Now finds the first ‘dataset’ resource and updates it. Not sure how this should be handled with multiple ‘dataset’ resources. Maybe just remove all of them and add new ones as they all are expected to be present when updating a dataset.

Parameters:data_dict – the data dictionary
Returns:the modified data dictionary (resources handled)
ckanext.kata.utils.generate_pid()[source]

Generate a permanent Kata identifier

ckanext.kata.utils.get_field_title(key, _)[source]

Get correctly translated title for one search field

Parameters:_ – gettext translator
Returns:dict of titles for fields
ckanext.kata.utils.get_field_titles(_)[source]

Get correctly translated titles for search fields

Parameters:_ – gettext translator
Returns:dict of titles for fields
ckanext.kata.utils.hide_sensitive_fields(pkg_dict1)[source]

Hide fields that contain sensitive data. Modifies input dict directly.

Parameters:pkg_dict1 – data dictionary from package_show
Returns:the modified data dictionary
ckanext.kata.utils.label_list_yso(tag_url)[source]

Takes tag keyword URL and fetches the labels that link to it.

Returns:the labels
ckanext.kata.utils.resource_to_dataset(data_dict)[source]

Move some fields from resources to dataset. Used for viewing a dataset.

We need field conversions to make sure the whole ‘resources’ key in datadict doesn’t get overwritten when modifying the dataset in WUI. That would drop all manually added resources if resources was already present.

Parameters:data_dict – the data dictionary
Returns:the modified data dictionary (resources handled)
ckanext.kata.utils.send_email(req)[source]

Send access request email.

Parameters:
  • user_id – user who requests access
  • pkg_id – dataset’s id

ckanext.kata.validators module

Validators for user inputs.

ckanext.kata.validators.check_access_request_url(key, data, errors, context)[source]

Validate dataset’s access request URL.

ckanext.kata.validators.check_agent(key, data, errors, context)[source]

Check that compulsory agents exist.

ckanext.kata.validators.check_agent_fields(key, data, errors, context)[source]

Check that compulsory fields for this agent exists.

ckanext.kata.validators.check_contact(key, data, errors, context)[source]

Check that compulsory contacts exist.

ckanext.kata.validators.check_direct_download_url(key, data, errors, context)[source]

Validate dataset’s direct download URL (resource.url).

ckanext.kata.validators.check_events(key, data, errors, context)[source]

Validates that none of the event’s data is empty If there is only type, removes it

ckanext.kata.validators.check_junk(key, data, errors, context)[source]

Checks the existence of ambiguous parameters

ckanext.kata.validators.check_langtitle(key, data, errors, context)[source]

Check that langtitle field exists

ckanext.kata.validators.check_last_and_update_pid(key, data, errors, context)[source]

Generates a pid (URN) for package if package.extras.version has changed.

ckanext.kata.validators.check_pids(key, data, errors, context)[source]

Check that pids field exists

ckanext.kata.validators.check_through_provider_url(key, data, errors, context)[source]

Validate dataset’s through_provider_URL.

ckanext.kata.validators.contains_alphanumeric(key, data, errors, context)[source]

Checks that the field contains some characters, so that eg. empty space isn’t a valid input

ckanext.kata.validators.kata_tag_name_validator(value, context)[source]

Checks an individual tag for unaccepted characters

ckanext.kata.validators.kata_tag_string_convert(key, data, errors, context)[source]

Takes a list of tags that is a comma-separated string (in data[key]) and parses tag names. These are added to the data dict, enumerated. They are also validated.

ckanext.kata.validators.package_name_not_changed(key, data, errors, context)[source]

Checks that package name doesn’t change

ckanext.kata.validators.validate_access_application_url(key, data, errors, context)[source]

Validate dataset’s access_application_URL.

Dummy value _must_ be added for a new form so that it can be overwritten in the same session in iPackageController edit hook. For REMS.

ckanext.kata.validators.validate_algorithm(key, data, errors, context)[source]

Matching to hash functions according to list in http://en.wikipedia.org/wiki/List_of_hash_functions

ckanext.kata.validators.validate_discipline(key, data, errors, context)[source]

Validate discipline

Parameters:key – ‘discipline’
ckanext.kata.validators.validate_email(key, data, errors, context)[source]

Validate an email address against a regular expression.

ckanext.kata.validators.validate_general(key, data, errors, context)[source]

General input validator. Validate arbitrary data for characters specified by GEN_REGEX

ckanext.kata.validators.validate_kata_date(key, data, errors, context)[source]

Validate a date string. Empty strings also pass.

ckanext.kata.validators.validate_kata_date_relaxed(key, data, errors, context)[source]

Validate a event date string. Empty strings also pass. 2001-03-01, 2001-03 and 2001 pass.

ckanext.kata.validators.validate_mimetype(key, data, errors, context)[source]

Validate mimetype, match to characters in http://www.freeformatter.com/mime-types-list.html#mime-types-list Also: http://www.iana.org/assignments/media-types

ckanext.kata.validators.validate_phonenum(key, data, errors, context)[source]

Validate a phone number against a regular expression.

ckanext.kata.validators.validate_spatial(key, data, errors, context)[source]

Validate spatial (aka geographical) coverage

Parameters:key – eg. ‘geographical_coverage’
ckanext.kata.validators.validate_title(key, data, errors, context)[source]

Check the existence of first title

ckanext.kata.validators.validate_title_duplicates(key, data, errors, context)[source]

Checks that there is only one title per language

ckanext.kata.vocab module

RDF Namespace definitions and some related functions.

ckanext.kata.vocab.Graph(*a, **kw)[source]
ckanext.kata.vocab.bind_ns(graph)[source]

Given an Graph, bind the namespaces present in the dictionary in this module to it for more readable serialisations.

Parameters:g – an instance of rdflib.graph.Graph.

Module contents

Kata extension for CKAN.

Provides modified Add Dataset (package) page and other modifications. This extension contains also jQuery files, custom css (eg. kata.css) and several templates are overwritten from basic CKAN to provide the Kata/TTA looks.