예제 #1
0
def harvest_source_schema():

    schema = {
        'id': [ignore_missing, unicode, package_id_exists],
        'type': [dataset_type_exists, unicode],
        'url': [not_empty, unicode, harvest_source_url_validator],
        'name': [not_empty, unicode, name_validator, package_name_validator],
        'source_type': [not_empty, unicode, harvest_source_type_exists,
                        convert_to_extras],
        'title': [if_empty_same_as("name"), unicode],
        'notes': [ignore_missing, unicode],
        'owner_org': [owner_org_validator, unicode],
        'private': [ignore_missing, boolean_validator],
        'organization': [ignore_missing],
        'frequency': [ignore_missing, unicode, harvest_source_frequency_exists,
                      convert_to_extras],
        'state': [ignore_missing],
        'config': [ignore_missing, harvest_source_config_validator,
                   convert_to_extras],
        'extras': default_extras_schema(),
    }

    extras_schema = default_extras_schema()
    extras_schema['__extras'] = [ignore]

    schema['extras'] = extras_schema

    if p.toolkit.check_ckan_version('2.2'):
        from ckan.logic.validators import \
            datasets_with_no_organization_cannot_be_private
        schema['private'].append(
            datasets_with_no_organization_cannot_be_private)

    return schema
예제 #2
0
def harvest_source_schema():

    schema = {
        'id': [ignore_missing, unicode, package_id_exists],
        'type': [dataset_type_exists, unicode],
        'url': [not_empty, unicode, harvest_source_url_validator],
        'name': [not_empty, unicode, name_validator, package_name_validator],
        'source_type':
        [not_empty, unicode, harvest_source_type_exists, convert_to_extras],
        'title': [if_empty_same_as("name"), unicode],
        'notes': [ignore_missing, unicode],
        'owner_org': [owner_org_validator, unicode],
        'organization': [ignore_missing],
        'frequency': [
            ignore_missing, unicode, harvest_source_frequency_exists,
            convert_to_extras
        ],
        'state': [ignore_missing],
        'config':
        [ignore_missing, harvest_source_config_validator, convert_to_extras],
        'extras':
        default_extras_schema(),
    }

    extras_schema = default_extras_schema()
    extras_schema['__extras'] = [ignore]

    schema['extras'] = extras_schema

    return schema
예제 #3
0
def harvest_source_schema():

    schema = {
        'id': [ignore_missing, six.text_type, package_id_exists],
        'type': [dataset_type_exists, six.text_type],
        'url': [not_empty, six.text_type, harvest_source_url_validator],
        'name': [not_empty, six.text_type, name_validator, package_name_validator],
        'source_type': [not_empty, six.text_type, harvest_source_type_exists, convert_to_extras],
        'title': [if_empty_same_as("name"), six.text_type],
        'notes': [ignore_missing, six.text_type],
        'owner_org': [owner_org_validator, six.text_type],
        'private': [ignore_missing, boolean_validator],
        'organization': [ignore_missing],
        'frequency': [ignore_missing, six.text_type, harvest_source_frequency_exists, convert_to_extras],
        'time': [ignore_missing, convert_to_extras],
        'state': [ignore_missing],
        'config': [ignore_missing, harvest_source_config_validator, convert_to_extras],
        'extras': default_extras_schema(),
    }

    extras_schema = default_extras_schema()
    extras_schema['__extras'] = [ignore]

    schema['extras'] = extras_schema

    if p.toolkit.check_ckan_version('2.2'):
        from ckan.logic.validators import datasets_with_no_organization_cannot_be_private
        schema['private'].append(datasets_with_no_organization_cannot_be_private)

    return schema
예제 #4
0
def harvest_source_schema():

    schema = {
        "id": [ignore_missing, unicode, package_id_exists],
        "type": [dataset_type_exists, unicode],
        "url": [not_empty, unicode, harvest_source_url_validator],
        "name": [not_empty, unicode, name_validator, package_name_validator],
        "source_type": [not_empty, unicode, harvest_source_type_exists, convert_to_extras],
        "title": [if_empty_same_as("name"), unicode],
        "notes": [ignore_missing, unicode],
        "owner_org": [owner_org_validator, unicode],
        "private": [ignore_missing, boolean_validator],
        "organization": [ignore_missing],
        "frequency": [ignore_missing, unicode, harvest_source_frequency_exists, convert_to_extras],
        "state": [ignore_missing],
        "config": [ignore_missing, harvest_source_config_validator, convert_to_extras],
        "extras": default_extras_schema(),
    }

    extras_schema = default_extras_schema()
    extras_schema["__extras"] = [ignore]

    schema["extras"] = extras_schema

    if p.toolkit.check_ckan_version("2.2"):
        from ckan.logic.validators import datasets_with_no_organization_cannot_be_private

        schema["private"].append(datasets_with_no_organization_cannot_be_private)

    return schema
예제 #5
0
def showcase_base_schema():
    schema = {
        'id': [empty],
        'revision_id': [ignore],
        'name': [not_empty, unicode, name_validator, package_name_validator],
        'title': [if_empty_same_as("name"), unicode],
        'author': [ignore_missing, unicode],
        'author_email': [ignore_missing, unicode],
        'notes': [ignore_missing, unicode],
        'url': [ignore_missing, unicode],
        'state': [ignore_not_package_admin, ignore_missing],
        'type': [ignore_missing, unicode],
        'log_message': [ignore_missing, unicode, no_http],
        '__extras': [ignore],
        '__junk': [empty],
        'resources': default_resource_schema(),
        'tags': default_tags_schema(),
        'tag_string': [ignore_missing, tag_string_convert],
        'extras': default_extras_schema(),
        'save': [ignore],
        'return_to': [ignore],
        'image_url': [toolkit.get_validator('ignore_missing'),
                      toolkit.get_converter('convert_to_extras')],
        'original_related_item_id': [
            toolkit.get_validator('ignore_missing'),
            toolkit.get_converter('convert_to_extras')]
    }
    return schema
예제 #6
0
    def form_to_db_schema(self, package_type=None):

        schema = {
            'title': [not_empty, unicode],
            'name': [not_empty, unicode, val.name_validator, val.package_name_validator],
            'notes': [not_empty, unicode],

            'date_released': [ignore_missing, date_to_db, convert_to_extras],
            'date_updated': [ignore_missing, date_to_db, convert_to_extras],
            'date_update_future': [ignore_missing, date_to_db, convert_to_extras],
            'last_major_modification': [ignore_missing, date_to_db, convert_to_extras],            
            'update_frequency': [ignore_missing, use_other, unicode, convert_to_extras],
            'update_frequency-other': [ignore_missing],
            'precision': [ignore_missing, unicode, convert_to_extras],
            'geographic_granularity': [ignore_missing, use_other, unicode, convert_to_extras],
            'geographic_granularity-other': [ignore_missing],
            'geographic_coverage': [ignore_missing, convert_geographic_to_db, convert_to_extras],
            'temporal_granularity': [ignore_missing, use_other, unicode, convert_to_extras],
            'temporal_granularity-other': [ignore_missing],
            'temporal_coverage-from': [date_to_db, convert_to_extras],
            'temporal_coverage-to': [date_to_db, convert_to_extras],
            'url': [ignore_missing, unicode],
            'taxonomy_url': [ignore_missing, unicode, convert_to_extras],

            'additional_resources': additional_resource_schema(),
            'timeseries_resources': timeseries_resource_schema(),
            'individual_resources': individual_resource_schema(),

            'groups': {
                'name': [not_empty, val.group_id_or_name_exists, unicode],
                'id': [ignore_missing, unicode],
            },

            'contact-name': [unicode, drop_if_same_as_publisher, convert_to_extras],
            'contact-email': [unicode, drop_if_same_as_publisher, convert_to_extras],
            'contact-phone': [unicode, drop_if_same_as_publisher, convert_to_extras],

            'foi-name': [unicode, drop_if_same_as_publisher, convert_to_extras],
            'foi-email': [unicode, drop_if_same_as_publisher, convert_to_extras],
            'foi-phone': [unicode, drop_if_same_as_publisher, convert_to_extras],
            'foi-web': [unicode, drop_if_same_as_publisher, convert_to_extras],

            'published_via': [ignore_missing, unicode, convert_to_extras],
            'mandate': [ignore_missing, unicode, convert_to_extras],
            'license_id': [unicode],
            'access_constraints': [ignore_missing, unicode],

            'tag_string': [ignore_missing, val.tag_string_convert],
            'national_statistic': [ignore_missing, convert_to_extras],
            'state': [val.ignore_not_admin, ignore_missing],

            'theme-primary': [not_empty, unicode, val.tag_string_convert, convert_to_extras],
            'theme-secondary': [ignore_missing, val.tag_string_convert, convert_to_extras],
            'extras': default_schema.default_extras_schema(),

            '__extras': [ignore],
            '__junk': [empty],
            '__after': [validate_license, remove_blank_resources, validate_resources, merge_resources]
        }
        return schema
예제 #7
0
    def test_convert_to_extras_free_extra_can_not_have_the_same_key(self):

        data_dict = {
            'custom_text': 'Hi',
            'extras': [
                {
                    'key': 'custom_text',
                    'value': 'Bye'
                },
            ]
        }

        schema = {
            'custom_text': [convert_to_extras],
            'extras': default_extras_schema(),
        }

        context = {
            'model': model,
            'session': model.Session,
        }

        data, errors = validate(data_dict, schema, context)

        assert 'extras' in errors
        eq_(errors['extras'], [{
            'key': [u'There is a schema field with the same name']
        }])
예제 #8
0
    def test_convert_to_extras_field_can_be_combined_with_extras_deleted(self):

        data_dict = {
            'custom_text': 'Hi',
            'extras': [
                {'key': 'proper_extra', 'value': 'Bye', 'deleted': True},
                {'key': 'proper_extra2', 'value': 'Bye2'},
            ]
        }

        schema = {
            'custom_text': [convert_to_extras],
            'extras': default_extras_schema(),
        }

        context = {
            'model': model,
            'session': model.Session,
        }

        data, errors = validate(data_dict, schema, context)

        assert 'extras' in data
        eq_(len(data['extras']), 3)
        eq_(sorted([e['key'] for e in data['extras']]),
            ['custom_text', 'proper_extra', 'proper_extra2'])
        eq_(sorted([e['value'] for e in data['extras']]),
            ['Bye', 'Bye2', 'Hi'])
예제 #9
0
def test_convert_to_extras_field_can_be_combined_with_a_proper_extra():

    data_dict = {
        "custom_text": "Hi",
        "extras": [{
            "key": "proper_extra",
            "value": "Bye"
        }],
    }

    schema = {
        "custom_text": [convert_to_extras],
        "extras": default_extras_schema(),
    }

    context = {"model": model, "session": model.Session}

    data, errors = validate(data_dict, schema, context)

    assert "extras" in data
    assert len(data["extras"]) == 2
    assert sorted([e["key"] for e in data["extras"]]) == [
        "custom_text",
        "proper_extra",
    ]
    assert sorted([e["value"] for e in data["extras"]]) == ["Bye", "Hi"]
예제 #10
0
    def test_convert_to_extras_field_can_be_combined_with_more_extras(self):

        data_dict = {
            'custom_text':
            'Hi',
            'extras': [
                {
                    'key': 'proper_extra',
                    'value': 'Bye'
                },
                {
                    'key': 'proper_extra2',
                    'value': 'Bye2'
                },
            ]
        }

        schema = {
            'custom_text': [convert_to_extras],
            'extras': default_extras_schema(),
        }

        context = {
            'model': model,
            'session': model.Session,
        }

        data, errors = validate(data_dict, schema, context)

        assert 'extras' in data
        eq_(len(data['extras']), 3)
        eq_(sorted([e['key'] for e in data['extras']]),
            ['custom_text', 'proper_extra', 'proper_extra2'])
        eq_(sorted([e['value'] for e in data['extras']]),
            ['Bye', 'Bye2', 'Hi'])
예제 #11
0
def custom_resource_extras_schema():

    not_missing = get_validator('not_missing')

    schema = default_extras_schema()

    schema['key'] = [not_empty, string_max_length(255), unicode]
    schema['value'] = [not_missing, string_max_length(64000)]

    return schema
예제 #12
0
    def _modify_package_schema(self, schema):
        schema.update({
            'theme-primary': [
                toolkit.get_validator('ignore_missing'),
                toolkit.get_validator('valid_theme'),
                toolkit.get_converter('convert_to_extras')
            ],
            'licence-custom': [
                toolkit.get_validator('ignore_missing'),
                toolkit.get_converter('convert_to_extras')
            ],
            'schema-vocabulary': [
                toolkit.get_validator('ignore_missing'),
                toolkit.get_converter('convert_to_extras')
            ],
            'codelist': [
                toolkit.get_validator('ignore_missing'),
                toolkit.get_converter('convert_to_extras')
            ],
            'author_email': [toolkit.get_validator('ignore_missing'), unicode],
            'maintainer_email':
            [toolkit.get_validator('ignore_missing'), unicode],
        })
        for contact_key in [
                'contact-name', 'contact-email', 'contact-phone', 'foi-name',
                'foi-email', 'foi-web', 'foi-phone'
        ]:
            schema.update({
                contact_key: [
                    toolkit.get_validator('ignore_missing'),
                    toolkit.get_converter('convert_to_extras')
                ]
            })

        from ckan.logic.schema import default_extras_schema
        from ckan.lib.navl.validators import not_empty
        from ckanext.datagovuk.logic.validators import extra_key_not_in_root_schema

        extras_schema = default_extras_schema()
        extras_schema['key'] = [
            not_empty,
            extra_key_not_in_root_schema,
            unicode,
        ]

        schema['extras'] = extras_schema

        schema['resources'].update({
            'resource-type': [toolkit.get_validator('ignore_missing')],
            'datafile-date': [toolkit.get_validator('ignore_missing')],
        })

        return schema
예제 #13
0
def harvest_source_schema():

    schema = {
        'id': [ignore_missing, unicode, package_id_exists],
        'type': [dataset_type_exists, unicode],
        'url': [not_empty, unicode, harvest_source_url_validator],
        'name': [not_empty, unicode, name_validator, package_name_validator],
        'source_type': [not_empty, unicode, harvest_source_type_exists, convert_to_extras],
        'title': [if_empty_same_as("name"), unicode],
        'notes': [ignore_missing, unicode],
        'owner_org': [owner_org_validator, unicode],
        'organization': [ignore_missing],
        'frequency': [ignore_missing, unicode, harvest_source_frequency_exists, convert_to_extras],
        'state': [ignore_missing],
        'config': [ignore_missing, harvest_source_config_validator, convert_to_extras],
        'extras': default_extras_schema(),
    }

    extras_schema = default_extras_schema()
    extras_schema['__extras'] = [ignore]

    schema['extras'] = extras_schema

    return schema
예제 #14
0
def test_convert_to_extras_field_gets_stored_as_extra():

    data_dict = {"custom_text": "Hi"}

    context = {"model": model, "session": model.Session}

    schema = {
        "custom_text": [convert_to_extras],
        "extras": default_extras_schema(),
    }

    data, errors = validate(data_dict, schema, context)

    assert "extras" in data
    assert len(data["extras"]) == 1
    assert data["extras"][0]["key"] == "custom_text"
    assert data["extras"][0]["value"] == "Hi"
예제 #15
0
    def test_convert_to_extras_field_gets_stored_as_extra(self):

        data_dict = {
            'custom_text': 'Hi',
        }

        context = {
            'model': model,
            'session': model.Session,
        }

        schema = {
            'custom_text': [convert_to_extras],
            'extras': default_extras_schema(),
        }

        data, errors = validate(data_dict, schema, context)

        assert 'extras' in data
        eq_(len(data['extras']), 1)
        eq_(data['extras'][0]['key'], 'custom_text')
        eq_(data['extras'][0]['value'], 'Hi')
예제 #16
0
    def test_convert_to_extras_field_gets_stored_as_extra(self):

        data_dict = {
            'custom_text': 'Hi',
        }

        context = {
            'model': model,
            'session': model.Session,
        }

        schema = {
            'custom_text': [convert_to_extras],
            'extras': default_extras_schema(),
        }

        data, errors = validate(data_dict, schema, context)

        assert 'extras' in data
        eq_(len(data['extras']), 1)
        eq_(data['extras'][0]['key'], 'custom_text')
        eq_(data['extras'][0]['value'], 'Hi')
예제 #17
0
def test_convert_to_extras_free_extra_can_not_have_the_same_key():

    data_dict = {
        "custom_text": "Hi",
        "extras": [{
            "key": "custom_text",
            "value": "Bye"
        }],
    }

    schema = {
        "custom_text": [convert_to_extras],
        "extras": default_extras_schema(),
    }

    context = {"model": model, "session": model.Session}

    data, errors = validate(data_dict, schema, context)

    assert "extras" in errors
    assert errors["extras"] == [{
        "key": [u"There is a schema field with the same name"]
    }]
예제 #18
0
    def test_convert_to_extras_free_extra_can_not_have_the_same_key(self):

        data_dict = {
            'custom_text': 'Hi',
            'extras': [
                {'key': 'custom_text', 'value': 'Bye'},
            ]
        }

        schema = {
            'custom_text': [convert_to_extras],
            'extras': default_extras_schema(),
        }

        context = {
            'model': model,
            'session': model.Session,
        }

        data, errors = validate(data_dict, schema, context)

        assert 'extras' in errors
        eq_(errors['extras'],
            [{'key': [u'There is a schema field with the same name']}])
예제 #19
0
    def _modify_package_schema(self, schema):
        schema.update({
            'theme-primary': [
                toolkit.get_validator('ignore_missing'),
                toolkit.get_validator('valid_theme'),
                toolkit.get_converter('convert_to_extras')
            ],
            'licence-custom': [
                toolkit.get_validator('ignore_missing'),
                toolkit.get_converter('convert_to_extras')
            ],
            'schema-vocabulary': [
                toolkit.get_validator('ignore_missing'),
                toolkit.get_converter('convert_to_extras')
            ],
            'codelist': [
                toolkit.get_validator('ignore_missing'),
                toolkit.get_converter('convert_to_extras')
            ],
            'author_email': [toolkit.get_validator('ignore_missing'), unicode],
            'maintainer_email':
            [toolkit.get_validator('ignore_missing'), unicode],
        })
        for contact_key in [
                'contact-name', 'contact-email', 'contact-phone', 'foi-name',
                'foi-email', 'foi-web', 'foi-phone'
        ]:
            schema.update({
                contact_key: [
                    toolkit.get_validator('ignore_missing'),
                    toolkit.get_converter('convert_to_extras')
                ]
            })

        from ckan.logic.schema import default_extras_schema
        from ckan.lib.navl.validators import ignore, not_empty
        from ckanext.datagovuk.logic.validators import extra_key_not_in_root_schema

        extras_schema = default_extras_schema()
        extras_schema['key'] = [
            not_empty,
            extra_key_not_in_root_schema,
            unicode,
        ]

        schema['extras'] = extras_schema

        schema['resources'].update({
            'resource-type': [toolkit.get_validator('ignore_missing')],
            'datafile-date': [toolkit.get_validator('ignore_missing')],
        })

        # was expecting:
        #   schema['harvest'] = [ignore]
        # to work but it doesn't prevent `harvest` from being added to
        # `__junk` which will cause updates on datasets to fail
        # See the issue on CKAN - https://github.com/ckan/ckan/issues/4989
        # as there may be better ways to resolve this issue
        schema['harvest'] = {'_': ignore}

        return schema
예제 #20
0
def showcase_base_schema():
    schema = {
        'id': [empty],
        'revision_id': [ignore],
        'name': [not_empty, unicode, name_validator, package_name_validator],
        'title': [if_empty_same_as("name"), unicode],
        'author': [ignore_missing, unicode],
        'author_email': [ignore_missing, unicode],
        'notes': [ignore_missing, unicode],
        'url': [ignore_missing, unicode],
        'state': [ignore_not_package_admin, ignore_missing],
        'type': [ignore_missing, unicode],
        'log_message': [ignore_missing, unicode, no_http],
        '__extras': [ignore],
        '__junk': [empty],
        'resources': default_resource_schema(),
        'tags': default_tags_schema(),
        'tag_string': [ignore_missing, tag_string_convert],
        'extras': default_extras_schema(),
        'save': [ignore],
        'return_to': [ignore],
        'groups': [ignore_missing, convert_group_names_to_group_objects],
    }

    # Extras
    schema['image_url'] = [
        toolkit.get_validator('ignore_missing'),
        toolkit.get_converter('convert_to_extras')
    ]
    schema['original_related_item_id'] = [
        toolkit.get_validator('ignore_missing'),
        toolkit.get_converter('convert_to_extras')
    ]
    schema['related_datasets'] = [
        toolkit.get_validator('ignore_missing'),
        toolkit.get_converter('convert_to_extras')
    ]
    schema['related_stories'] = [
        toolkit.get_validator('ignore_missing'),
        toolkit.get_converter('convert_to_extras')
    ]
    schema['story_date'] = [
        toolkit.get_validator('ignore_missing'),
        toolkit.get_converter('convert_to_extras')
    ]
    schema['story_type'] = [
        toolkit.get_validator('ignore_missing'),
        toolkit.get_converter('convert_to_extras')
    ]
    schema['methodology'] = [
        toolkit.get_validator('ignore_missing'),
        toolkit.get_converter('convert_to_extras')
    ]
    schema['spatial_text'] = [
        toolkit.get_validator('ignore_missing'),
        toolkit.get_converter('convert_to_extras')
    ]
    schema['author_title'] = [
        toolkit.get_validator('ignore_missing'),
        toolkit.get_converter('convert_to_extras')
    ]
    schema['author_workplace'] = [
        toolkit.get_validator('ignore_missing'),
        toolkit.get_converter('convert_to_extras')
    ]
    schema['author_profile'] = [
        toolkit.get_validator('ignore_missing'),
        toolkit.get_converter('convert_to_extras')
    ]

    # Extras (conditional)
    if config.get('disqus.name'):
        schema['allow_commenting'] = [
            toolkit.get_validator('ignore_missing'),
            toolkit.get_validator('boolean_validator'),
            toolkit.get_converter('convert_to_extras')
        ]

    return schema
예제 #21
0
    def form_to_db_schema(self, package_type=None):

        schema = {
            'title': [not_empty, unicode],
            'name': [
                not_empty, unicode, val.name_validator,
                val.package_name_validator
            ],
            'notes': [not_empty, unicode],
            'date_released': [ignore_missing, date_to_db, convert_to_extras],
            'date_updated': [ignore_missing, date_to_db, convert_to_extras],
            'date_update_future':
            [ignore_missing, date_to_db, convert_to_extras],
            'update_frequency':
            [ignore_missing, use_other, unicode, convert_to_extras],
            'update_frequency-other': [ignore_missing],
            'precision': [ignore_missing, unicode, convert_to_extras],
            'geographic_granularity':
            [ignore_missing, use_other, unicode, convert_to_extras],
            'geographic_granularity-other': [ignore_missing],
            'geographic_coverage':
            [ignore_missing, convert_geographic_to_db, convert_to_extras],
            'temporal_granularity':
            [ignore_missing, use_other, unicode, convert_to_extras],
            'temporal_granularity-other': [ignore_missing],
            'temporal_coverage-from': [date_to_db, convert_to_extras],
            'temporal_coverage-to': [date_to_db, convert_to_extras],
            'url': [ignore_missing, unicode],
            'taxonomy_url': [ignore_missing, unicode, convert_to_extras],
            'additional_resources':
            additional_resource_schema(),
            'timeseries_resources':
            timeseries_resource_schema(),
            'individual_resources':
            individual_resource_schema(),
            'groups': {
                'name': [not_empty, val.group_id_or_name_exists, unicode],
                'id': [ignore_missing, unicode],
            },
            'contact-name':
            [unicode, drop_if_same_as_publisher, convert_to_extras],
            'contact-email':
            [unicode, drop_if_same_as_publisher, convert_to_extras],
            'contact-phone':
            [unicode, drop_if_same_as_publisher, convert_to_extras],
            'foi-name':
            [unicode, drop_if_same_as_publisher, convert_to_extras],
            'foi-email':
            [unicode, drop_if_same_as_publisher, convert_to_extras],
            'foi-phone':
            [unicode, drop_if_same_as_publisher, convert_to_extras],
            'published_via': [ignore_missing, unicode, convert_to_extras],
            'mandate': [ignore_missing, unicode, convert_to_extras],
            'license_id': [unicode],
            'access_constraints': [ignore_missing, unicode],
            'tag_string': [ignore_missing, val.tag_string_convert],
            'national_statistic': [ignore_missing, convert_to_extras],
            'state': [val.ignore_not_admin, ignore_missing],
            'theme-primary':
            [not_empty, unicode, val.tag_string_convert, convert_to_extras],
            'theme-secondary': [
                ignore_missing, val.tag_string_convert, convert_to_extras
            ],
            'extras':
            default_schema.default_extras_schema(),
            '__extras': [ignore],
            '__junk': [empty],
            '__after': [
                validate_license, remove_blank_resources, validate_resources,
                merge_resources
            ]
        }
        return schema
예제 #22
0
    def form_to_db_schema(cls, package_type=None):

        schema = {
            'title': [not_empty, unicode],
            'name': [not_empty, unicode, val.name_validator, val.package_name_validator],
            'notes': [not_empty, unicode],

            'date_released': [ignore_missing, date_to_db, convert_to_extras],
            'date_updated': [ignore_missing, date_to_db, convert_to_extras],
            'date_update_future': [ignore_missing, date_to_db, convert_to_extras],
            'last_major_modification': [ignore_missing, date_to_db, convert_to_extras],
            'update_frequency': [ignore_missing, use_other, unicode, convert_to_extras],
            'update_frequency-other': [ignore_missing],
            'precision': [ignore_missing, unicode, convert_to_extras],
            'geographic_granularity': [ignore_missing, use_other, unicode, convert_to_extras],
            'geographic_granularity-other': [ignore_missing],
            'geographic_coverage': [ignore_missing, convert_geographic_to_db, convert_to_extras],
            'temporal_granularity': [ignore_missing, use_other, unicode, convert_to_extras],
            'temporal_granularity-other': [ignore_missing],
            'temporal_coverage-from': [ignore_missing, date_to_db, convert_to_extras],
            'temporal_coverage-to': [ignore_missing, date_to_db, convert_to_extras],
            'url': [ignore_missing, unicode],
            'taxonomy_url': [ignore_missing, unicode, convert_to_extras],

            'additional_resources': additional_resource_schema(),
            'timeseries_resources': timeseries_resource_schema(),
            'individual_resources': individual_resource_schema(),

            'owner_org': [val.owner_org_validator, unicode],
            'groups': {
                'name': [not_empty, val.group_id_or_name_exists, unicode],
                'id': [ignore_missing, unicode],
            },

            'contact-name': [ignore_missing, unicode, drop_if_same_as_publisher, convert_to_extras],
            'contact-email': [ignore_missing, unicode, drop_if_same_as_publisher, convert_to_extras],
            'contact-phone': [ignore_missing, unicode, drop_if_same_as_publisher, convert_to_extras],

            'foi-name': [ignore_missing, unicode, drop_if_same_as_publisher, convert_to_extras],
            'foi-email': [ignore_missing, unicode, drop_if_same_as_publisher, convert_to_extras],
            'foi-phone': [ignore_missing, unicode, drop_if_same_as_publisher, convert_to_extras],
            'foi-web': [ignore_missing, unicode, drop_if_same_as_publisher, convert_to_extras],

            'published_via': [ignore_missing, unicode, convert_to_extras],
            'mandate': [ignore_missing, to_list, remove_blanks, ignore_empty, to_json, convert_to_extras],
            'schema': [ignore_missing, to_list, schema_codelist_validator, remove_blanks, ignore_empty, to_json, convert_to_extras],
            'codelist': [ignore_missing, to_list, schema_codelist_validator, remove_blanks, ignore_empty, to_json, convert_to_extras],
            'sla': [ignore_missing, convert_to_extras],

            'license_id': [unicode],
            'access_constraints': [ignore_missing, unicode],

            'tags': tags_schema(),
            'tag_string': [ignore_missing, val.tag_string_convert],
            'national_statistic': [ignore_missing, convert_to_extras],
            'state': [val.ignore_not_admin, ignore_missing],

            'unpublished': [ignore_missing, bool_, convert_to_extras],
            'core-dataset': [ignore_missing, bool_, convert_to_extras],
            'release-notes': [ignore_missing, unicode, convert_to_extras],
            'publish-date': [ignore_missing, date_to_db, convert_to_extras],
            'publish-restricted': [ignore_missing, bool_, convert_to_extras],

            'theme-primary': [ignore_missing, unicode, convert_to_extras],
            'theme-secondary': [ignore_missing, to_json, convert_to_extras],
            'extras': default_schema.default_extras_schema(),

            # This is needed by the core CKAN update_resource, but isn't found by it because
            # we do the work in __after.
            'resources': resources_schema(),

            '__extras': [ignore],
            '__junk': [empty],
            '__after': [validate_license, remove_blank_resources, validate_resources, merge_resources]
        }
        return schema
예제 #23
0
def custom_extras_schema():
    schema = default_extras_schema()
    schema['key'] = [not_empty, extra_key_not_in_root_schema, unicode]
    return schema