From 89e7fa098aeca5542a11769a2adc94ab630ef020 Mon Sep 17 00:00:00 2001 From: Jari Voutilainen Date: Tue, 5 Dec 2017 16:02:03 +0200 Subject: [PATCH] Add required fields to dataset schema --- .../ckanext/ytp/dataset/presets.json | 10 + .../ckanext/ytp/dataset/schemas/dataset.json | 177 +++++++++--------- .../ckanext/ytp/dataset/validators.py | 10 +- 3 files changed, 108 insertions(+), 89 deletions(-) diff --git a/modules/ckanext-ytp-main/ckanext/ytp/dataset/presets.json b/modules/ckanext-ytp-main/ckanext/ytp/dataset/presets.json index 73e55a5b18..0828322ef7 100644 --- a/modules/ckanext-ytp-main/ckanext/ytp/dataset/presets.json +++ b/modules/ckanext-ytp-main/ckanext/ytp/dataset/presets.json @@ -105,6 +105,16 @@ }, { "preset_name": "fluent_core_markdown_translated", + "values": { + "form_snippet": "fluent_markdown_ex.html", + "display_snippet": "fluent_markdown.html", + "error_snippet": "fluent_text.html", + "validators": "only_default_lang_required fluent_text", + "output_validators": "fluent_core_translated_output" + } + }, + { + "preset_name": "fluent_markdown_translated", "values": { "form_snippet": "fluent_markdown_ex.html", "display_snippet": "fluent_markdown.html", diff --git a/modules/ckanext-ytp-main/ckanext/ytp/dataset/schemas/dataset.json b/modules/ckanext-ytp-main/ckanext/ytp/dataset/schemas/dataset.json index 7cb8038c5a..faf370e071 100644 --- a/modules/ckanext-ytp-main/ckanext/ytp/dataset/schemas/dataset.json +++ b/modules/ckanext-ytp-main/ckanext/ytp/dataset/schemas/dataset.json @@ -20,19 +20,105 @@ "form_placeholder": "eg. my-dataset", "description": "An URL-address which refers to the dataset. The automatically filled option derived from the title is the best option in most cases." }, + { + "field_name": "notes_translated", + "preset": "fluent_core_markdown_translated", + "form_placeholder": "eg. A detailed description", + "form_languages": ["fi", "en", "sv"], + "label": "Description", + "display_snippet": null, + "only_default_lang_required": true, + "description": "An universal, compact and easy to understand description of the added dataset. Use as confining terms as possible to assist the user to understand what types of data, meters and dimensions the dataset contains." + }, { "field_name": "keywords", "label": "Tags", "form_placeholder":"eg. every second week", "form_languages": ["fi", "en", "sv"], "preset": "fluent_vocabulary_with_autocomplete", - "validators": "fluent_tags create_fluent_tags(keywords)", + "validators": "only_default_lang_required fluent_tags create_fluent_tags(keywords)", "form_attrs": { "data-module": "autocomplete", "data-module-tags": "", "data-module-source": "/api/2/util/tag/autocomplete?incomplete=?&vocabulary_id=keywords" }, - "description": "Keywords or tags through which users are able to find this dataset easily through the search page or other datasets which have the same tag." + "description": "Keywords or tags through which users are able to find this dataset easily through the search page or other datasets which have the same tag.", + "only_default_lang_required": true + }, + { + "field_name": "collection_type", + "label": "Collection type", + "preset": "select", + "choices": [ + { + "value": "Open Data", + "label": "Open data" + }, + { + "value": "Interoperability Tools", + "label": "Interoperability tools" + } + ], + "required": true + }, + { + "field_name": "maintainer", + "label": "Maintainer", + "form_placeholder": "Joe Bloggs", + "display_property": "dc:contributor", + "required": true + }, + { + "field_name": "maintainer_email", + "label": "Maintainer email", + "form_placeholder": "joe@example.com", + "display_property": "dc:contributor", + "display_snippet": "email.html", + "display_email_name_field": "maintainer", + "required": true + }, + { + "field_name": "maintainer_website", + "label": "Maintainer website", + "form_placeholder": "http://www.example.com", + "display_property": "dc:contributor", + "display_snippet": "link.html" + }, + { + "field_name": "private", + "label": "Visibility", + "form_snippet": "private.html", + "display_snippet": null, + "validators": "boolean_validator set_private_if_not_admin", + "description": "Private datasets will only be seen by the logged in users of the dataset's organization. Public datasets will be listed publicly through the search." + }, + { + "field_name": "owner_org", + "label": "Organization", + "preset": "dataset_organization_ex", + "description": "The organization which owns the dataset." + }, + { + "field_name": "owner", + "label": "Owner", + "form_placeholder": "Joe Bloggs" + }, + { + "field_name": "license_id", + "label": "License", + "preset": "sixodp_licence", + "form_snippet": "license.html", + "display_snippet": "license.html", + "required": true + }, + { + "field_name": "copyright_notice_translated", + "preset": "fluent_markdown_translated", + "form_placeholder": "eg. A detailed description", + "form_languages": ["fi", "en", "sv"], + "label": "Copyright notice", + "display_snippet": null, + "description": "An universal, compact and easy to understand description of the added dataset. Use as confining terms as possible to assist the user to understand what types of data, meters and dimensions the dataset contains." }, { "field_name": "content_type", @@ -61,16 +147,6 @@ }, "description": "Select the municipalities from which the dataset contains data." }, - { - "field_name": "notes_translated", - "preset": "fluent_core_markdown_translated", - "form_placeholder": "eg. A detailed description", - "form_languages": ["fi", "en", "sv"], - "label": "Description", - "display_snippet": null, - "only_default_lang_required": true, - "description": "An universal, compact and easy to understand description of the added dataset. Use as confining terms as possible to assist the user to understand what types of data, meters and dimensions the dataset contains." - }, { "field_name": "external_urls", "preset": "repeating_text", @@ -80,12 +156,7 @@ "form_snippet": "repeating.html", "description": "Links to additional information concerning the dataset." }, - { - "field_name": "owner_org", - "label": "Organization", - "preset": "dataset_organization_ex", - "description": "The organization which owns the dataset." - }, + { "field_name": "url", "label": "Source", @@ -94,27 +165,7 @@ "display_snippet": "link.html", "description": "The origin of the dataset." }, - { - "field_name": "maintainer", - "label": "Maintainer", - "form_placeholder": "Joe Bloggs", - "display_property": "dc:contributor" - }, - { - "field_name": "maintainer_email", - "label": "Maintainer email", - "form_placeholder": "joe@example.com", - "display_property": "dc:contributor", - "display_snippet": "email.html", - "display_email_name_field": "maintainer" - }, - { - "field_name": "maintainer_website", - "label": "Maintainer website", - "form_placeholder": "http://www.example.com", - "display_property": "dc:contributor", - "display_snippet": "link.html" - }, + { "field_name": "author", "label": "Author", @@ -129,19 +180,6 @@ "display_snippet": "email.html", "display_email_name_field": "author" }, - { - "field_name": "owner", - "label": "Owner", - "form_placeholder": "Joe Bloggs" - }, - { - "field_name": "private", - "label": "Visibility", - "form_snippet": "private.html", - "display_snippet": null, - "validators": "boolean_validator set_private_if_not_admin", - "description": "Private datasets will only be seen by the logged in users of the dataset's organization. Public datasets will be listed publicly through the search." - }, { "field_name": "update_frequency", "label": "Update frequency", @@ -156,39 +194,8 @@ }, "description": "A short description of how frequently the dataset will get updated." }, - { - "field_name": "license_id", - "label": "License", - "preset": "sixodp_licence", - "form_snippet": "license.html", - "display_snippet": "license.html", - "required": true - }, - { - "field_name": "copyright_notice_translated", - "preset": "fluent_core_markdown_translated", - "form_placeholder": "eg. A detailed description", - "form_languages": ["fi", "en", "sv"], - "label": "Copyright notice", - "display_snippet": null, - "description": "An universal, compact and easy to understand description of the added dataset. Use as confining terms as possible to assist the user to understand what types of data, meters and dimensions the dataset contains." - }, - { - "field_name": "collection_type", - "label": "Collection type", - "preset": "select", - "choices": [ - { - "value": "Open Data", - "label": "Open data" - }, - { - "value": "Interoperability Tools", - "label": "Interoperability tools" - } - ], - "required": true - }, + + { "field_name": "valid_from", "label": "Valid from", diff --git a/modules/ckanext-ytp-main/ckanext/ytp/dataset/validators.py b/modules/ckanext-ytp-main/ckanext/ytp/dataset/validators.py index 3282308fda..b37293be68 100644 --- a/modules/ckanext-ytp-main/ckanext/ytp/dataset/validators.py +++ b/modules/ckanext-ytp-main/ckanext/ytp/dataset/validators.py @@ -102,7 +102,9 @@ def add_to_vocab(context, tags, vocab): except ObjectNotFound: v = plugin.create_vocabulary(vocab) - context['vocabulary'] = model.Vocabulary.get(v.get('id')) + + if isinstance(tags, basestring): + tags = [tags] for tag in tags: validators.tag_length_validator(tag, context) @@ -232,14 +234,14 @@ def validator(key, data, errors, context): errors[key].append(_('expecting JSON object')) return - if value.get(default_lang) is None: + if field.get('only_default_lang_required') is not None and value.get(default_lang) is None: errors[key].append(_('Required language "%s" missing') % default_lang) return prefix = key[-1] + '-' extras = data.get(key[:-1] + ('__extras',), {}) - if extras.get(prefix + default_lang) == '': - errors[key[:-1] + (key[-1] + '-' + default_lang,)] = [_('Missing value')] + if extras.get(prefix + default_lang) == '' or extras.get(prefix + default_lang) is None: + errors[key].append(_('Required language "%s" missing') % default_lang) return validator