2012-11-29 17:52:10 +01:00
|
|
|
from ckan.logic.schema import default_extras_schema
|
2012-11-29 12:48:36 +01:00
|
|
|
from ckan.logic.validators import (package_id_exists,
|
|
|
|
name_validator,
|
|
|
|
package_name_validator,
|
2012-11-29 17:52:10 +01:00
|
|
|
ignore_not_package_admin,
|
2012-11-29 12:48:36 +01:00
|
|
|
)
|
2012-11-30 14:20:37 +01:00
|
|
|
from ckan.logic.converters import convert_to_extras, convert_from_extras
|
2012-03-06 17:01:43 +01:00
|
|
|
|
2011-05-13 15:17:58 +02:00
|
|
|
from ckan.lib.navl.validators import (ignore_missing,
|
|
|
|
not_empty,
|
|
|
|
ignore,
|
2012-11-29 12:48:36 +01:00
|
|
|
if_empty_same_as,
|
2012-11-30 14:20:37 +01:00
|
|
|
)
|
2011-05-13 15:17:58 +02:00
|
|
|
|
2012-11-30 14:20:37 +01:00
|
|
|
from ckanext.harvest.logic.validators import (harvest_source_url_validator,
|
|
|
|
harvest_source_type_exists,
|
|
|
|
harvest_source_config_validator,
|
|
|
|
harvest_source_frequency_exists,
|
|
|
|
dataset_type_exists,
|
|
|
|
)
|
2012-11-29 12:48:36 +01:00
|
|
|
|
|
|
|
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],
|
|
|
|
'frequency': [ignore_missing, unicode, harvest_source_frequency_exists, convert_to_extras],
|
2012-11-29 17:52:10 +01:00
|
|
|
'state': [ignore_not_package_admin, ignore_missing],
|
|
|
|
'config': [ignore_missing, harvest_source_config_validator, convert_to_extras],
|
|
|
|
'extras': default_extras_schema(),
|
2012-11-30 14:20:37 +01:00
|
|
|
'__extras': [ignore],
|
2012-11-29 12:48:36 +01:00
|
|
|
}
|
|
|
|
|
2012-11-30 14:20:37 +01:00
|
|
|
extras_schema = default_extras_schema()
|
|
|
|
extras_schema['__extras'] = [ignore]
|
|
|
|
|
|
|
|
schema['extras'] = extras_schema
|
|
|
|
|
2012-11-29 12:48:36 +01:00
|
|
|
return schema
|
2011-05-13 15:17:58 +02:00
|
|
|
|
2012-11-30 14:20:37 +01:00
|
|
|
def harvest_source_form_to_db_schema():
|
2011-05-13 15:17:58 +02:00
|
|
|
|
2012-11-29 12:48:36 +01:00
|
|
|
schema = harvest_source_schema()
|
|
|
|
|
2011-05-13 15:17:58 +02:00
|
|
|
schema['save'] = [ignore]
|
2012-11-29 12:48:36 +01:00
|
|
|
schema.pop("id")
|
2011-05-13 15:17:58 +02:00
|
|
|
|
|
|
|
return schema
|
2012-11-29 12:48:36 +01:00
|
|
|
|
2012-11-30 14:20:37 +01:00
|
|
|
def harvest_source_db_to_form_schema():
|
|
|
|
|
|
|
|
schema = harvest_source_schema()
|
|
|
|
schema.update({
|
|
|
|
'source_type': [convert_from_extras, ignore_missing],
|
|
|
|
'frequency': [convert_from_extras, ignore_missing],
|
|
|
|
'config': [convert_from_extras, ignore_missing],
|
|
|
|
})
|
|
|
|
|
|
|
|
return schema
|