def test_convert_from_tags(): tag_name1 = factories.Tag.stub().name tag_name2 = factories.Tag.stub().name vocab = factories.Vocabulary(tags=[ { "name": tag_name1 }, { "name": tag_name2 }, ]) key = "tags" data = { ("tags", 0, "__extras"): { "name": tag_name1, "vocabulary_id": vocab["id"], }, ("tags", 1, "__extras"): { "name": tag_name2, "vocabulary_id": vocab["id"], }, } errors = [] context = {"model": model, "session": model.Session} converters.convert_from_tags(vocab["name"])(key, data, errors, context) assert tag_name1 in data["tags"] assert tag_name2 in data["tags"]
def test_convert_from_tags(self): key = 'tags' data = { ('tags', 0, '__extras'): {'name': 'tag1', 'vocabulary_id': self.vocab.id}, ('tags', 1, '__extras'): {'name': 'tag2', 'vocabulary_id': self.vocab.id} } errors = [] context = {'model': model, 'session': model.Session} converters.convert_from_tags(self.vocab.name)(key, data, errors, context) assert 'tag1' in data['tags'] assert 'tag2' in data['tags']
def show_package_schema(self): schema = default_show_package_schema() schema.update({ 'tags': { '__extras': [keep_extras, free_tags_only] }, 'vocab_tags_selected': [convert_from_tags(TEST_VOCAB_NAME), ignore_missing], }) return schema
def test_convert_from_tags(self): key = "tags" data = { ("tags", 0, "__extras"): { "name": "tag1", "vocabulary_id": self.vocab.id, }, ("tags", 1, "__extras"): { "name": "tag2", "vocabulary_id": self.vocab.id, }, } errors = [] context = {"model": model, "session": model.Session} converters.convert_from_tags(self.vocab.name)(key, data, errors, context) assert "tag1" in data["tags"] assert "tag2" in data["tags"]
def db_to_form_schema(self): """ Returns the schema for mapping package data from the database into a format suitable for the form (optional) """ schema = package_form_schema() schema.update({ 'tags': { '__extras': [keep_extras, free_tags_only] }, 'genre_tags_selected': [convert_from_tags(GENRE_VOCAB), ignore_missing], 'composer_tags_selected': [convert_from_tags(COMPOSER_VOCAB), ignore_missing], 'published_by': [convert_from_extras, ignore_missing], }) schema['groups'].update({ 'name': [not_empty, unicode], 'title': [ignore_missing] }) return schema
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 db_to_form_schema(self): """ Returns the schema for mapping package data from the database into a format suitable for the form (optional) """ schema = package_form_schema() schema.update({ 'tags': { '__extras': [keep_extras, free_tags_only] }, 'genre_tags_selected': [ convert_from_tags(GENRE_VOCAB), ignore_missing ], 'composer_tags_selected': [ convert_from_tags(COMPOSER_VOCAB), ignore_missing ], 'published_by': [convert_from_extras, ignore_missing], }) schema['groups'].update({ 'name': [not_empty, unicode], 'title': [ignore_missing] }) 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 db_to_form_schema(self): """ Returns the schema for mapping package data from the database into a format suitable for the form (optional) """ schema = db_to_form_package_schema() schema.update({ 'tags': { '__extras': [keep_extras, free_tags_only] }, 'id': [not_empty], 'license_url': [not_empty], 'license_title': [not_empty], 'isopen': [not_empty], 'Titolare': [convert_from_extras, ignore_missing], 'Descrizione campi': [convert_from_extras, ignore_missing], 'Categorie': [convert_from_tags(CATEGORY_VOCAB), ignore_missing], 'Copertura Geografica': [convert_from_extras, ignore_missing], 'Copertura Temporale (Data di inizio)': [convert_from_extras, ignore_missing, date_to_form], 'Copertura Temporale (Data di fine)': [convert_from_extras, ignore_missing, date_to_form], 'Aggiornamento': [convert_from_extras, ignore_missing], 'Data di pubblicazione': [convert_from_extras, ignore_missing, date_to_form], 'Data di aggiornamento': [convert_from_extras, ignore_missing, date_to_form], 'Codifica Caratteri': [convert_from_extras, ignore_missing], 'Data di creazione': [convert_from_extras, ignore_missing], 'URL sito': [convert_from_extras, ignore_missing], 'DATEFIELDS': [ignore_missing], 'VIEWFIELDS': [ignore_missing], 'view_fields': [ignore_missing], }) for field in DATEFIELDS: schema.update({field+ISOEXTENSION: [ignore_missing]}) return schema
def show_package_schema(self): schema = super(CeresPlugin, 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 access_level metadata field to the schema. schema.update({ 'Topic': [ convert_from_tags('Topic'), listToString, ignore_missing] }) '''schema.update({ 'pkg_type': [ tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')] }) schema.update({ 'contributing_org': [ tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing') ] }) # Add our systemOfRecords field to the dataset schema. schema.update({ 'locations': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')] }) schema.update({ 'data_contact': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')] }) schema.update({ 'distribution_contact': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')] }) schema.update({ 'metadata_contact': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')] }) schema.update({ 'other_contact': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')] }) # Add our granularity field to the dataset schema. schema.update({ 'purpose': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')] }) schema.update({ 'progress': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')] }) schema.update({ 'currentness': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')] }) schema.update({ 'spatial': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')] }) schema.update({ 'update_frequency': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')] }) schema.update({ 'use_constraints': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')] })''' return schema