def taxonomy_create(context, data_dict): """ Creates a new taxonomy. Terms are not created here, they must be created using taxonomy_term_create with the taxonomy id from this call. :param owner_org: the id of the dataset's owning organization, see :returns: The newly created taxonomy :rtype: A dictionary. """ _check_access('taxonomy_create', context, data_dict) model = context['model'] name = data_dict.get('name') title = logic.get_or_bust(data_dict, 'title') uri = logic.get_or_bust(data_dict, 'uri') if not name: name = munge_name(title) # Check the name has not been used if model.Session.query(Taxonomy).filter(Taxonomy.name == name).count() > 0: raise logic.ValidationError("Name is already in use") t = Taxonomy(name=name, title=title, uri=uri) model.Session.add(t) model.Session.commit() return t.as_dict()
def setup_taxonomy_data(cls): if model.Session.query(Taxonomy).count() > 0: return cls.taxonomies = [{ u'name': u'taxonomy-one', u'title': u'Taxonomy One', u'uri': u'http://localhost.local/taxonomy-one' }, { u'name': u'taxonomy-two', u'title': u'Taxonomy Two', u'uri': u'http://localhost.local/taxonomy-two' }] for t in cls.taxonomies: tx = Taxonomy(**t) model.Session.add(tx) model.Session.commit() t['id'] = tx.id