#29 make new idatasets form work with harvest source form

This commit is contained in:
kindly 2013-03-25 17:38:07 +00:00
parent 548d3c1c2a
commit c754479014
3 changed files with 18 additions and 26 deletions

View File

@ -10,7 +10,7 @@ from ckan import model
from ckan.model import Session, Package from ckan.model import Session, Package
from ckan.logic import ValidationError, NotFound, get_action from ckan.logic import ValidationError, NotFound, get_action
from ckan.logic.schema import default_package_schema from ckan.logic.schema import default_create_package_schema
from ckan.lib.navl.validators import ignore_missing,ignore from ckan.lib.navl.validators import ignore_missing,ignore
from ckan.lib.munge import munge_title_to_name,substitute_ascii_equivalents from ckan.lib.munge import munge_title_to_name,substitute_ascii_equivalents
@ -124,7 +124,7 @@ class HarvesterBase(SingletonPlugin):
''' '''
try: try:
# Change default schema # Change default schema
schema = default_package_schema() schema = default_create_package_schema()
schema['id'] = [ignore_missing, unicode] schema['id'] = [ignore_missing, unicode]
schema['__junk'] = [ignore] schema['__junk'] = [ignore]

View File

@ -47,7 +47,7 @@ def harvest_source_schema():
return schema return schema
def harvest_source_form_to_db_schema(): def harvest_source_create_package_schema():
schema = harvest_source_schema() schema = harvest_source_schema()
schema['__extras'] = [harvest_source_extra_validator] schema['__extras'] = [harvest_source_extra_validator]
@ -56,7 +56,7 @@ def harvest_source_form_to_db_schema():
return schema return schema
def harvest_source_db_to_form_schema(): def harvest_source_show_package_schema():
schema = harvest_source_schema() schema = harvest_source_schema()
schema.update({ schema.update({

View File

@ -135,43 +135,35 @@ class Harvest(p.SingletonPlugin, DefaultDatasetForm):
p.toolkit.c.dataset_type = DATASET_TYPE_NAME p.toolkit.c.dataset_type = DATASET_TYPE_NAME
def form_to_db_schema_options(self, options):
'''
Similar to form_to_db_schema but with further options to allow
slightly different schemas, eg for creation or deletion on the API.
'''
schema = self.form_to_db_schema()
# Tweak the default schema to allow using the same id as the harvest source def create_package_schema(self):
# if creating datasets for the harvest sources
if self.startup:
schema['id'] = [unicode]
return schema
def form_to_db_schema(self):
''' '''
Returns the schema for mapping package data from a form to a format Returns the schema for mapping package data from a form to a format
suitable for the database. suitable for the database.
''' '''
from ckanext.harvest.logic.schema import harvest_source_form_to_db_schema from ckanext.harvest.logic.schema import harvest_source_create_package_schema
schema = harvest_source_create_package_schema()
if self.startup:
schema['id'] = [unicode]
return harvest_source_form_to_db_schema() return schema
def db_to_form_schema_options(self, options): def update_package_schema(self):
''' '''
Similar to db_to_form_schema but with further options to allow Returns the schema for mapping package data from a form to a format
slightly different schemas, eg for creation or deletion on the API. suitable for the database.
''' '''
return self.db_to_form_schema() return self.create_package_schema()
def db_to_form_schema(self):
def show_package_schema(self):
''' '''
Returns the schema for mapping package data from the database into a Returns the schema for mapping package data from the database into a
format suitable for the form format suitable for the form
''' '''
from ckanext.harvest.logic.schema import harvest_source_db_to_form_schema from ckanext.harvest.logic.schema import harvest_source_show_package_schema
return harvest_source_db_to_form_schema() return harvest_source_show_package_schema()
def check_data_dict(self, data_dict, schema=None): def check_data_dict(self, data_dict, schema=None):
'''Check if the return data is correct, mostly for checking out '''Check if the return data is correct, mostly for checking out