def convert(tag_string, vocab): key = 'vocab_tags' data = {key: tag_string} errors = [] context = {'model': model, 'session': model.Session} converters.convert_to_tags(vocab)(key, data, errors, context) del data[key] return data
def convert(tag_string, vocab): key = "vocab_tags" data = {key: tag_string} errors = [] context = {"model": model, "session": model.Session} converters.convert_to_tags(vocab)(key, data, errors, context) del data[key] return data
def test_convert_to_tags(): tag_name = factories.Tag.stub().name vocab = factories.Vocabulary(tags=[{"name": tag_name}]) key = ("vocab_tags", ) data = {key: tag_name} context = {"model": model, "session": model.Session} converters.convert_to_tags(vocab["name"])(key, data, [], context) assert data[("tags", 0, "name")] == tag_name assert data[("tags", 0, "vocabulary_id")] == vocab["id"]
def form_to_db_schema(self): """ Returns the schema for mapping package data from a form to a format suitable for the database. """ schema = package_form_schema() schema.update({ 'published_by': [ignore_missing, unicode, convert_to_extras], 'genre_tags': [ignore_missing, convert_to_tags(GENRE_VOCAB)], 'composer_tags': [ignore_missing, convert_to_tags(COMPOSER_VOCAB)] }) return schema
def form_to_db_schema(self): schema = default_package_schema() schema.update({ 'vocab_tags': [ignore_missing, convert_to_tags(TEST_VOCAB_NAME)], }) return schema
def form_to_db_schema(self): """ Returns the schema for mapping package data from a form to a format suitable for the database. """ schema = form_to_db_package_schema() schema.update({ 'license_id': [not_empty], 'Titolare': [not_empty, convert_to_extras], 'Descrizione campi': [not_empty, convert_to_extras], 'Categorie': [ignore_missing, convert_to_tags(CATEGORY_VOCAB)], 'Copertura Geografica': [not_empty, convert_to_extras], 'Copertura Temporale (Data di inizio)': [not_empty, convert_to_extras, date_to_db], 'Copertura Temporale (Data di fine)': [convert_to_extras, date_to_db], 'Aggiornamento': [not_empty, convert_to_extras], 'Data di pubblicazione': [not_empty, convert_to_extras, date_to_db], 'Data di aggiornamento': [not_empty, convert_to_extras, date_to_db], 'Codifica Caratteri': [not_empty, convert_to_extras], 'Data di creazione': [convert_to_extras], 'URL sito': [convert_to_extras], 'maintainer': [not_empty, unicode], 'maintainer_email': [not_empty, unicode], }) schema['groups']['capacity'] = [ignore_missing, unicode] 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 _schema_field_validators(name, lang, field, required): """ return a tuple with lists of validators for the field: one for create/update and one for show, or None to leave both lists unchanged """ if name == 'portal_release_date': return ([treat_missing_as_empty, protect_portal_release_date, isodate, convert_to_extras], [convert_from_extras, ignore_missing]) edit = [] view = [] if field['type'] in ('calculated', 'fixed') or not field['mandatory']: edit.append(ignore_missing) elif field['mandatory']: # FIXME: assuming dataset field passed! edit.append(required.dataset_field(name, lang, field)) if field['type'] == 'date': edit.append(isodate) elif field['type'] == 'keywords': edit.append(keywords_validate) elif field['type'] == 'tag_vocabulary': return (edit + [convert_pilot_uuid_list(field), convert_to_tags(field['vocabulary'])], view + [convert_from_tags(field['vocabulary'])]) elif field['type'] == 'boolean': edit.extend([unicode, boolean_validator]) view.extend([convert_from_extras, ignore_missing, boolean_validator]) elif field['type'] == 'fixed': edit.append(ignore) view.append(fixed_value(field, lang)) elif field['type'] == 'geojson': edit.append(geojson_validator) else: edit.append(unicode) if name == 'ready_to_publish': edit.append(required.ready_to_publish) return (edit + [convert_to_extras], view if view else [convert_from_extras, ignore_missing])
def _schema_field_validators(name, lang, field): """ return a tuple with lists of validators for the field: one for create/update and one for show, or None to leave both lists unchanged """ if name == 'portal_release_date': return ([ treat_missing_as_empty, protect_portal_release_date, isodate, convert_to_extras ], [convert_from_extras, ignore_missing]) edit = [] view = [] if field['type'] in ('calculated', 'fixed') or not field['mandatory']: edit.append(ignore_missing) elif field['mandatory']: # FIXME: assuming dataset field passed! edit.append(not_empty) if field['type'] == 'date': edit.append(isodate) elif field['type'] == 'keywords': edit.append(keywords_validate) elif field['type'] == 'tag_vocabulary': return (edit + [ convert_pilot_uuid_list(field), convert_to_tags(field['vocabulary']) ], view + [convert_from_tags(field['vocabulary'])]) elif field['type'] == 'boolean': edit.extend([unicode, boolean_validator]) view.extend([convert_from_extras, ignore_missing, boolean_validator]) elif field['type'] == 'fixed': edit.append(ignore) view.append(fixed_value(field, lang)) elif field['type'] == 'geojson': edit.append(geojson_validator) else: edit.append(unicode) return (edit + [convert_to_extras], view if view else [convert_from_extras, ignore_missing])
def form_to_db_schema_options(self, options): ''' This allows us to select different schemas for different purpose eg via the web interface or via the api or creation vs updating. It is optional and if not available form_to_db_schema should be used. If a context is provided, and it contains a schema, it will be returned. ''' schema = options.get('context',{}).get('schema',None) if schema: schema.update({'Categorie': [ignore_missing, convert_to_tags(CATEGORY_VOCAB)]}) return schema if options.get('api'): if options.get('type') == 'create': return self.form_to_db_schema_api_create() else: assert options.get('type') == 'update' return self.form_to_db_schema_api_update() else: return self.form_to_db_schema()
def update_package_schema(self): schema = default_update_package_schema() schema.update({ 'vocab_tags': [ignore_missing, convert_to_tags(TEST_VOCAB_NAME)], }) return schema
def form_to_db_schema(self): schema = package_form_schema() schema.update({ 'vocab_tags': [ignore_missing, convert_to_tags(TEST_VOCAB_NAME)], }) return schema
def create_package_schema(self): schema = default_create_package_schema() schema.update({"vocab_tags": [ignore_missing, convert_to_tags(TEST_VOCAB_NAME)]}) return schema