def db_to_form_schema(self): # in CKAN 2.3: schema = ckan.logic.schema.default_show_group_schema() # TODO should be called by ckan.lib.plugins.DefaultGroupForm.db_to_form_schema # or return {} # CKAN 2.2 schema = self._default_show_group_schema() from_extras = tk.get_converter('convert_from_extras') optional = tk.get_validator('ignore_missing') not_empty = tk.get_validator('not_empty') default_validators = [from_extras, optional] schema.update({ # If i don't put these 'extras' entries in schema # dictization_functions.augment_data converts ('extras', '0', 'key') -> string # to ('extras', '0', '__extras') -> dict # and from_extras is cannot match ('extras', '0', 'key') and does nothing 'extras': { 'value': [], 'key': [] }, 'address_city': default_validators, 'address_postal_code': default_validators, 'address_street': default_validators, 'website': default_validators, 'email': default_validators, 'tel': default_validators, 'fax': default_validators, 'regon': default_validators, 'epuap': default_validators }) return schema
def db_to_form_schema(self): # in CKAN 2.3: schema = ckan.logic.schema.default_show_group_schema() # TODO should be called by ckan.lib.plugins.DefaultGroupForm.db_to_form_schema # or return {} # CKAN 2.2 schema = self._default_show_group_schema() from_extras = tk.get_converter("convert_from_extras") optional = tk.get_validator("ignore_missing") not_empty = tk.get_validator("not_empty") default_validators = [from_extras, optional] schema.update( { # If i don't put these 'extras' entries in schema # dictization_functions.augment_data converts ('extras', '0', 'key') -> string # to ('extras', '0', '__extras') -> dict # and from_extras is cannot match ('extras', '0', 'key') and does nothing "extras": {"value": [], "key": []}, "address_city": default_validators, "address_postal_code": default_validators, "address_street": default_validators, "website": default_validators, "email": default_validators, "tel": default_validators, "fax": default_validators, "regon": default_validators, "epuap": default_validators, } ) return schema
def _modify_package_schema(self, schema): schema.update({ 'inventory_entry_id': [get_converter('convert_to_extras'), get_validator('ignore_missing'), ] }) return schema
def show_package_schema(self): schema = super(InventoryPluginFix, self).show_package_schema() schema.update({ 'inventory_entry_id': [get_converter('convert_from_extras'), get_validator('ignore_missing')] }) return schema
def test_convert_from_extras(): from ckan import logic context = {"model": ckan.model, "session": ckan.model.Session} schema = ckan.logic.schema.default_create_package_schema() schema.update({"my_field": [logic.converters.convert_from_extras]}) data_dict = { "name": "my-pkg", "extras": [ { "key": "my_field", "value": "hola" }, { "key": "another_extra", "value": "caracola" }, ], } data, errors = validate(data_dict, schema, context) assert "my_field" in data assert data["my_field"] == "hola" assert data["extras"][0]["key"] == "another_extra"
def resource_view_create(context, data_dict): '''Creates a new resource view. :param resource_id: id of the resource :type resource_id: string :param title: the title of the view :type title: string :param description: a description of the view (optional) :type description: string :param view_type: type of view :type view_type: string :param config: options necessary to recreate a view state (optional) :type config: JSON string :returns: the newly created resource view :rtype: dictionary ''' model = context['model'] resource_id = _get_or_bust(data_dict, 'resource_id') view_type = _get_or_bust(data_dict, 'view_type') view_plugin = ckan.lib.datapreview.get_view_plugin(view_type) if not view_plugin: raise ValidationError( {"view_type": "No plugin found for view_type {view_type}".format( view_type=view_type )} ) default = logic.schema.default_create_resource_view_schema(view_plugin) schema = context.get('schema', default) plugin_schema = view_plugin.info().get('schema', {}) schema.update(plugin_schema) data, errors = _validate(data_dict, schema, context) if errors: model.Session.rollback() raise ValidationError(errors) _check_access('resource_view_create', context, data_dict) if context.get('preview'): return data max_order = model.Session.query( func.max(model.ResourceView.order) ).filter_by(resource_id=resource_id).first() order = 0 if max_order[0] is not None: order = max_order[0] + 1 data['order'] = order resource_view = model_save.resource_view_dict_save(data, context) if not context.get('defer_commit'): model.repo.commit() return model_dictize.resource_view_dictize(resource_view, context)
def db_to_form_schema(data, package_type=None): schema = logic.schema.package_form_schema() schema.update({ 'id': [ignore_missing, unicode], 'tags': { '__extras': [keep_extras, free_tags_only] }, 'alternative_title': [convert_from_extras, ignore_missing], 'status': [convert_from_tags(STATUS_VOCAB_NAME), ignore_missing], 'identifier': [convert_from_extras, ignore_missing], 'interoperability_level': [convert_from_tags(INTEROP_VOCAB_NAME), ignore_missing], 'type_of_dataset': [convert_from_tags(DATASET_TYPE_VOCAB_NAME), ignore_missing], 'published_by': [convert_from_groups('name')], 'capacity': [convert_from_groups('capacity')], 'release_date': [convert_from_extras, ignore_missing], 'modified_date': [convert_from_extras, ignore_missing], 'accrual_periodicity': [convert_from_extras, ignore_missing], 'temporal_coverage_from': [convert_from_extras, ignore_missing], 'temporal_coverage_to': [convert_from_extras, ignore_missing], 'temporal_granularity': [convert_from_tags(TEMPORAL_VOCAB_NAME), ignore_missing], 'geographical_coverage': [convert_from_tags(GEO_VOCAB_NAME), ignore_missing], 'language': [convert_from_tags(LANGUAGE_VOCAB_NAME), ignore_missing], 'metadata_language': [convert_from_extras, ignore_missing], 'version_description': [convert_from_extras, ignore_missing], 'rdf': [convert_from_extras, ignore_missing], 'contact_name': [convert_from_extras, ignore_missing], 'contact_email': [convert_from_extras, ignore_missing], 'contact_address': [convert_from_extras, ignore_missing], 'contact_telephone': [convert_from_extras, ignore_missing], 'contact_webpage': [convert_from_extras, ignore_missing], 'license_url': [ignore_missing], 'license_title': [ignore_missing], 'metadata_created': [ignore_missing], 'metadata_modified': [ignore_missing], '__after': [duplicate_extras_key, rename('tags', 'keywords'), rename('notes', 'description')] }) schema['groups'].update({ 'name': [not_empty, unicode], 'title': [ignore_missing], 'capacity': [ignore_missing, unicode] }) schema['resources'].update({ 'created': [ignore_missing], 'position': [not_empty], 'last_modified': [ignore_missing], 'cache_last_updated': [ignore_missing], 'webstore_last_updated': [ignore_missing] }) return schema
def _modify_package_schema(self, schema): schema.update({ 'inventory_entry_id': [ get_converter('convert_to_extras'), get_validator('ignore_missing'), ] }) return schema
def _modify_package_schema(self, schema): schema.update({ 'inventory_entry_id': [ get_converter('convert_to_extras'), get_converter('update_package_inventory_entry') ] }) return schema
def form_to_db_schema(self): schema = super(InventoryPlugin, self).form_to_db_schema() schema.update({ 'inventory_organization_id': [ get_validator('ignore_missing'), get_converter('convert_to_extras')] }) return schema
def db_to_form_schema(self): schema = ckan.logic.schema.default_show_group_schema() schema.update({ 'inventory_organization_id': [ get_validator('ignore_missing'), get_converter('convert_from_extras')] }) return schema
def resource_view_create(context, data_dict): '''Creates a new resource view. :param resource_id: id of the resource :type resource_id: string :param title: the title of the view :type title: string :param description: a description of the view (optional) :type description: string :param view_type: type of view :type view_type: string :param config: options necessary to recreate a view state (optional) :type config: JSON string :returns: the newly created resource view :rtype: dictionary ''' model = context['model'] resource_id = _get_or_bust(data_dict, 'resource_id') view_type = _get_or_bust(data_dict, 'view_type') view_plugin = ckan.lib.datapreview.get_view_plugin(view_type) if not view_plugin: raise ValidationError({ "view_type": "No plugin found for view_type {view_type}".format( view_type=view_type) }) default = logic.schema.default_create_resource_view_schema(view_plugin) schema = context.get('schema', default) plugin_schema = view_plugin.info().get('schema', {}) schema.update(plugin_schema) data, errors = _validate(data_dict, schema, context) if errors: model.Session.rollback() raise ValidationError(errors) _check_access('resource_view_create', context, data_dict) if context.get('preview'): return data max_order = model.Session.query(func.max( model.ResourceView.order)).filter_by(resource_id=resource_id).first() order = 0 if max_order[0] is not None: order = max_order[0] + 1 data['order'] = order resource_view = model_save.resource_view_dict_save(data, context) if not context.get('defer_commit'): model.repo.commit() return model_dictize.resource_view_dictize(resource_view, context)
def show_package_schema(self): schema = super(InventoryPluginFix, self).show_package_schema() schema.update({ 'inventory_entry_id': [ get_converter('convert_from_extras'), get_validator('ignore_missing') ] }) return schema
def db_to_form_schema(self): schema = ckan.logic.schema.default_show_group_schema() schema.update({ 'inventory_organization_id': [ get_validator('ignore_missing'), get_converter('convert_from_extras') ] }) return schema
def form_to_db_schema(self): schema = super(InventoryPlugin, self).form_to_db_schema() schema.update({ 'inventory_organization_id': [ get_validator('ignore_missing'), get_converter('convert_to_extras') ] }) return schema
def _db_to_edit_form_schema(self): schema = self._unique_email_user_schema(logic.schema.default_user_schema()) from_json = convert_from_json('about') ignore_missing = tk.get_validator('ignore_missing') schema.update({ 'official_position': [from_json, ignore_missing], 'official_phone': [from_json, ignore_missing], 'about': [] }) return schema
def form_to_db_schema(self, package_type=None): schema = logic.schema.package_form_schema() schema.update({ 'name': [not_empty, unicode, ecportal_name_validator, package_name_validator], 'license_id': [ignore_missing, reduce_list, map_licenses, unicode], 'keyword_string': [ignore_missing, keyword_string_convert], 'alternative_title': [ignore_missing, unicode, convert_to_extras], 'description': [not_empty, unicode], 'status': [not_empty, convert_to_tags(STATUS_VOCAB_NAME)], 'identifier': [ignore_missing, unicode, convert_to_extras], 'interoperability_level': [ignore_missing, convert_to_tags(INTEROP_VOCAB_NAME)], 'type_of_dataset': [ignore_missing, convert_to_tags(DATASET_TYPE_VOCAB_NAME)], 'published_by': [not_empty, unicode, publisher_exists, convert_to_groups('name')], 'capacity': [ignore_missing, unicode, default(u'private'), convert_to_groups('capacity')], 'release_date': [ignore_missing, ecportal_date_to_db, convert_to_extras], 'modified_date': [ignore_missing, ecportal_date_to_db, convert_to_extras], 'accrual_periodicity': [ignore_missing, unicode, convert_to_extras], 'temporal_coverage_from': [ignore_missing, ecportal_date_to_db, convert_to_extras], 'temporal_coverage_to': [ignore_missing, ecportal_date_to_db, convert_to_extras], 'temporal_granularity': [ignore_missing, convert_to_tags(TEMPORAL_VOCAB_NAME)], 'geographical_coverage': [ignore_missing, convert_to_tags(GEO_VOCAB_NAME)], 'language': [ignore_missing, convert_to_tags(LANGUAGE_VOCAB_NAME)], 'metadata_language': [ignore_missing, member_of_vocab(LANGUAGE_VOCAB_NAME), convert_to_extras], 'version_description': [ignore_missing, unicode, convert_to_extras], 'rdf': [ignore_missing, unicode, update_rdf, convert_to_extras], 'contact_name': [ignore_missing, unicode, convert_to_extras], 'contact_email': [ignore_missing, requires_field('contact_name'), unicode, convert_to_extras], 'contact_address': [ignore_missing, requires_field('contact_name'), unicode, convert_to_extras], 'contact_telephone': [ignore_missing, requires_field('contact_name'), unicode, convert_to_extras], 'contact_webpage': [ignore_missing, requires_field('contact_name'), unicode, convert_to_extras], '__after': [duplicate_extras_key, rename('keywords', 'tags'), rename('description', 'notes')], }) schema['groups'].update({ 'capacity': [ignore_missing, unicode] }) schema['resources'].update({ 'type': [ignore_missing, unicode, convert_resource_type] }) return schema
def form_to_db_schema(self): '''Return the schema for mapping group data from the form to the db.''' schema = ckan.logic.schema.group_form_schema() # Add CMAP's custom Group Type metadata field to the schema. schema.update({ 'cmap_group_type': [validators.ignore_missing, unicode, converters.convert_to_extras] }) # Add CMAP's custom Website URL metadata field to the schema. schema.update({'website_url': [validators.ignore_missing, unicode, converters.convert_to_extras]}) return schema
def form_to_db_schema(self): '''Return the schema for mapping group data from the form to the db.''' schema = ckan.logic.schema.group_form_schema() # Add CMAP's custom Group Type metadata field to the schema. schema.update({ 'cmap_group_type': [validators.ignore_missing, unicode, converters.convert_to_extras] }) # Add CMAP's custom Website URL metadata field to the schema. schema.update({ 'website_url': [validators.ignore_missing, unicode, converters.convert_to_extras] }) return schema
def _form_to_db_schema(self, schema): to_extras = tk.get_converter('convert_to_extras') optional = tk.get_validator('ignore_missing') not_empty = tk.get_validator('not_empty') default_validators = [not_empty, to_extras] schema.update({ 'address_city': default_validators, 'address_postal_code': default_validators, 'address_street': default_validators, 'website': default_validators, 'email': default_validators, 'tel': default_validators, 'fax': default_validators, 'regon': default_validators, 'epuap': default_validators }) return schema
def test_convert_from_extras(self): from ckan import logic context = {'model': ckan.model, 'session': ckan.model.Session} schema = ckan.logic.schema.default_create_package_schema() schema.update({ 'my_field': [logic.converters.convert_from_extras] }) data_dict = { 'name': 'my-pkg', 'extras': [ {'key': 'my_field', 'value': 'hola'}, {'key': 'another_extra', 'value': 'caracola'} ] } data, errors = validate(data_dict, schema, context) assert 'my_field' in data assert data['my_field'] == 'hola' assert data['extras'][0]['key'] == 'another_extra'
def _form_to_db_schema(self, schema): to_extras = tk.get_converter("convert_to_extras") optional = tk.get_validator("ignore_missing") not_empty = tk.get_validator("not_empty") default_validators = [not_empty, to_extras] schema.update( { "address_city": default_validators, "address_postal_code": default_validators, "address_street": default_validators, "website": default_validators, "email": default_validators, "tel": default_validators, "fax": default_validators, "regon": default_validators, "epuap": default_validators, } ) return schema
def test_convert_from_extras(self): from ckan import logic context = {'model': ckan.model, 'session': ckan.model.Session} schema = ckan.logic.schema.default_create_package_schema() schema.update({'my_field': [logic.converters.convert_from_extras]}) data_dict = { 'name': 'my-pkg', 'extras': [{ 'key': 'my_field', 'value': 'hola' }, { 'key': 'another_extra', 'value': 'caracola' }] } data, errors = validate(data_dict, schema, context) assert 'my_field' in data assert data['my_field'] == 'hola' assert data['extras'][0]['key'] == 'another_extra'
def form_to_db_schema_options(self, options): 'Use ODP schema for WUI and API calls' schema = self.form_to_db_schema() if options.get('api'): schema.update({ 'keywords': logic.schema.default_tags_schema(), 'groups': { 'id': [ignore_missing, unicode], 'name': [ignore_missing, unicode], '__extras': [ignore], } }) if options.get('type') == 'create': schema.update({'id': [empty]}) else: schema.update({ 'id': [ignore_missing, package_id_not_changed], 'name': [ignore_missing, ecportal_name_validator, package_name_validator, unicode], 'title': [ignore_missing, unicode] }) return schema
def form_to_db_schema(self): schema = ckan.logic.schema.form_to_db_package_schema() schema['groups']['capacity'] = [validators.ignore_missing, unicode] schema['__after'] = [group_required] schema.update({'cmap_geographical_level': [validators.ignore_missing, unicode, converters.convert_to_extras]}) schema.update({'cmap_data_family': [validators.ignore_missing, unicode, converters.convert_to_extras]}) schema.update({'cmap_data_category': [validators.ignore_missing, unicode, converters.convert_to_extras]}) schema.update({'cmap_data_subcategory': [validators.ignore_missing, unicode, converters.convert_to_extras]}) schema.update({'cmap_data_field': [validators.ignore_missing, unicode, converters.convert_to_extras]}) schema.update({'__junk': [validators.ignore]}) return schema
def form_to_db_schema(self): schema = super(YtpOrganizationsPlugin, self).form_to_db_schema() ignore_missing = toolkit.get_validator('ignore_missing') convert_to_extras = toolkit.get_converter('convert_to_extras') # schema for homepages # schema.update({'homepages': [ignore_missing, convert_to_list, unicode, convert_to_extras]}) schema.update( {'homepage': [ignore_missing, unicode, convert_to_extras]}) schema.update({ 'public_adminstration_organization': [ignore_missing, unicode, convert_to_extras] }) schema.update( {'producer_type': [ignore_missing, unicode, convert_to_extras]}) # schema for extra org info # schema.update({'business_id': [ignore_missing, unicode, convert_to_extras]}) # schema.update({'oid': [ignore_missing, unicode, convert_to_extras]}) # schema.update({'alternative_name': [ignore_missing, unicode, convert_to_extras]}) schema.update({ 'valid_from': [ignore_missing, date_validator, convert_to_extras] }) schema.update({ 'valid_till': [ignore_missing, date_validator, convert_to_extras] }) # schema for organisation address schema.update( {'street_address': [ignore_missing, unicode, convert_to_extras]}) # schema.update({'street_address_pobox': [ignore_missing, unicode, convert_to_extras]}) schema.update({ 'street_address_zip_code': [ignore_missing, unicode, convert_to_extras] }) schema.update({ 'street_address_place_of_business': [ignore_missing, unicode, convert_to_extras] }) # schema.update({'street_address_country': [ignore_missing, unicode, convert_to_extras]}) # schema.update({'street_address_unofficial_name': [ignore_missing, unicode, convert_to_extras]}) # schema.update({'street_address_building_id': [ignore_missing, unicode, convert_to_extras]}) # schema.update({'street_address_getting_there': [ignore_missing, unicode, convert_to_extras]}) # schema.update({'street_address_parking': [ignore_missing, unicode, convert_to_extras]}) # schema.update({'street_address_public_transport': [ignore_missing, unicode, convert_to_extras]}) # schema.update({'street_address_url_public_transport': [ignore_missing, unicode, convert_to_extras]}) schema = add_translation_modify_schema(schema) schema = add_languages_modify(schema, self._localized_fields) return schema
def db_to_form_schema(self): schema = ckan.logic.schema.group_form_schema() ignore_missing = toolkit.get_validator('ignore_missing') convert_from_extras = toolkit.get_converter('convert_from_extras') # add following since they are missing from schema schema.update({'num_followers': [ignore_missing]}) schema.update({'package_count': [ignore_missing]}) # Schema for homepages schema.update({'homepage': [convert_from_extras, ignore_missing]}) # schema for extra org info schema.update({'valid_from': [convert_from_extras, ignore_missing]}) schema.update({'valid_till': [convert_from_extras, ignore_missing]}) # schema for organisation address schema.update( {'street_address': [convert_from_extras, ignore_missing]}) schema.update( {'street_address_zip_code': [convert_from_extras, ignore_missing]}) schema.update({ 'street_address_place_of_business': [convert_from_extras, ignore_missing] }) schema.update({'producer_type': [convert_from_extras, ignore_missing]}) schema.update({ 'public_adminstration_organization': [convert_from_extras, ignore_missing] }) # old schema is used to display old data if it exists schema.update({ 'homepages': [convert_from_extras, from_json_to_object, ignore_missing] }) schema.update({'business_id': [convert_from_extras, ignore_missing]}) schema.update({'oid': [convert_from_extras, ignore_missing]}) schema.update( {'alternative_name': [convert_from_extras, ignore_missing]}) schema.update( {'street_address_pobox': [convert_from_extras, ignore_missing]}) schema.update( {'street_address_country': [convert_from_extras, ignore_missing]}) schema.update({ 'street_address_unofficial_name': [convert_from_extras, ignore_missing] }) schema.update({ 'street_address_building_id': [convert_from_extras, ignore_missing] }) schema.update({ 'street_address_getting_there': [convert_from_extras, ignore_missing] }) schema.update( {'street_address_parking': [convert_from_extras, ignore_missing]}) schema.update({ 'street_address_public_transport': [convert_from_extras, ignore_missing] }) schema.update({ 'street_address_url_public_transport': [convert_from_extras, ignore_missing] }) schema = add_translation_show_schema(schema) schema = add_languages_show(schema, self._localized_fields) return schema
def form_to_db_schema(self): schema = ckan.logic.schema.form_to_db_package_schema() schema['groups']['capacity'] = [validators.ignore_missing, unicode] schema['__after'] = [group_required] schema.update({ 'cmap_geographical_level': [validators.ignore_missing, unicode, converters.convert_to_extras] }) schema.update({ 'cmap_data_family': [validators.ignore_missing, unicode, converters.convert_to_extras] }) schema.update({ 'cmap_data_category': [validators.ignore_missing, unicode, converters.convert_to_extras] }) schema.update({ 'cmap_data_subcategory': [validators.ignore_missing, unicode, converters.convert_to_extras] }) schema.update({ 'cmap_data_field': [validators.ignore_missing, unicode, converters.convert_to_extras] }) schema.update({'__junk': [validators.ignore]}) return schema
def _unique_email_user_schema(self, schema): schema.update({ 'email': schema['email'] + [email_unique_validator] }) return schema
def db_to_form_schema(self): schema = ckan.logic.schema.group_form_schema() ignore_missing = toolkit.get_validator('ignore_missing') convert_from_extras = toolkit.get_converter('convert_from_extras') # add following since they are missing from schema schema.update({'num_followers': [ignore_missing]}) schema.update({'package_count': [ignore_missing]}) # Schema for homepages schema.update({'homepage': [convert_from_extras, ignore_missing]}) # schema for extra org info schema.update({'valid_from': [convert_from_extras, ignore_missing]}) schema.update({'valid_till': [convert_from_extras, ignore_missing]}) # schema for organisation address schema.update({'street_address': [convert_from_extras, ignore_missing]}) schema.update({'street_address_zip_code': [convert_from_extras, ignore_missing]}) schema.update({'street_address_place_of_business': [convert_from_extras, ignore_missing]}) schema.update({'producer_type': [convert_from_extras, ignore_missing]}) schema.update({'public_adminstration_organization': [convert_from_extras, ignore_missing]}) # old schema is used to display old data if it exists schema.update({'homepages': [convert_from_extras, from_json_to_object, ignore_missing]}) schema.update({'business_id': [convert_from_extras, ignore_missing]}) schema.update({'oid': [convert_from_extras, ignore_missing]}) schema.update({'alternative_name': [convert_from_extras, ignore_missing]}) schema.update({'street_address_pobox': [convert_from_extras, ignore_missing]}) schema.update({'street_address_country': [convert_from_extras, ignore_missing]}) schema.update({'street_address_unofficial_name': [convert_from_extras, ignore_missing]}) schema.update({'street_address_building_id': [convert_from_extras, ignore_missing]}) schema.update({'street_address_getting_there': [convert_from_extras, ignore_missing]}) schema.update({'street_address_parking': [convert_from_extras, ignore_missing]}) schema.update({'street_address_public_transport': [convert_from_extras, ignore_missing]}) schema.update({'street_address_url_public_transport': [convert_from_extras, ignore_missing]}) schema = add_translation_show_schema(schema) schema = add_languages_show(schema, self._localized_fields) return schema
def form_to_db_schema(self): schema = super(YtpOrganizationsPlugin, self).form_to_db_schema() ignore_missing = toolkit.get_validator('ignore_missing') convert_to_extras = toolkit.get_converter('convert_to_extras') # schema for homepages # schema.update({'homepages': [ignore_missing, convert_to_list, unicode, convert_to_extras]}) schema.update({'homepage': [ignore_missing, unicode, convert_to_extras]}) schema.update({'public_adminstration_organization': [ignore_missing, unicode, convert_to_extras]}) schema.update({'producer_type': [ignore_missing, unicode, convert_to_extras]}) # schema for extra org info # schema.update({'business_id': [ignore_missing, unicode, convert_to_extras]}) # schema.update({'oid': [ignore_missing, unicode, convert_to_extras]}) # schema.update({'alternative_name': [ignore_missing, unicode, convert_to_extras]}) schema.update({'valid_from': [ignore_missing, date_validator, convert_to_extras]}) schema.update({'valid_till': [ignore_missing, date_validator, convert_to_extras]}) # schema for organisation address schema.update({'street_address': [ignore_missing, unicode, convert_to_extras]}) # schema.update({'street_address_pobox': [ignore_missing, unicode, convert_to_extras]}) schema.update({'street_address_zip_code': [ignore_missing, unicode, convert_to_extras]}) schema.update({'street_address_place_of_business': [ignore_missing, unicode, convert_to_extras]}) # schema.update({'street_address_country': [ignore_missing, unicode, convert_to_extras]}) # schema.update({'street_address_unofficial_name': [ignore_missing, unicode, convert_to_extras]}) # schema.update({'street_address_building_id': [ignore_missing, unicode, convert_to_extras]}) # schema.update({'street_address_getting_there': [ignore_missing, unicode, convert_to_extras]}) # schema.update({'street_address_parking': [ignore_missing, unicode, convert_to_extras]}) # schema.update({'street_address_public_transport': [ignore_missing, unicode, convert_to_extras]}) # schema.update({'street_address_url_public_transport': [ignore_missing, unicode, convert_to_extras]}) schema = add_translation_modify_schema(schema) schema = add_languages_modify(schema, self._localized_fields) return schema
def db_to_form_schema(self): schema = ckan.logic.schema.db_to_form_package_schema() schema.update({ 'cmap_geographical_level': [converters.convert_from_extras, validators.ignore_missing] }) schema.update({ 'cmap_data_family': [converters.convert_from_extras, validators.ignore_missing] }) schema.update({ 'cmap_data_category': [converters.convert_from_extras, validators.ignore_missing] }) schema.update({ 'cmap_data_subcategory': [converters.convert_from_extras, validators.ignore_missing] }) schema.update({ 'cmap_data_field': [converters.convert_from_extras, validators.ignore_missing] }) # CMAPPackageController adds group_image_url to package dicts, this # needs to be added to the schema so that validation doesn't remove it. schema.update({'group_image_url': [validators.ignore_missing]}) # CMAPPackageController adds group_website_url to package dicts, this # needs to be added to the schema so that validation doesn't remove it. schema.update({'group_website_url': [validators.ignore_missing]}) # Put group capacity (i.e. public or private) into the schema so it # doesn't get removed by validation. schema['groups']['capacity'] = [] # Put a few more keys into the schema so they don't get removed by # validation. This stops the user profile page from crashing when the # user has some datasets. schema.update({'isopen': [validators.ignore_missing]}) schema['tags'] = { 'name': [ validators.not_missing, validators.not_empty, unicode, ], 'vocabulary_id': [validators.ignore_missing, unicode], 'revision_timestamp': [validators.ignore], 'state': [validators.ignore], 'display_name': [validators.ignore_missing, unicode], } schema.update({'tracking_summary': [validators.ignore_missing]}) # This fixes a crash when viewing historical versions of datasets. schema.update({'revision_id': [validators.ignore_missing, unicode]}) schema.update( {'revision_timestamp': [validators.ignore_missing, unicode]}) return schema
def db_to_form_schema(self): schema = ckan.logic.schema.db_to_form_package_schema() schema.update({'cmap_geographical_level': [converters.convert_from_extras, validators.ignore_missing]}) schema.update({'cmap_data_family': [converters.convert_from_extras, validators.ignore_missing]}) schema.update({'cmap_data_category': [converters.convert_from_extras, validators.ignore_missing]}) schema.update({'cmap_data_subcategory': [converters.convert_from_extras, validators.ignore_missing]}) schema.update({'cmap_data_field': [converters.convert_from_extras, validators.ignore_missing]}) # CMAPPackageController adds group_image_url to package dicts, this # needs to be added to the schema so that validation doesn't remove it. schema.update({'group_image_url': [validators.ignore_missing]}) # CMAPPackageController adds group_website_url to package dicts, this # needs to be added to the schema so that validation doesn't remove it. schema.update({'group_website_url': [validators.ignore_missing]}) # Put group capacity (i.e. public or private) into the schema so it # doesn't get removed by validation. schema['groups']['capacity'] = [] # Put a few more keys into the schema so they don't get removed by # validation. This stops the user profile page from crashing when the # user has some datasets. schema.update({'isopen': [validators.ignore_missing]}) schema['tags'] = { 'name': [validators.not_missing, validators.not_empty, unicode, ], 'vocabulary_id': [validators.ignore_missing, unicode], 'revision_timestamp': [validators.ignore], 'state': [validators.ignore], 'display_name': [validators.ignore_missing, unicode], } schema.update({'tracking_summary': [validators.ignore_missing]}) # This fixes a crash when viewing historical versions of datasets. schema.update({'revision_id': [validators.ignore_missing, unicode]}) schema.update({'revision_timestamp': [validators.ignore_missing, unicode]}) return schema
def update_config_schema(self, schema): '''Add's new fields to the schema for run-time editable configuration options. ''' ignore_missing = toolkit.get_validator('ignore_missing') # Added piece of mind. ignore_not_sysadmin = toolkit.get_validator('ignore_not_sysadmin') unicode_safe = toolkit.get_validator('unicode_safe') # Remove leading and trailing whitespace. remove_whitespace = toolkit.get_converter('remove_whitespace') schema.update({ # Custom configuration options for home page content. 'ckanext.ontario_theme.home_block_one-en': [ignore_missing, ignore_not_sysadmin, unicode_safe], 'ckanext.ontario_theme.home_block_one-fr': [ignore_missing, ignore_not_sysadmin, unicode_safe], 'ckanext.ontario_theme.home_block_one_image': [ ignore_missing, ignore_not_sysadmin, unicode_safe, remove_whitespace ], 'ckanext.ontario_theme.home_block_one_link-en': [ ignore_missing, ignore_not_sysadmin, unicode_safe, remove_whitespace ], 'ckanext.ontario_theme.home_block_one_link-fr': [ ignore_missing, ignore_not_sysadmin, unicode_safe, remove_whitespace ], 'ckanext.ontario_theme.home_block_two-en': [ignore_missing, ignore_not_sysadmin, unicode_safe], 'ckanext.ontario_theme.home_block_two-fr': [ignore_missing, ignore_not_sysadmin, unicode_safe], 'ckanext.ontario_theme.home_block_two_image': [ ignore_missing, ignore_not_sysadmin, unicode_safe, remove_whitespace ], 'ckanext.ontario_theme.home_block_two_link-en': [ ignore_missing, ignore_not_sysadmin, unicode_safe, remove_whitespace ], 'ckanext.ontario_theme.home_block_two_link-fr': [ ignore_missing, ignore_not_sysadmin, unicode_safe, remove_whitespace ], 'ckanext.ontario_theme.home_block_three-en': [ignore_missing, ignore_not_sysadmin, unicode_safe], 'ckanext.ontario_theme.home_block_three-fr': [ignore_missing, ignore_not_sysadmin, unicode_safe], 'ckanext.ontario_theme.home_block_three_image': [ ignore_missing, ignore_not_sysadmin, unicode_safe, remove_whitespace ], 'ckanext.ontario_theme.home_block_three_link-en': [ ignore_missing, ignore_not_sysadmin, unicode_safe, remove_whitespace ], 'ckanext.ontario_theme.home_block_three_link-fr': [ ignore_missing, ignore_not_sysadmin, unicode_safe, remove_whitespace ], }) return schema
def _modify_package_schema(self, schema): schema.update({ 'inventory_entry_id': [get_converter('convert_to_extras'), get_converter('update_package_inventory_entry')] }) return schema