def taxonomy_show(context, data_dict): """ Shows a single taxonomy. :param id: The name of id of the taxonomy :returns: A single taxonomy :rtype: A dictionary """ _check_access('taxonomy_show', context, data_dict) model = context['model'] id = data_dict.get('id') uri = data_dict.get('uri') name = data_dict.get('name') if not id and not uri and not name: raise logic.ValidationError("Neither id, name or uri were provided") item = Taxonomy.get(id or name) if not item and uri: item = Taxonomy.by_uri(uri) if not item: raise logic.NotFound() return item.as_dict(with_terms=True)
def taxonomy_update(context, data_dict): """ Updates an existing taxonomy. title, name and uri are required :returns: The newly updated taxonomy :rtype: A dictionary """ _check_access('taxonomy_update', context, data_dict) model = context['model'] id = logic.get_or_bust(data_dict, 'id') name = logic.get_or_bust(data_dict, 'name') title = logic.get_or_bust(data_dict, 'title') uri = logic.get_or_bust(data_dict, 'uri') tax = Taxonomy.get(id) if not tax: raise logic.NotFound() tax.name = name tax.title = title tax.uri = uri model.Session.add(tax) model.Session.commit() return tax.as_dict()
def taxonomy_delete(context, data_dict): """ Delete the specific taxonomy, and as a result, all of the terms within it. :returns: The newly deleted taxonomy :rtype: A dictionary """ _check_access('taxonomy_delete', context, data_dict) model = context['model'] name = logic.get_or_bust(data_dict, 'id') taxonomy = Taxonomy.get(name) if not taxonomy: raise logic.NotFound() terms = model.Session.query(TaxonomyTerm)\ .filter(TaxonomyTerm.taxonomy == taxonomy) map(model.Session.delete, terms.all()) model.Session.delete(taxonomy) model.Session.commit() return taxonomy.as_dict()
def taxonomy_update(context, data_dict): """ Updates an existing taxonomy. title, name and uri are required :returns: The newly updated taxonomy :rtype: A dictionary """ _check_access('taxonomy_update', context, data_dict) model = context['model'] id = logic.get_or_bust(data_dict, 'id') tax = Taxonomy.get(id) if not tax: raise logic.NotFound() tax.name = data_dict.get('name', tax.name) tax.title = data_dict.get('title', tax.title) tax.uri = data_dict.get('name', tax.uri) last_modified = data_dict.get('last_modified', tax.last_modified) if tax.last_modified != last_modified: tax.last_modified = isodate(last_modified, context) model.Session.add(tax) model.Session.commit() return tax.as_dict()