コード例 #1
0
ファイル: navl_schema.py プロジェクト: boxkite/ckanext-canada
def _schema_update(schema, purpose):
    """
    :param schema: schema dict to update
    :param purpose: 'create', 'update' or 'show'
    """
    assert purpose in ('create', 'update', 'show')

    if purpose == 'create':
        schema['id'] = [
            ignore_missing, protect_new_dataset_id, unicode, name_validator,
            package_id_doesnt_exist
        ]
        schema['name'] = [
            ignore_missing, unicode, name_validator, package_name_validator
        ]
    if purpose in ('create', 'update'):
        schema['title'] = [not_empty_allow_override, unicode]
        schema['notes'] = [not_empty_allow_override, unicode]
        schema['owner_org'] = [
            not_empty, owner_org_validator_publisher, unicode
        ]
        schema['license_id'] = [not_empty_allow_override, unicode]
    else:
        schema['author_email'] = [
            fixed_value(schema_description.dataset_field_by_id['author_email'])
        ]
        schema['license_id'] = [
            fixed_value(schema_description.dataset_field_by_id['license_id'])
        ]
        schema['department_number'] = [get_department_number]
        schema['license_title_fra'] = [get_license_field('title_fra')]
        schema['license_url_fra'] = [get_license_field('url_fra')]

    resources = schema['resources']

    for name, lang, field in schema_description.dataset_field_iter():
        if name in schema:
            continue  # don't modify other existing fields

        v = _schema_field_validators(name, lang, field)
        if v is not None:
            schema[name] = v[0] if purpose != 'show' else v[1]

        if field['type'] == 'choice' and purpose in ('create', 'update'):
            schema[name].extend([
                convert_pilot_uuid(field),
                OneOf([c['key'] for c in field['choices']])
            ])

    for name, lang, field in schema_description.resource_field_iter():
        if field['mandatory'] and purpose in ('create', 'update'):
            resources[name] = [not_empty_allow_override, unicode]
        if field['type'] == 'choice' and purpose in ('create', 'update'):
            resources[name].extend([
                convert_pilot_uuid(field),
                OneOf([c['key'] for c in field['choices']])
            ])

    if purpose in ('create', 'update'):
        schema['validation_override'] = [ignore_missing]
コード例 #2
0
def _schema_update(schema, purpose):
    """
    :param schema: schema dict to update
    :param purpose: 'create', 'update' or 'show'
    """
    assert purpose in ('create', 'update', 'show')

    # XXX: remove duplicate_extras_key validation
    # to work around update failures on packages with
    # multiple portal_release_date values mistakenly added
    if '__before' in schema:
        schema['__before'] = [v for v in schema['__before']
            if v != duplicate_extras_key]

    if purpose == 'create':
        schema['id'] = [canada_validate_generate_uuid,
            unicode, name_validator, package_id_doesnt_exist]
        schema['name'] = [if_empty_same_as('id'), unicode, name_validator,
            package_name_validator]
    if purpose in ('create', 'update'):
        schema['title'] = [not_empty, unicode]
        schema['notes'] = [not_empty, unicode]
        schema['owner_org'] = [not_empty, owner_org_validator_publisher, unicode]
        schema['license_id'] = [not_empty, unicode]
    else:
        schema['author_email'] = [fixed_value(
            schema_description.dataset_field_by_id['author_email'])]
        schema['department_number'] = [get_department_number]
        schema['license_title_fra'] = [get_license_field('title_fra')]
        schema['license_url_fra'] = [get_license_field('url_fra')]

    resources = schema['resources']

    for name, lang, field in schema_description.dataset_field_iter():
        if name in schema:
            continue # don't modify other existing fields

        v = _schema_field_validators(name, lang, field)
        if v is not None:
            schema[name] = v[0] if purpose != 'show' else v[1]

        if field['type'] == 'choice' and purpose in ('create', 'update'):
            schema[name].extend([
                convert_pilot_uuid(field),
                OneOf([c['key'] for c in field['choices']])])

    for name, lang, field in schema_description.resource_field_iter():
        if field['mandatory'] and purpose in ('create', 'update'):
            resources[name] = [not_empty, unicode]
        if field['type'] == 'choice' and purpose in ('create', 'update'):
            resources[name].extend([
                convert_pilot_uuid(field),
                OneOf([c['key'] for c in field['choices']])])
コード例 #3
0
ファイル: navl_schema.py プロジェクト: boxkite/ckanext-canada
def _schema_update(schema, purpose):
    """
    :param schema: schema dict to update
    :param purpose: 'create', 'update' or 'show'
    """
    assert purpose in ('create', 'update', 'show')

    if purpose == 'create':
        schema['id'] = [ignore_missing, protect_new_dataset_id,
            unicode, name_validator, package_id_doesnt_exist]
        schema['name'] = [ignore_missing, unicode, name_validator,
            package_name_validator]
    if purpose in ('create', 'update'):
        schema['title'] = [not_empty_allow_override, unicode]
        schema['notes'] = [not_empty_allow_override, unicode]
        schema['owner_org'] = [not_empty, owner_org_validator_publisher, unicode]
        schema['license_id'] = [not_empty_allow_override, unicode]
    else:
        schema['author_email'] = [fixed_value(
            schema_description.dataset_field_by_id['author_email'])]
        schema['license_id'] = [fixed_value(
            schema_description.dataset_field_by_id['license_id'])]
        schema['department_number'] = [get_department_number]
        schema['license_title_fra'] = [get_license_field('title_fra')]
        schema['license_url_fra'] = [get_license_field('url_fra')]

    resources = schema['resources']

    for name, lang, field in schema_description.dataset_field_iter():
        if name in schema:
            continue # don't modify other existing fields

        v = _schema_field_validators(name, lang, field)
        if v is not None:
            schema[name] = v[0] if purpose != 'show' else v[1]

        if field['type'] == 'choice' and purpose in ('create', 'update'):
            schema[name].extend([
                convert_pilot_uuid(field),
                OneOf([c['key'] for c in field['choices']])])

    for name, lang, field in schema_description.resource_field_iter():
        if field['mandatory'] and purpose in ('create', 'update'):
            resources[name] = [not_empty_allow_override, unicode]
        if field['type'] == 'choice' and purpose in ('create', 'update'):
            resources[name].extend([
                convert_pilot_uuid(field),
                OneOf([c['key'] for c in field['choices']])])

    if purpose in ('create', 'update'):
        schema['validation_override'] = [ignore_missing]
コード例 #4
0
def _schema_update(schema, purpose):
    """
    :param schema: schema dict to update
    :param purpose: 'create', 'update' or 'show'
    """
    assert purpose in ('create', 'update', 'show')

    # XXX: remove duplicate_extras_key validation
    # to work around update failures on packages with
    # multiple portal_release_date values mistakenly added
    if '__before' in schema:
        schema['__before'] = [
            v for v in schema['__before'] if v != duplicate_extras_key
        ]

    if purpose == 'create':
        schema['id'] = [
            protect_new_dataset_id, if_empty_generate_uuid, unicode,
            name_validator, package_id_doesnt_exist
        ]
        schema['name'] = [
            if_empty_same_as('id'), unicode, name_validator,
            package_name_validator
        ]
    if purpose in ('create', 'update'):
        schema['title'] = [not_empty, unicode]
        schema['notes'] = [not_empty, unicode]
        schema['owner_org'] = [
            not_empty, owner_org_validator_publisher, unicode
        ]
        schema['license_id'] = [not_empty, unicode]
    else:
        schema['author_email'] = [
            fixed_value(schema_description.dataset_field_by_id['author_email'])
        ]
        schema['department_number'] = [get_department_number]
        schema['license_title_fra'] = [get_license_field('title_fra')]
        schema['license_url_fra'] = [get_license_field('url_fra')]

    resources = schema['resources']

    for name, lang, field in schema_description.dataset_field_iter():
        if name in schema:
            continue  # don't modify other existing fields

        v = _schema_field_validators(name, lang, field)
        if v is not None:
            schema[name] = v[0] if purpose != 'show' else v[1]

        if field['type'] == 'choice' and purpose in ('create', 'update'):
            schema[name].extend([
                convert_pilot_uuid(field),
                OneOf([c['key'] for c in field['choices']])
            ])

    for name, lang, field in schema_description.resource_field_iter():
        if field['mandatory'] and purpose in ('create', 'update'):
            resources[name] = [not_empty, unicode]
        if field['type'] == 'choice' and purpose in ('create', 'update'):
            resources[name].extend([
                convert_pilot_uuid(field),
                OneOf([c['key'] for c in field['choices']])
            ])