def _modify_package_schema(self, schema): #schema.update({ # 'access_level': [tk.get_validator('ignore_missing'), # tk.get_converter('convert_to_tags')('access_levels')] # }) # Add custom access_level as extra field schema.update({ 'accessLevel': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')] }) # Add custom systemOfRecord as extra field schema.update({ 'systemOfRecords': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')] }) # Add custom granularity as extra field schema.update({ 'granularity': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')] }) # Add our custom_text metadata field to the schema, this one will use # convert_to_extras instead of convert_to_tags. schema.update({ 'dataDictionary': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')] }) return schema
def _modify_package_schema(self, schema): # Add our custom country_code metadata field to the schema. # schema.update({ # 'country_code': [tk.get_validator('ignore_missing'), # tk.get_converter('convert_to_tags')('country_codes')] # }) schema.update({ 'megasites': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_tags')('megasites')] }) schema.update({ 'countries': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_tags')('countries')] }) schema.update({ 'villages': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_tags')('villages')] }) # Add our custom_test metadata field to the schema, this one will use # convert_to_extras instead of convert_to_tags. schema.update({ 'citation': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')] }) # schema['resources'].update({ # 'citation_resource' : [ tk.get_validator('ignore_missing') ] # }) return schema
def show_package_schema(self): schema = super(NewZealandLandcarePlugin, self).show_package_schema() schema.update({ 'publisher': [toolkit.get_converter('convert_from_extras'), toolkit.get_validator('ignore_empty')], 'publication_year': [toolkit.get_converter('convert_from_extras'), toolkit.get_validator('ignore_empty'), toolkit.get_validator('ckanext_lcrnz_is_year'), ], 'start_date': [toolkit.get_converter('convert_from_extras'), toolkit.get_validator('ignore_empty'), toolkit.get_validator('ckanext_lcrnz_is_date'), ], 'end_date': [toolkit.get_converter('convert_from_extras'), toolkit.get_validator('ignore_empty'), toolkit.get_validator('ckanext_lcrnz_is_date'), ], 'doi': [toolkit.get_converter('convert_from_extras'), toolkit.get_validator('ignore_empty')], }) schema['author'] = [toolkit.get_validator('repeating_text_output'), toolkit.get_validator('ignore_empty')] return schema
def update_package_schema(self): schema = super(CphmetadataPlugin, self).update_package_schema() #our custom fields schema.update({ 'update_frequency': [frequency_validator, toolkit.get_converter('convert_to_extras')], 'department': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_extras')], 'office': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_extras')], 'editor': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_extras')], 'kkkort': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_extras')], 'copenhagenkortet': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_extras')], 'datakk': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_extras')], 'date_created': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_extras')], 'date_updated': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_extras')], 'data_quality': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_extras')], 'quality_note': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_extras')], }) return schema
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
def show_package_schema(self): schema = super(AgesicIDatasetFormPlugin, self).show_package_schema() # Don't show vocab tags mixed in with normal 'free' tags # (e.g. on dataset pages, or on the search page) schema['tags']['__extras'].append(tk.get_converter('free_tags_only')) # Add our custom country_code metadata field to the schema. schema.update({ 'country_code': [ tk.get_converter('convert_from_tags')('country_codes'), tk.get_validator('ignore_missing')] }) # Add our custom fields to the dataset schema. schema.update({ 'update_frequency': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')], 'spatial_ref_system': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')], 'spatial_coverage': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')], 'temporal_coverage': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')] }) 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 show_package_schema(self): schema = super(SurreyTemplatePlugin, self).show_package_schema() # Add our custom_text field to the dataset schema. schema.update({ 'update_frequency': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')] }) schema.update({ 'coordinate_system': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')] }) schema.update({ 'more_information': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')] }) schema.update({ 'attribute_details': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')] }) schema.update({ 'is_geospatial': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')] }) return schema
def _modify_package_schema(self, schema): schema.update({ 'update_frequency': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')] }) schema.update({ 'coordinate_system': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')] }) schema.update({ 'more_information': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')] }) schema.update({ 'attribute_details': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')] }) schema.update({ 'is_geospatial': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')] }) return schema
def show_package_schema(self): schema = super(ExampleIDatasetFormPlugin, self).show_package_schema() # Don't show vocab tags mixed in with normal 'free' tags # (e.g. on dataset pages, or on the search page) schema['tags']['__extras'].append(tk.get_converter('free_tags_only')) # Add our custom country_code metadata field to the schema. schema.update({ 'country_code': [ tk.get_converter('convert_from_tags')('country_codes'), tk.get_validator('ignore_missing')] }) # Add our custom_text field to the dataset schema. schema.update({ 'custom_text': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')] }) #XXX this is the additional field for bug demo XXX schema.update({ 'another_custom_text' : [ tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing'), ] }) return schema
def _modify_package_schema(self, schema): # Add our custom data_types metadata field to the schema. schema.update({ 'data_type': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_tags')('data_types')] }) # Add our custom geographies metadata field to the schema. schema.update({ 'geography': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_tags')('geographies')] }) # Add source_url and date fields to the schema schema.update({ 'source_url': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_extras')] }) schema.update({ 'date': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_extras')] }) schema.update({ 'availability_notes': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_extras')] }) return schema
def validate_datarequest(context, request_data): errors = {} # Check name if len(request_data['title']) > constants.NAME_MAX_LENGTH: errors['Title'] = [tk._('Title must be a maximum of %d characters long') % constants.NAME_MAX_LENGTH] if not request_data['title']: errors['Title'] = [tk._('Title cannot be empty')] # Title is only checked in the database when it's correct avoid_existing_title_check = context['avoid_existing_title_check'] if 'avoid_existing_title_check' in context else False if 'Title' not in errors and not avoid_existing_title_check: if db.DataRequest.datarequest_exists(request_data['title']): errors['Title'] = ['That title is already in use'] # Check description if len(request_data['description']) > constants.DESCRIPTION_MAX_LENGTH: errors['Description'] = [tk._('Description must be a maximum of %d characters long') % constants.DESCRIPTION_MAX_LENGTH] # Check organization if request_data['organization_id']: try: tk.get_validator('group_id_exists')(request_data['organization_id'], context) except Exception: errors['Organization'] = ['Organization is not valid'] if len(errors) > 0: raise tk.ValidationError(errors)
def create_package_schema(self): ''' Returns the schema for mapping package data from a form to a format suitable for the database. ''' from ckanext.harvest.logic.schema import harvest_source_create_package_schema schema = harvest_source_create_package_schema() if self.startup: schema['id'] = [unicode] schema.update({ 'catalogue_country': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')] }) schema.update({ 'catalogue_date_created': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')] }) schema.update({ 'catalogue_date_updated': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')] }) schema.update({ 'language': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')] }) return schema
def doi_prefix(key, data, errors, context): '''Make sure prefix isn't missing, if auto_doi_identifier is True.''' if data.get(('auto_doi_identifier',)): toolkit.get_validator('not_empty')(key, data, errors, context) else: toolkit.get_validator('ignore_missing')(key, data, errors, context)
def _modify_package_schema(self, schema): # TODO: need to implement chained validators # that allows to validate a group of fields together # e.g if start_date is entered then end_date is required # Add custom metadata fields to the schema, this one will use # convert_to_extras for all fields except for package_type for which convert_to_tags will be used. _not_empty = tk.get_validator('not_empty') _ignore_missing = tk.get_validator('ignore_missing') _convert_to_extras = tk.get_converter('convert_to_extras') schema.update({ 'pkg_model_name': [_not_empty, _convert_to_extras], 'model_version': [_not_empty, _convert_to_extras], 'north_extent': [_ignore_missing, v.Number(), _convert_to_extras], 'west_extent': [_ignore_missing, v.Number(), _convert_to_extras], 'south_extent': [_ignore_missing, v.Number(), _convert_to_extras], 'east_extent': [_ignore_missing, v.Number(), _convert_to_extras], 'simulation_start_day': [_ignore_missing, v.DateConverter(), _convert_to_extras], 'simulation_end_day': [_ignore_missing, v.DateConverter(), _convert_to_extras], 'time_step': [_ignore_missing, v.Number(), _convert_to_extras], 'package_type': [_not_empty, tk.get_converter('convert_to_tags')('model_package_types')], 'package_run_status': [_ignore_missing, _convert_to_extras], 'package_run_job_id': [_ignore_missing, _convert_to_extras], 'dataset_type': [_not_empty, _convert_to_extras] }) schema = super(ModelPackagePlugin, self).modify_schema(schema) return schema
def _modify_package_schema(self, schema): to_extras = tk.get_converter('convert_to_extras') to_tags = tk.get_converter('convert_to_tags') optional = tk.get_validator('ignore_missing') checkboxes = [optional, tk.get_validator('boolean_validator'), to_extras] # License is fixed to Open (Public Domain) def fixed_license(value, context): return 'other-pd' schema.update({ 'category': [category_exists, category_to_group], 'update_frequency': [to_tags('update_frequencies')], 'license_id': [fixed_license, unicode], # Reuse conditions specified in http://mojepanstwo.pl/dane/prawo/2007,ustawa-dostepie-informacji-publicznej/tresc 'license_condition_source': checkboxes, 'license_condition_timestamp': checkboxes, 'license_condition_original': checkboxes, 'license_condition_modification': checkboxes, 'license_condition_responsibilities': [optional, to_extras] }) # Add our custom_resource_text metadata field to the schema # schema['resources'].update({ # 'custom_resource_text' : [ tk.get_validator('ignore_missing') ] # }) return schema
def convert_to_extras_custom(key, data, errors, context): # get the current number of extras field unflattened = df.unflatten(data) if("extras" in unflattened): extras_count = len(unflattened['extras']) else: extras_count = 0 data.update({ ('extras', (extras_count), 'id') : [tk.get_validator('ignore')], ('extras', (extras_count), 'revision_timestamp') : [tk.get_validator('ignore')], ('extras', (extras_count), 'state') : [tk.get_validator('ignore')], ('extras', (extras_count), 'deleted') : [], # this needs to be blank so the fields won't be deleted }) if key[-1] == "pkg_creator": data.update({ ('extras', (extras_count), 'key') : key[-1], ('extras', (extras_count), 'value') : c.userobj.id }) elif key[-1] == "pkg_invisible": if data[key] != ( "True" or "False" ): data[key] = "False" data.update({ ('extras', (extras_count), 'key') : key[-1], ('extras', (extras_count), 'value') : data[key] }) pass
def show_package_schema(self): schema = super(MidjaPlugin, self).show_package_schema() # Don't show vocab tags mixed in with normal 'free' tags # (e.g. on dataset pages, or on the search page) schema['tags']['__extras'].append(toolkit.get_converter('free_tags_only')) # Add our custom fields to the schema. schema.update({ 'data_type': [ toolkit.get_converter('convert_from_tags')('data_types'), toolkit.get_validator('ignore_missing')] }) schema.update({ 'geography': [ toolkit.get_converter('convert_from_tags')('geographies'), toolkit.get_validator('ignore_missing')] }) schema.update({ 'source_url': [toolkit.get_converter('convert_from_extras'), toolkit.get_validator('ignore_missing')] }) schema.update({ 'date': [toolkit.get_converter('convert_from_extras'), toolkit.get_validator('ignore_missing')] }) schema.update({ 'availability_notes': [toolkit.get_converter('convert_from_extras'), toolkit.get_validator('ignore_missing')] }) return schema
def validate_datarequest_closing(context, request_data): accepted_dataset_id = request_data.get('accepted_dataset_id', '') if accepted_dataset_id: try: tk.get_validator('package_name_exists')(accepted_dataset_id, context) except Exception: raise tk.ValidationError({'Accepted Dataset': ['Dataset not found']})
def _modify_package_resource_schema(self, schema): schema['resources'].update({ 'download_url': [tk.get_validator('ignore_missing')], 'modified': [tk.get_validator('ignore_missing')], 'adms_status': [tk.get_validator('ignore_missing')], 'issued': [tk.get_validator('ignore_missing')], 'bytesize': [tk.get_validator('ignore_missing')], }) return schema
def _modify_group_schema(self, schema): schema.update( { "description": [tk.get_validator("not_empty")], "org_url": [tk.get_validator("not_missing"), tk.get_converter("convert_to_extras")], "fts_id": [tk.get_validator("ignore_missing"), tk.get_converter("convert_to_extras")], } ) return schema
def _modify_package_schema(self, schema): # Add our custom country_code metadata field to the schema. schema.update( {"country_code": [tk.get_validator("ignore_missing"), tk.get_converter("convert_to_tags")("country_codes")]} ) # Add our custom_test metadata field to the schema, this one will use # convert_to_extras instead of convert_to_tags. schema.update({"custom_text": [tk.get_validator("ignore_missing"), tk.get_converter("convert_to_extras")]}) return schema
def show_package_schema(self): schema = super(EurovocDatasetPlugin, self).show_package_schema() schema.update({ self.eurovoc_category: [ toolkit.get_converter('convert_from_extras'), toolkit.get_validator('eurovoc_text_output'), toolkit.get_validator('ignore_missing') ] }) return schema
def _modify_package_schema(self, schema): schema.update({ 'eurovoc_uri': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')], 'eurovoc_concept': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')], 'spatial': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')] }) return schema
def show_package_schema(self): schema = super(MultilingualDatasetForm, self).show_package_schema() ignore_missing = toolkit.get_validator('ignore_missing') convert_from_extras = toolkit.get_converter('convert_from_extras') default = toolkit.get_validator('default') schema['language'] = [ convert_from_extras, default(pylons.config['ckan.locale_default'])] return schema
def show_package_schema(self): schema = super(CadastaPlugin, self).show_package_schema() schema.update({ 'cadasta_id': [toolkit.get_converter('convert_from_extras'), toolkit.get_validator('ignore_missing')] }) schema['resources'].update({ 'custom_resource_text' : [ toolkit.get_validator('ignore_missing') ] }) return schema
def _modify_package_schema(self, schema): schema.update({ 'cadasta_id': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_extras')] }) # Add our custom_resource_text metadata field to the schema schema['resources'].update({ 'custom_resource_text' : [ toolkit.get_validator('ignore_missing') ] }) return schema
def show_package_schema(self): schema = super(SGDatasetForm, self).show_package_schema() schema['tags']['__extras'].append(toolkit.get_converter( 'free_tags_only')) for field in (SIMPLE_MANDATORY_TEXT_FIELDS + SIMPLE_OPTIONAL_TEXT_FIELDS): schema[field] = [ toolkit.get_converter('convert_from_extras'), toolkit.get_validator('ignore_missing')] schema['reference-period-start'] = [ toolkit.get_converter('convert_from_extras'), toolkit.get_validator('ignore_missing')] schema['reference-period-end'] = [ toolkit.get_converter('convert_from_extras'), toolkit.get_validator('ignore_missing')] schema['available-from'] = [ toolkit.get_converter('convert_from_extras'), toolkit.get_validator('ignore_missing')] schema['type_of_data_collection'] = [ toolkit.get_converter('convert_from_tags')('type_of_data_collection'), toolkit.get_validator('ignore_missing'), first_item_only] schema['status'] = [ toolkit.get_converter('convert_from_tags')('status'), toolkit.get_validator('ignore_missing'), first_item_only] schema['frequency'] = [ toolkit.get_converter('convert_from_tags')('frequency'), toolkit.get_validator('ignore_missing'), first_item_only] schema['security_classification'] = [ toolkit.get_converter('convert_from_tags')('security_classification'), toolkit.get_validator('ignore_missing'), first_item_only] schema['data_granularity'] = [ toolkit.get_converter('convert_from_tags')('data_granularity'), toolkit.get_validator('ignore_missing'), first_item_only] schema['publish_on_data_gov_sg'] = [ toolkit.get_converter('convert_from_tags')('publish_on_data_gov_sg'), toolkit.get_validator('ignore_missing'), first_item_only] return schema
def _form_to_db_schema(self, schema): to_extras = tk.get_converter('convert_to_extras') not_empty = tk.get_validator('not_empty') optional = tk.get_validator('ignore_missing') schema.update({ 'color': [not_empty, to_extras], 'title_i18n': [fluent_text, not_empty, to_extras], 'description': [fluent_text, optional] }) return schema
def _add_wotkit_credentials_to_schema(self, schema): """ Adds timezone to user schema for parameters to be validated on form submit""" schema['timezone'] = [ignore_missing, unicode] """ Changes the min name length to be compatible with wotkit """ schema['name'] = [tk.get_validator("not_empty"), validators.name_validator, # altered validator tk.get_validator("user_name_validator"), unicode]
def update_config_schema(self, schema): ignore_missing = toolkit.get_validator('ignore_missing') schema.update({ 'ckanext.romania_theme.disallowed_extensions': [ignore_missing, unicode], 'ckanext.romania_theme.allowed_extensions': [ignore_missing, unicode], }) return schema
def update_package_schema(self) -> Schema: schema: Schema = super(ExampleIDatasetFormPlugin, self).update_package_schema() # our custom field schema.update({ u'custom_text': [ tk.get_validator(u'ignore_missing'), tk.get_converter(u'convert_to_extras') ] }) return schema
def _modify_package_schema(self, schema): # Add our custom country_code metadata field to the schema. schema.update({ 'country_code': [ tk.get_validator('ignore_missing'), tk.get_converter('convert_to_tags')('country_codes') ] }) # Add our custom_test metadata field to the schema, this one will use # convert_to_extras instead of convert_to_tags. schema.update({ 'custom_text': [ tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras') ] }) # Add our custom_resource_text metadata field to the schema schema['resources'].update( {'custom_resource_text': [tk.get_validator('ignore_missing')]}) return schema
def show_package_schema(self): # grab the default schema schema = super(CprvalidationPlugin, self).show_package_schema() schema.update({ 'verified': [ toolkit.get_converter('convert_from_extras'), toolkit.get_validator('ignore_missing') ], }) return schema
def show_package_schema(self): schema = super(TestingresourceschemaPlugin, self).show_package_schema() schema['resources'].update({ 'testing_custom_field': [ toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_from_extras') ] }) return schema
def create_package_schema(self): # let's grab the default schema in our plugin schema = super(ExampleIDatasetFormPlugin, self).create_package_schema() # our custom field schema.update({ 'custom_text': [ tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras') ] }) return schema
def update_package_schema(self): #Default schema schema = super(KyelathemePlugin, self).update_package_schema() #Update 'spatial' field schema.update({ 'spatial': [ toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_extras') ] }) return schema
def _modify_package_schema(self, schema): not_empty = toolkit.get_validator('not_empty') convert_to_extras = toolkit.get_converter('convert_to_extras') members_in_org_validator = validators.members_in_org_validator schema.update({ 'maintainer': [not_empty, members_in_org_validator, convert_to_extras] }) return schema
def showcase_show_schema(): schema = showcase_base_schema() # Don't strip ids from package dicts when validating them. schema['id'] = [] schema.update({ 'tags': {'__extras': [keep_extras]}}) schema.update({ 'state': [ignore_missing], }) # Remove validators for several keys from the schema so validation doesn't # strip the keys from the package dicts if the values are 'missing' (i.e. # None). schema['author'] = [] schema['author_email'] = [] schema['notes'] = [] schema['url'] = [] # Add several keys that are missing from default_create_package_schema(), # so validation doesn't strip the keys from the package dicts. schema['metadata_created'] = [] schema['metadata_modified'] = [] schema['creator_user_id'] = [] schema['num_tags'] = [] schema['revision_id'] = [] schema['tracking_summary'] = [] schema.update({ 'image_url': [toolkit.get_converter('convert_from_extras'), toolkit.get_validator('ignore_missing')], 'original_related_item_id': [ toolkit.get_converter('convert_from_extras'), toolkit.get_validator('ignore_missing')], 'redirect_link': [ toolkit.get_converter('convert_from_extras'), toolkit.get_validator('ignore_missing')] }) return schema
def _modify_package_schema(self, schema): ## # Getting custom package schema ## for field in dcatapit_schema.get_custom_package_schema(): if 'ignore' in field and field['ignore'] == True: continue if 'couples' in field: for couple in field['couples']: self.update_schema_field(schema, couple) else: self.update_schema_field(schema, field) schema.update({ 'notes': [ toolkit.get_validator('not_empty') ] }) ## # Getting custom resource schema ## for field in dcatapit_schema.get_custom_resource_schema(): if 'ignore' in field and field['ignore'] == True: continue validators = [] for validator in field['validator']: validators.append(toolkit.get_validator(validator)) schema['resources'].update({ field['name']: validators }) log.debug("Schema updated for DCAT_AP-TI: %r", schema) return schema
def get_validator_or_converter(name): """ Get a validator or converter by name """ if name == 'unicode': return unicode try: v = get_validator(name) return v except UnknownValidator: pass raise SchemingException('validator/converter not found: %r' % name)
def show_package_schema(self): schema = super(TopicsPlugin, self).show_package_schema() # Don't show vocab tags mixed in with normal 'free' tags # (e.g. on dataset pages, or on the search page) schema['tags']['__extras'].append( toolkit.get_converter('free_tags_only')) # Add our custom country_code metadata field to the schema. schema.update({ 'custom_topic': [ toolkit.get_converter('convert_from_tags')('custom_topics'), toolkit.get_validator('ignore_missing') ], 'custom_subtopic': [ toolkit.get_converter('convert_from_tags')('custom_subtopics'), toolkit.get_validator('ignore_missing') ] }) return schema
def update_config_schema(self, schema): for field in dcatapit_schema.get_custom_config_schema(False): validators = [] for validator in field['validator']: validators.append(toolkit.get_validator(validator)) schema.update({ field['name']: validators }) return schema
def show_package_schema(self): schema = super(TestESDPlugin, self).show_package_schema() default_validators = [ toolkit.get_converter('convert_from_extras'), toolkit.get_validator('ignore_missing') ] schema.update({ 'la_function': default_validators, 'la_service': default_validators, }) return schema
def db_to_form_schema(self): '''This is an interface to manipulate data from the database into a format suitable for the form (optional)''' schema = logic.schema.default_show_group_schema() schema['extras'] = logic.schema.default_extras_schema() FROM_EXTRAS = toolkit.get_converter('convert_from_extras') for field in dcatapit_schema.get_custom_organization_schema(): schema[field['name']] = [ FROM_EXTRAS ] + [toolkit.get_validator(v) for v in field['validator']] return schema
def update_config_schema(self, schema): ignore_missing = toolkit.get_validator('ignore_missing') schema.update({ # This is an existing CKAN core configuration option, we are just # making it available to be editable at runtime 'ckan.featured_orgs': [ignore_missing] }) 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 command(self): self._load_config() h.register_activity_types() object_id_validators[ h.dataset_activity_type_review_package] = tk.get_validator( 'user_id_exists') #tk.get_validator('package_id_exists') # if len(self.args) == 0: # self.parser.print_usage() # sys.exit(1) context = { 'model': ckan.model, 'session': ckan.model.Session, 'ignore_auth': True } admin_user = plugins.toolkit.get_action('get_site_user')(context, {}) #get all packages that need to be reviewed package_reviews = get_by_daterange(ckan.model.Session, datetime.date(2001, 1, 1), datetime.date.today()) for pr in package_reviews: #get the package pkg = ckan.model.Package.get(pr.package_id) pkg_dict = ckan.lib.dictization.table_dictize(pkg, context) if 'maintainer' in pkg_dict: recipient = pkg_dict.get('maintainer') elif 'creator_user_id' in pkg_dict: recipient = pkg_dict.get('creator_user_id') else: raise ValueError('User not found') # Check if user exists try: user = ckan.model.User.get(recipient) review_context = { 'model': ckan.model, 'user': admin_user.get('name'), 'session': ckan.model.Session, 'ignore_auth': True } activity_object_id = user.id h.create_review_activity( review_context, pkg_dict, h.dataset_activity_type_review_package, activity_object_id) except NotFound: # raise ValueError('User not found') print 'User not found %s ' % (recipient) print 'done'
def show_package_schema(self): schema = super(PBZThemePlugin, self).show_package_schema() for field in self.custom_fields: schema.update({ field[0]: [ toolkit.get_converter('convert_from_extras'), toolkit.get_validator('ignore_missing') ] }) return schema
def test_datatype_validator_default(self): """ tests fao_datatype validator with default value in config """ _load_vocabulary('datatype', 'faociok.datatype.csv') test_values = ((None, True, 'default_val',), ([], True, 'default_val',), ("", True, 'default_val',), ('invalid', False, None,), ('microdata', True, 'microdata'), ) _run_validator_checks(test_values, t.get_validator('fao_datatype'))
def show_package_schema(self): schema = super(Kdl_MadihPlugin, self).show_package_schema() schema["tags"]["__extras"].append(toolkit.get_converter("free_tags_only")) schema.update( { "madih_kdl_time_periods": [ toolkit.get_converter("convert_from_tags")("madih_kdl_time_periods") ], MADIH_KDL_DATATYPE: [ toolkit.get_converter("convert_from_tags")(MADIH_KDL_DATATYPE) ], "madih_kdl_project_url": [ toolkit.get_converter("convert_from_extras"), toolkit.get_validator("url_validator"), toolkit.get_validator("ignore_missing"), ], "madih_kdl_project_pi": [ toolkit.get_converter("convert_from_extras"), toolkit.get_validator("ignore_missing"), ], "madih_kdl_project_team": [ toolkit.get_converter("convert_from_extras"), toolkit.get_validator("ignore_missing"), ], "madih_kdl_project_start_date": [ toolkit.get_converter("convert_from_extras"), toolkit.get_validator("ignore_missing"), ], "madih_kdl_project_end_date": [ toolkit.get_converter("convert_from_extras"), toolkit.get_validator("ignore_missing"), ], "madih_kdl_project_status": [ toolkit.get_converter("convert_from_tags")( "madih_kdl_project_status" ), ], "madih_kdl_project_funder": [ toolkit.get_converter("convert_from_extras"), toolkit.get_validator("ignore_missing"), ], "madih_kdl_project_citation": [ toolkit.get_converter("convert_from_extras"), toolkit.get_validator("ignore_missing"), ], } ) return schema
def show_package_schema(self): schema = super(DatasetForm, self).show_package_schema() # Don't show vocab tags mixed in with normal 'free' tags # (e.g. on dataset pages, or on the search page) schema['tags']['__extras'].append(toolkit.get_converter('free_tags_only')) schema.update({ # Add our custom "music_genre" metadata field to the schema. 'music_genre': [ toolkit.get_converter('convert_from_tags')('music_genres'), toolkit.get_validator('ignore_missing') ], # Add our "music_title" field to the dataset schema. 'music_title': [ toolkit.get_converter('convert_from_extras'), toolkit.get_validator('ignore_missing') ], # Add our non-input field (created at after_validation_processor) 'record_modified_at': [ toolkit.get_converter('convert_from_extras'), ], # Add our dynamic (not registered at modify schema) field 'foo.x1': [ toolkit.get_converter('convert_from_extras'), toolkit.get_validator('ignore_missing') ] }) # Append computed fields in the __after stage def f(k, data, errors, context): data[('baz_view',)] = u'I am a computed Baz' pass if not schema.get('__after'): schema['__after'] = [] schema['__after'].append(f) return schema
def show_package_schema(self): schema = super(EtalabDatasetFormPlugin, self).show_package_schema() schema.update( dict( frequency=[ tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing'), ], supplier_id=[ tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing'), ], temporal_coverage_from=[ tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing'), convert_date_to_form, ], temporal_coverage_to=[ tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing'), convert_date_to_form, ], territorial_coverage=[ tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing'), ], territorial_coverage_granularity=[ tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing'), ], )) return schema
def _modify_package_schema(self, schema): # Add our custom country_code metadata field to the schema. schema.update({ 'country_code': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_tags')('country_codes')] }) # Add our custom_test metadata field to the schema, this one will use # convert_to_extras instead of convert_to_tags. schema.update({ 'frekuensi_penerbitan': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_extras')] }) schema.update({ 'level_penyajian': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_extras')] }) schema.update({ 'tahun': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_extras')] }) schema.update({ 'cakupan': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_extras')] }) schema.update({ 'rujukan': [toolkit.get_validator('ignore_missing'), toolkit.get_converter('convert_to_extras')] }) return schema
def show_package_schema(self): schema = super(SurreyTemplatePlugin, self).show_package_schema() # Add our custom_text field to the dataset schema. schema.update({ 'update_frequency': [ tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing') ] }) schema.update({ 'coordinate_system': [ tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing') ] }) schema.update({ 'more_information': [ tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing') ] }) schema.update({ 'attribute_details': [ tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing') ] }) schema.update({ 'is_geospatial': [ tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing') ] }) return schema
def _update_with_requestdata_show_package_schema(self, schema): log.debug('Update with requestdata show package schema') # Adding requestdata related schema for plugin in plugins.PluginImplementations(plugins.IDatasetForm): if plugin.name == 'requestdata': requestdata_schema = plugin.show_package_schema() schema.update(requestdata_schema) # Adding hdx specific request data schema schema.update({ 'field_names': [ tk.get_converter('convert_from_extras'), tk.get_validator('not_empty') ], 'file_types': [ tk.get_converter('convert_from_extras'), tk.get_validator('not_empty') ], 'num_of_rows': [ tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing'), tk.get_validator('is_positive_integer') ], 'data_update_frequency': [ tk.get_validator('convert_from_extras'), tk.get_converter('ignore_missing') ], 'methodology': [ tk.get_validator('convert_from_extras'), tk.get_converter('ignore_missing') ] })
def _modify_group_schema(self, schema): schema.update({'language_code': [ tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')], }) schema.update({'relief_web_url': [ tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')]}) schema.update({'hr_info_url': [ tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')]}) schema.update({'geojson': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')], 'custom_loc': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')], 'customization': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')], 'activity_level': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')], 'data_completeness': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')] }) 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 add_languages_show(schema, fields, locales=None): """ Add translation to schema to given fields. """ if locales is None: locales = get_locales() convert_from_extras = toolkit.get_converter('convert_from_extras') ignore_missing = toolkit.get_validator('ignore_missing') for locale in locales: for field in fields: schema.update({ "%s_%s" % (field, locale): [convert_from_extras, ignore_missing] }) return schema
def _modify_group_schema(self, schema): for field in dcatapit_schema.get_custom_organization_schema(): validators = [] for validator in field['validator']: validators.append(toolkit.get_validator(validator)) schema.update({ field['name']: validators + [toolkit.get_converter('convert_to_extras')] }) return schema